Changeset 33812

Show
Ignore:
Timestamp:
18.12.2019 21:36:07 (5 weeks ago)
Author:
ak19
Message:

Better handling of multi-line comment symbols, so I can now include proper multi-line spanning comments in my .json files

Location:
other-projects/maori-lang-detection
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • other-projects/maori-lang-detection/conf/countrycodes.json

    r33805 r33812  
    11/* CountryCodes with geolocation from https://developers.google.com/public-data/docs/canonical/countries_csv */ 
    2 /* BEWARE OF ADDING OR MODIFYING COMMENTS IN THIS FILE INTO MULTILINE COMMENTS, AS JAVA CODE CAN'T DEAL WITH THAT */ 
    32 
    43/* 1 */ 
  • other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java

    r33805 r33812  
    8181 * TO RUN: 
    8282 *    maori-lang-detection/src$ 
    83  *       java -cp ".:../conf:../lib/*" org/greenstone/atea/CountryCodeCountsMapData ../mongodb-data/countrycodes.json ../mongodb-data/counts.json 
     83 *       java -cp ".:../conf:../lib/*" org/greenstone/atea/CountryCodeCountsMapData ../mongodb-data/counts.json 
    8484 *################### 
    8585 * 
     
    215215        new StringBuilder("["); 
    216216        String line; 
     217 
     218        boolean multi_line_comment = false; 
     219         
    217220        while((line = reader.readLine()) != null) { 
    218         line = line.replaceAll("/\\* [^\\/]* \\*/", ""); // get rid of any multiline comments symbols on a single line 
     221        line = line.trim(); 
     222 
     223        // ignore any single line comments nested in multi-line symbols 
     224        if(line.startsWith("/*") && line.endsWith("*/")) { 
     225            continue; // skip line 
     226        } 
     227 
     228        // skip multi-line comments spread over multiple lines 
     229        // assumes this ends on a line containing */ without further content on the line. 
     230        if(line.startsWith("/*") && !line.endsWith("*/")) { 
     231            multi_line_comment = true; 
     232            continue; // skip line 
     233        } 
     234        if(multi_line_comment) { 
     235            if(line.contains("*/")) { 
     236            multi_line_comment = false; 
     237            } 
     238 
     239            continue; // we're in a comment or at end of comment, skip line 
     240        } 
     241 
    219242        str.append(line); 
    220243        if(line.endsWith("}")) {