解决配置文件中特殊字符问题

This commit is contained in:
heavyrain2012
2021-08-05 15:44:20 +08:00
parent 5a2ded4b6e
commit debd4f1aea
@@ -84,34 +84,37 @@ class ConfigurationParser {
String line; String line;
try { try {
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
line = line.trim();
int commentMarker = line.indexOf('#'); int commentMarker = line.indexOf('#');
if (commentMarker != -1) { if (commentMarker != -1) {
if (commentMarker == 0) { if (commentMarker == 0) {
// skip its a comment // skip its a comment
continue; continue;
} else { } else {
// it's a malformed comment String[] ss = line.split(" ");
throw new ParseException(line, commentMarker); if(ss.length != 2) {
throw new ParseException(line, commentMarker);
}
} }
} else { } else {
if (line.isEmpty() || line.matches("^\\s*$")) { if (line.isEmpty() || line.matches("^\\s*$")) {
// skip it's a black line // skip it's a black line
continue; continue;
} }
// split till the first space
int delimiterIdx = line.indexOf(' ');
String key;
String value = "";
if (delimiterIdx > 0) {
key = line.substring(0, delimiterIdx).trim();
value = line.substring(delimiterIdx).trim();
} else {
key = line.trim();
}
m_properties.put(key, value);
} }
// split till the first space
int delimiterIdx = line.indexOf(' ');
String key;
String value = "";
if (delimiterIdx > 0) {
key = line.substring(0, delimiterIdx).trim();
value = line.substring(delimiterIdx).trim();
} else {
key = line.trim();
}
m_properties.put(key, value);
} }
} catch (IOException ex) { } catch (IOException ex) {
throw new ParseException("Failed to read", 1); throw new ParseException("Failed to read", 1);