mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 19:50:29 +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
|
@Override
|
||||||
public Object convert(String s) {
|
public Object convert(String s) {
|
||||||
char[] chars = s.toCharArray();
|
char[] chars = s.toCharArray();
|
||||||
boolean terminated = false;
|
int endIndex = -1;
|
||||||
StringBuilder sb = new StringBuilder(s.length());
|
|
||||||
|
|
||||||
for (int i = 1; i < chars.length; i++) {
|
for (int i = 1; i < chars.length; i++) {
|
||||||
char c = chars[i];
|
char c = chars[i];
|
||||||
|
|
||||||
if (c == '\'') {
|
if (c == '\'') {
|
||||||
terminated = true;
|
endIndex = i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!terminated) {
|
if (endIndex > -1 && c == '#') {
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (terminated && c == '#') {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (terminated && !Character.isWhitespace(c)) {
|
if (endIndex > -1 && !Character.isWhitespace(c)) {
|
||||||
return INVALID;
|
return INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!terminated) {
|
if (endIndex == -1) {
|
||||||
return INVALID;
|
return INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return s.substring(1, endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LiteralStringConverter() {}
|
private LiteralStringConverter() {}
|
||||||
|
|
|
@ -14,32 +14,27 @@ class MultilineLiteralStringConverter implements ValueConverter {
|
||||||
@Override
|
@Override
|
||||||
public Object convert(String s) {
|
public Object convert(String s) {
|
||||||
char[] chars = s.toCharArray();
|
char[] chars = s.toCharArray();
|
||||||
boolean terminated = false;
|
int endIndex = -1;
|
||||||
StringBuilder sb = new StringBuilder(s.length());
|
|
||||||
|
|
||||||
for (int i = 3; i < chars.length; i++) {
|
for (int i = 3; i < chars.length; i++) {
|
||||||
char c = chars[i];
|
char c = chars[i];
|
||||||
|
|
||||||
if (c == '\'' && chars.length > i + 2 && chars[i + 1] == '\'' && chars[i + 2] == '\'') {
|
if (c == '\'' && chars.length > i + 2 && chars[i + 1] == '\'' && chars[i + 2] == '\'') {
|
||||||
|
endIndex = i;
|
||||||
i += 2;
|
i += 2;
|
||||||
terminated = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!terminated) {
|
if (endIndex > -1 && c == '#') {
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (terminated && c == '#') {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (terminated && !Character.isWhitespace(c)) {
|
if (endIndex > -1 && !Character.isWhitespace(c)) {
|
||||||
return INVALID;
|
return INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return s.substring(3, endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MultilineLiteralStringConverter() {}
|
private MultilineLiteralStringConverter() {}
|
||||||
|
|
Loading…
Reference in a new issue