diff src/org/tmatesoft/hg/internal/ConfigFile.java @ 136:947bf231acbb

Strip off comments in config file
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 16 Feb 2011 22:08:58 +0100
parents 44b97930570c
children 981f9f50bb6c
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/ConfigFile.java	Wed Feb 16 22:00:39 2011 +0100
+++ b/src/org/tmatesoft/hg/internal/ConfigFile.java	Wed Feb 16 22:08:58 2011 +0100
@@ -107,10 +107,14 @@
 			Map<String,String> section = new LinkedHashMap<String, String>();
 			while ((line = br.readLine()) != null) {
 				line = line.trim();
+				int x;
+				if ((x = line.indexOf('#')) != -1) {
+					// do not keep comments in memory, get new, shorter string
+					line = new String(line.substring(0, x).trim());
+				}
 				if (line.length() <= 2) { // a=b or [a] are at least of length 3
 					continue;
 				}
-				int x;
 				if (line.charAt(0) == '[' && line.charAt(line.length() - 1) == ']') {
 					sectionName = line.substring(1, line.length() - 1);
 					if (sections.indexOf(sectionName) == -1) {
@@ -120,6 +124,7 @@
 						section = null; // drop cached value
 					}
 				} else if ((x = line.indexOf('=')) != -1) {
+					// share char[] of the original string
 					String key = line.substring(0, x).trim();
 					String value = line.substring(x+1).trim();
 					if (section == null) {