Mercurial > jhg
comparison 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 |
comparison
equal
deleted
inserted
replaced
135:3959bffb14e9 | 136:947bf231acbb |
---|---|
105 String line; | 105 String line; |
106 String sectionName = ""; | 106 String sectionName = ""; |
107 Map<String,String> section = new LinkedHashMap<String, String>(); | 107 Map<String,String> section = new LinkedHashMap<String, String>(); |
108 while ((line = br.readLine()) != null) { | 108 while ((line = br.readLine()) != null) { |
109 line = line.trim(); | 109 line = line.trim(); |
110 int x; | |
111 if ((x = line.indexOf('#')) != -1) { | |
112 // do not keep comments in memory, get new, shorter string | |
113 line = new String(line.substring(0, x).trim()); | |
114 } | |
110 if (line.length() <= 2) { // a=b or [a] are at least of length 3 | 115 if (line.length() <= 2) { // a=b or [a] are at least of length 3 |
111 continue; | 116 continue; |
112 } | 117 } |
113 int x; | |
114 if (line.charAt(0) == '[' && line.charAt(line.length() - 1) == ']') { | 118 if (line.charAt(0) == '[' && line.charAt(line.length() - 1) == ']') { |
115 sectionName = line.substring(1, line.length() - 1); | 119 sectionName = line.substring(1, line.length() - 1); |
116 if (sections.indexOf(sectionName) == -1) { | 120 if (sections.indexOf(sectionName) == -1) { |
117 sections.add(sectionName); | 121 sections.add(sectionName); |
118 content.add(section = new LinkedHashMap<String, String>()); | 122 content.add(section = new LinkedHashMap<String, String>()); |
119 } else { | 123 } else { |
120 section = null; // drop cached value | 124 section = null; // drop cached value |
121 } | 125 } |
122 } else if ((x = line.indexOf('=')) != -1) { | 126 } else if ((x = line.indexOf('=')) != -1) { |
127 // share char[] of the original string | |
123 String key = line.substring(0, x).trim(); | 128 String key = line.substring(0, x).trim(); |
124 String value = line.substring(x+1).trim(); | 129 String value = line.substring(x+1).trim(); |
125 if (section == null) { | 130 if (section == null) { |
126 int i = sections.indexOf(sectionName); | 131 int i = sections.indexOf(sectionName); |
127 assert i >= 0; | 132 assert i >= 0; |