IDEA-78458 Patch ini4j to let comment be on the same line as section header

This commit is contained in:
Kirill Likhodedov
2011-12-08 16:35:30 +03:00
parent 6b6a9ca09a
commit 22b31b249e
3 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
Index: src/main/java/org/ini4j/spi/IniParser.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>x-MacCyrillic
===================================================================
--- src/main/java/org/ini4j/spi/IniParser.java (date 1319206062000)
+++ src/main/java/org/ini4j/spi/IniParser.java (revision )
@@ -114,10 +114,19 @@
{
String sectionName;
- if (line.charAt(line.length() - 1) != SECTION_END)
+ if (line.charAt(line.length() - 1) != SECTION_END)
{
+ int sectionEnd = line.lastIndexOf(SECTION_END);
+ String afterSectionEnd = line.substring(sectionEnd + 1).trim();
+ if (afterSectionEnd.isEmpty() || isComment(afterSectionEnd.charAt(0)))
+ {
+ line = line.substring(0, sectionEnd + 1);
+ }
+ else
+ {
parseError(line, source.getLineNumber());
- }
+ }
+ }
sectionName = unescapeFilter(line.substring(1, line.length() - 1).trim());
if ((sectionName.length() == 0) && !getConfig().isUnnamedSection())
@@ -133,5 +142,9 @@
handler.startSection(sectionName);
return sectionName;
+ }
+
+ private boolean isComment(char c) {
+ return COMMENTS.indexOf(c) >= 0;
}
}