mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 03:30:00 +00:00
Removed StringBuilder from literal string processors
This commit is contained in:
parent
77788d3c87
commit
84de939b7c
2 changed files with 11 additions and 21 deletions
|
@ -15,35 +15,30 @@ class LiteralStringConverter implements ValueConverter {
|
|||
@Override
|
||||
public Object convert(String s) {
|
||||
char[] chars = s.toCharArray();
|
||||
boolean terminated = false;
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
int endIndex = -1;
|
||||
|
||||
for (int i = 1; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
|
||||
if (c == '\'') {
|
||||
terminated = true;
|
||||
endIndex = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!terminated) {
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
if (terminated && c == '#') {
|
||||
if (endIndex > -1 && c == '#') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (terminated && !Character.isWhitespace(c)) {
|
||||
if (endIndex > -1 && !Character.isWhitespace(c)) {
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (!terminated) {
|
||||
if (endIndex == -1) {
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
return s.substring(1, endIndex);
|
||||
}
|
||||
|
||||
private LiteralStringConverter() {}
|
||||
|
|
|
@ -14,32 +14,27 @@ class MultilineLiteralStringConverter implements ValueConverter {
|
|||
@Override
|
||||
public Object convert(String s) {
|
||||
char[] chars = s.toCharArray();
|
||||
boolean terminated = false;
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
int endIndex = -1;
|
||||
|
||||
for (int i = 3; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
|
||||
if (c == '\'' && chars.length > i + 2 && chars[i + 1] == '\'' && chars[i + 2] == '\'') {
|
||||
endIndex = i;
|
||||
i += 2;
|
||||
terminated = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!terminated) {
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
if (terminated && c == '#') {
|
||||
if (endIndex > -1 && c == '#') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (terminated && !Character.isWhitespace(c)) {
|
||||
if (endIndex > -1 && !Character.isWhitespace(c)) {
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
return s.substring(3, endIndex);
|
||||
}
|
||||
|
||||
private MultilineLiteralStringConverter() {}
|
||||
|
|
Loading…
Reference in a new issue