Changeset 6828


Ignore:
Timestamp:
2004-02-18T13:12:08+13:00 (20 years ago)
Author:
mdewsnip
Message:

Added a transformation from plain text to a regular expression that matches it. This involves escaping special regular expression characters such as \().[]{}.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/Codec.java

    r6539 r6828  
    4848    static final public String TEXT_TO_DOM = "TEXT_TO_DOM";
    4949    static final public String TEXT_TO_GREENSTONE = "TEXT_TO_GREENSTONE";
     50    static final public String TEXT_TO_REGEXP = "TEXT_TO_REGEXP";
    5051    static final public String TEXT_TO_SHELL_UNIX = "TEXT_TO_SHELL_UNIX";
    5152    static final public String TEXT_TO_SHELL_WINDOWS = "TEXT_TO_SHELL_WINDOWS";
     
    102103    dom_to_text = null;
    103104
     105    // Transform text into a regular expression that will match it
     106    String[] text_to_regexp = {
     107        "\\\\", "\\\\\\\\",
     108        "\\(", "\\\\(",
     109        "\\)", "\\\\)",
     110        "\\[", "\\\\[",
     111        "\\]", "\\\\]",
     112        "\\{", "\\\\{",
     113        "\\}", "\\\\}",
     114        "\\.", "\\\\."
     115    };
     116    TRANSFORMS.put(TEXT_TO_REGEXP, text_to_regexp);
     117    text_to_regexp = null;
     118
    104119    String[] encode_path = {
    105120        "\\|",  "|",
     
    191206    }
    192207
    193     static public String transform(String raw, String transform) {
    194         if(raw == null) {
    195             return raw;
    196         }
    197     ///ystem.err.println("Transforming by "+transform+":\n" + raw);
     208    static public String transform(String raw, String transform) {
     209    if(raw == null) {
     210        return raw;
     211    }
     212    // System.err.println("Transforming by "+transform+":\n" + raw);
    198213    String processed = (String) CACHE.get(transform, raw);
    199214    if(processed == null) {
     
    207222        }
    208223        }
    209         //Gatherer.println("\n*** Transform: " + transform + " ***");
    210         //Gatherer.println("*** Raw      : '" + raw + "'");
    211         //Gatherer.println("*** Processed: '" + processed + "'");
     224        Gatherer.println("\n*** Transform: " + transform + " ***");
     225        Gatherer.println("*** Raw      : '" + raw + "'");
     226        Gatherer.println("*** Processed: '" + processed + "'");
    212227        // If cache is at maximum size, empty it and start again
    213228        if(CACHE.size() == MAX_CACHE_SIZE) {
Note: See TracChangeset for help on using the changeset viewer.