Show
Ignore:
Timestamp:
03/10/08 12:46:31 (4 years ago)
Author:
flithm
Message:

Update parseTo and parseFrom

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/scrapple/text/convert/parseFrom.d

    r47 r55  
    313313    return ((c <= '\r' && c >= '\a') || c == '\"' || c == '\'' || c == '\\'); 
    314314} 
    315 // Warning: this DOES NOT check c is escapable 
     315// Throws on unsupported escape sequences; however this should never actually happen within parseFrom. 
    316316private char replaceEscapableChar (char c) { 
    317     static char[char] escCharsRev;  // reversed escChars 
    318     static bool escCharsRevFilled;  // will be initialised false 
    319      
    320     if (!escCharsRevFilled) {   // only do this once 
    321         // map of all supported escape sequences 
    322         escCharsRev = ['"' : '"', '\'' : '\'', 
    323                        '\\' : '\\', '\a' : 'a', 
    324                        '\b' : 'b', '\f' : 'f', 
    325                        '\n' : 'n', '\r' : 'r', 
    326                        '\t' : 't', '\v' : 'v']; 
    327         escCharsRevFilled = true; 
    328     } 
    329      
    330     return escCharsRev[c]; 
    331 
    332  
    333 debug (UnitTest) unittest { 
    334     // all utility functions should be well-enough used not to need testing 
     317    // This code was generated: 
     318    if (c <= '\v') { 
     319        if (c <= '\b') { 
     320            if (c == '\a') { 
     321                return 'a'; 
     322            } else if (c == '\b') { 
     323                return 'b'; 
     324            } 
     325        } else { 
     326            if (c == '\t') { 
     327                return 't'; 
     328            } else if (c == '\n') { 
     329                return 'n'; 
     330            } else if (c == '\v') { 
     331                return 'v'; 
     332            } 
     333        } 
     334    } else { 
     335        if (c <= '\r') { 
     336            if (c == '\f') { 
     337                return 'f'; 
     338            } else if (c == '\r') { 
     339                return 'r'; 
     340            } 
     341        } else { 
     342            if (c == '\"') { 
     343                return '\"'; 
     344            } else if (c == '\'') { 
     345                return '\''; 
     346            } else if (c == '\\') { 
     347                return '\\'; 
     348            } 
     349        } 
     350    } 
     351     
     352    // if we haven't returned: 
     353    throw new IllegalArgumentException ("Character is not escapable (internal parseFrom error)"); 
     354
     355 
     356debug (UnitTest) { 
     357    import tango.io.Console; 
     358     
     359    unittest { 
     360        Cout ("Running unittest: parseFrom ...").flush; 
     361         
     362        assert (parseFrom!(char[]) ("\a\b\t\n\v\f\r\"\'\\") == "\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\""); 
     363         
     364        Cout (" complete").newline; 
     365    } 
    335366} 
    336367//END Utility funcs