[attributes] Introduce attributes extensions

This commit is contained in:
2025-07-27 01:18:32 +02:00
parent e4ea5fdfc2
commit c9a609d457
28 changed files with 1627 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ import java.util.regex.Pattern;
public class HjsonWriter implements TweedDataVisitor {
private static final int PREFILL_INDENT = 10;
private static final Pattern LINE_FEED_PATTERN = Pattern.compile("\\n|\\r\\n");
private static final Pattern NUMBER_PATTERN = Pattern.compile("^-?\\d+(?:\\.\\d*)?(?:[eE][+-]?\\d+)?$");
private final Writer writer;
private final Options options;
@@ -101,8 +102,11 @@ public class HjsonWriter implements TweedDataVisitor {
if (value.isEmpty() || "true".equals(value) || "false".equals(value) || "null".equals(value)) {
return HjsonStringType.INLINE_DOUBLE_QUOTE;
}
if (NUMBER_PATTERN.matcher(value).matches()) {
return HjsonStringType.INLINE_DOUBLE_QUOTE;
}
int firstCodePoint = value.codePointAt(0);
if (Character.isDigit(firstCodePoint) || Character.isWhitespace(firstCodePoint)) {
if (Character.isWhitespace(firstCodePoint)) {
return HjsonStringType.INLINE_DOUBLE_QUOTE;
}
int lastCodePoint = value.codePointBefore(value.length());