Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3909

Show
Ignore:
Timestamp:
08/24/08 23:05:41 (3 months ago)
Author:
kris
Message:

made parser faster

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/text/json/JsonParser.d

    r3872 r3909  
    2424        public enum Token 
    2525               { 
    26                Name, String, Number, BeginObject, EndObject,  
    27                BeginArray, EndArray, True, False, Null, Empty  
     26               Empty, Name, String, Number, BeginObject, EndObject,  
     27               BeginArray, EndArray, True, False, Null  
    2828               } 
    2929 
     
    174174                       ++p; 
    175175 
    176                 if(*p != '"')  
    177                     expected("\" in member name"); 
    178                  
    179                 curLoc = ++p
     176                if (*p != '"') 
     177                    expected ("\" before member name"); 
     178 
     179                curLoc = p+1
    180180                curType = Token.Name; 
    181                  
    182                 while (p < e)  
    183                       { 
    184                       if (*p is '"')  
    185                           if (*(p-1) != '\\') 
    186                               break; 
    187                       ++p; 
    188                       } 
     181 
     182                while (++p < e)  
     183                       if (*p is '"' && !escaped(p)) 
     184                           break; 
    189185 
    190186                if (p < e)  
     
    258254                curLoc = p; 
    259255                curType = Token.Number; 
    260                  
     256 
    261257                while (p < e) 
    262258                      { 
     
    286282                auto e = str.end; 
    287283 
    288                 if (*p != '"')  
    289                     expected ("\" in string"); 
    290  
    291                 curLoc = ++p; 
     284                curLoc = p+1; 
    292285                curType = Token.String; 
    293286                 
    294                 while (p < e)  
    295                       { 
    296                       if (*p is '"')  
    297                           if (*(p-1) != '\\') 
    298                               break; 
    299                       ++p; 
    300                       } 
     287                while (++p < e)  
     288                       if (*p is '"' && !escaped(p)) 
     289                           break; 
    301290 
    302291                if (p < e)  
     
    371360 
    372361                return parseValue (*(str.ptr = p)); 
     362        } 
     363 
     364        /*********************************************************************** 
     365         
     366        ***********************************************************************/ 
     367         
     368        private int escaped (T* p) 
     369        { 
     370                int i; 
     371 
     372                while (*--p is '\\') 
     373                       ++i; 
     374                return i & 1; 
    373375        } 
    374376}