CadixDev/Lorenz

Support blank comments in IO readers

phase opened this issue · 2 comments

Lorenz does ignore comments in *SRG formats.

Format Reader Usage
SRG https://github.com/CadixDev/Lorenz/blob/develop/lorenz/src/main/java/org/cadixdev/lorenz/io/srg/SrgReader.java#L84
CSRG https://github.com/CadixDev/Lorenz/blob/develop/lorenz/src/main/java/org/cadixdev/lorenz/io/srg/csrg/CSrgReader.java#L79
TSRG https://github.com/CadixDev/Lorenz/blob/develop/lorenz/src/main/java/org/cadixdev/lorenz/io/srg/tsrg/TSrgReader.java#L82

They all use the same implementation.

private static final Pattern HASH_COMMENT = Pattern.compile("#.+");

public static String removeComments(final String line) {
    return HASH_COMMENT.matcher(line).replaceAll("");
}
phase commented

I got this error and assumed there as no support for it:

Exception in thread "main" java.lang.IllegalArgumentException: Faulty TSRG mapping encountered: `#`!
	at org.cadixdev.lorenz.io.srg.tsrg.TSrgReader$Processor.accept(TSrgReader.java:86)
	at org.cadixdev.lorenz.io.srg.tsrg.TSrgReader$Processor.accept(TSrgReader.java:56)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:647)
	at org.cadixdev.lorenz.io.TextMappingsReader.read(TextMappingsReader.java:73)
	at org.cadixdev.lorenz.io.MappingFormat.read(MappingFormat.java:79)
	at org.cadixdev.lorenz.io.MappingFormat.read(MappingFormat.java:92)

Usage:

MappingFormats.TSRG.read(Paths.get("beta/serverToClientObf.tsrg")),

After looking at this again, it appears to only error on lines that only contain a #. This is probably due to the comment regex being .+ instead of .*.