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/parseTo.d

    r49 r55  
    442442private char replaceEscapedChar (char c) 
    443443{ 
    444     static char[char] escChars; 
    445     static bool escCharsFilled; // will be initialised false 
    446      
    447     if (!escCharsFilled) { 
    448         // map of all supported escape sequences (cannot be static?) 
    449         escChars = ['"'  : '"', '\'' : '\'', 
    450                     '\\' : '\\', 'a' : '\a', 
    451                     'b'  : '\b', 'f' : '\f', 
    452                     'n'  : '\n', 'r' : '\r', 
    453                     't'  : '\t', 'v' : '\v']; 
    454         escCharsFilled = true; 
    455     } 
    456      
    457     char* r = c in escChars; 
    458     if (r != null) return *r; 
    459     else throw new ParseException ("Invalid escape sequence: \\"~c); 
     444    // This code was generated: 
     445    if (c <= 'b') { 
     446        if (c <= '\'') { 
     447            if (c == '\"') { 
     448                return '\"'; 
     449            } else if (c == '\'') { 
     450                return '\''; 
     451            } 
     452        } else { 
     453            if (c == '\\') { 
     454                return '\\'; 
     455            } else if (c == 'a') { 
     456                return '\a'; 
     457            } else if (c == 'b') { 
     458                return '\b'; 
     459            } 
     460        } 
     461    } else { 
     462        if (c <= 'n') { 
     463            if (c == 'f') { 
     464                return '\f'; 
     465            } else if (c == 'n') { 
     466                return '\n'; 
     467            } 
     468        } else { 
     469            if (c == 'r') { 
     470                return '\r'; 
     471            } else if (c == 't') { 
     472                return '\t'; 
     473            } else if (c == 'v') { 
     474                return '\v'; 
     475            } 
     476        } 
     477    } 
     478     
     479    // if we haven't returned: 
     480    throw new ParseException ("Invalid escape sequence: \\"~c); 
    460481} 
    461482 
     
    484505} 
    485506 
    486 debug (UnitTest) unittest { 
    487     // all utility functions should be well-enough used not to need testing 
     507debug (UnitTest) { 
     508    import tango.io.Console; 
     509     
     510    unittest { 
     511        Cout ("Running unittest: parseTo ...").flush; 
     512         
     513        assert (parseTo!(char[]) ("\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\"") == "\a\b\t\n\v\f\r\"\'\\"); 
     514         
     515        Cout (" complete").newline; 
     516    } 
    488517} 
    489518//END Utility funcs