2022-05-05 07:49:03 +00:00
|
|
|
package dev.plex.toml;
|
2022-05-04 12:18:07 +00:00
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
2022-05-04 12:19:34 +00:00
|
|
|
class MultilineStringValueReader implements ValueReader
|
2022-05-04 12:18:07 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
static final MultilineStringValueReader MULTILINE_STRING_VALUE_READER = new MultilineStringValueReader();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canRead(String s) {
|
|
|
|
return s.startsWith("\"\"\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-05-05 07:49:03 +00:00
|
|
|
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context) {
|
2022-05-04 12:18:07 +00:00
|
|
|
AtomicInteger line = context.line;
|
|
|
|
int startLine = line.get();
|
|
|
|
int originalStartIndex = index.get();
|
|
|
|
int startIndex = index.addAndGet(3);
|
|
|
|
int endIndex = -1;
|
|
|
|
|
|
|
|
if (s.charAt(startIndex) == '\n') {
|
|
|
|
startIndex = index.incrementAndGet();
|
|
|
|
line.incrementAndGet();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = startIndex; i < s.length(); i = index.incrementAndGet()) {
|
|
|
|
char c = s.charAt(i);
|
|
|
|
|
|
|
|
if (c == '\n') {
|
|
|
|
line.incrementAndGet();
|
|
|
|
} else if (c == '"' && s.length() > i + 2 && s.charAt(i + 1) == '"' && s.charAt(i + 2) == '"') {
|
|
|
|
endIndex = i;
|
|
|
|
index.addAndGet(2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endIndex == -1) {
|
2022-05-05 07:49:03 +00:00
|
|
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
2022-05-04 12:18:07 +00:00
|
|
|
errors.unterminated(context.identifier.getName(), s.substring(originalStartIndex), startLine);
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = s.substring(startIndex, endIndex);
|
|
|
|
s = s.replaceAll("\\\\\\s+", "");
|
2022-05-05 07:49:03 +00:00
|
|
|
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceUnicodeCharacters(s);
|
|
|
|
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceSpecialCharacters(s);
|
2022-05-04 12:18:07 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
private MultilineStringValueReader() {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|