Changeset 18405


Ignore:
Timestamp:
01/19/09 15:15:38 (12 years ago)
Author:
kjdon
Message:

modifications to make this in line with gs2 version. Allows comments in arg indicators in dictionary text (eg {0-collection name}). The - needs to come immediately after the number

File:
1 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/util/Dictionary.java

    r13989 r18405  
    118118        // convert to unicode, copied from gatherer dictionary
    119119        String initial = new String(initial_raw.getBytes("ISO-8859-1"), "UTF-8");
     120
     121        // Remove any comments from the string
     122        if (initial.indexOf("#") != -1) {
     123        initial = initial.substring(0, initial.indexOf("#"));
     124        }
    120125        // If the string contains arguments we have to insert them.
    121         String complete = "";
     126        StringBuffer complete = new StringBuffer();
    122127        // While we still have initial string left.
    123128        while(initial.length() > 0 && initial.indexOf('{') != -1 && initial.indexOf('}') != -1) {
     
    125130        int opening = initial.indexOf('{');
    126131        int closing = initial.indexOf('}');
    127         complete = complete + initial.substring(0, opening);
     132        int comment_mark = initial.indexOf('-', opening); // May not exist
     133        if (comment_mark > closing) { // May also be detecting a later comment
     134            comment_mark = -1;
     135        }
     136        complete.append(initial.substring(0, opening));
     137       
    128138        // Parse arg_num
    129         String arg_str = initial.substring(opening + 1, closing);
    130         int arg_num = Integer.parseInt(arg_str);
     139        String arg_str = null;
     140        if (comment_mark != -1) {
     141          arg_str = initial.substring(opening + 1, comment_mark);
     142        } else {
     143          arg_str = initial.substring(opening + 1, closing);
     144        }
    131145        if(closing + 1 < initial.length()) {
    132146            initial = initial.substring(closing + 1);
     
    135149            initial = "";
    136150        }
     151        int arg_num = Integer.parseInt(arg_str);
    137152        // Insert argument
    138153        if(args != null && 0 <= arg_num && arg_num < args.length) {
    139             complete = complete + args[arg_num];
     154          complete.append(args[arg_num]);
    140155        }
    141156        }
    142         return complete + initial;
     157        complete.append(initial);
     158        return complete.toString();
    143159    }
    144160    catch (Exception e) {
Note: See TracChangeset for help on using the changeset viewer.