Read from a file with a bunch of attribute/value pairs that are separated by = and ignore comments with #.
(File inputFile)
| 2242 | * that are separated by = and ignore comments with #. |
| 2243 | */ |
| 2244 | static public HashMap<String, String> readSettings(File inputFile) { |
| 2245 | HashMap<String, String> outgoing = new HashMap<>(); |
| 2246 | if (!inputFile.exists()) return outgoing; // return empty hash |
| 2247 | |
| 2248 | String lines[] = PApplet.loadStrings(inputFile); |
| 2249 | for (int i = 0; i < lines.length; i++) { |
| 2250 | int hash = lines[i].indexOf('#'); |
| 2251 | String line = (hash == -1) ? |
| 2252 | lines[i].trim() : lines[i].substring(0, hash).trim(); |
| 2253 | if (line.length() == 0) continue; |
| 2254 | |
| 2255 | int equals = line.indexOf('='); |
| 2256 | if (equals == -1) { |
| 2257 | System.err.println("ignoring illegal line in " + inputFile); |
| 2258 | System.err.println(" " + line); |
| 2259 | continue; |
| 2260 | } |
| 2261 | String attr = line.substring(0, equals).trim(); |
| 2262 | String valu = line.substring(equals + 1).trim(); |
| 2263 | outgoing.put(attr, valu); |
| 2264 | } |
| 2265 | return outgoing; |
| 2266 | } |
| 2267 | |
| 2268 | |
| 2269 | static public void copyFile(File sourceFile, |
nothing calls this directly
no test coverage detected