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

Changeset 3827

Show
Ignore:
Timestamp:
07/31/08 00:53:02 (4 months ago)
Author:
kris
Message:

ignoring more garbage at eof

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/text/xml/PullParser.d

    r3826 r3827  
    9191                   while (*++p <= 32) 
    9292                          if (p >= text.end)                                       
    93                               return doEndOfStream
     93                              return endOfInput
    9494                   text.point = p; 
    9595                   } 
     
    135135                      return type = XmlTokenType.Data; 
    136136                      } 
    137                    return XmlTokenType.Done
     137                   return endOfInput
    138138                   } 
    139139 
     
    148148                            // check if we ran past the end 
    149149                            if (q >= e) 
    150                                 return XmlTokenType.Done
     150                                return endOfInput
    151151 
    152152                            text.point = q; 
     
    181181                               { 
    182182                               text.point += 4; 
    183                                return doComment()
     183                               return doComment
    184184                               }        
    185185                            else  
     
    187187                                  { 
    188188                                  text.point += 9; 
    189                                   return doCData()
     189                                  return doCData
    190190                                  } 
    191191                               else  
     
    193193                                     { 
    194194                                     text.point += 9; 
    195                                      return doDoctype()
     195                                     return doDoctype
    196196                                     } 
    197                             return doUnexpected("!"); 
     197                            return doUnexpected("!", p); 
    198198 
    199199                       case '\?': 
    200200                            text.point += 2; 
    201                             return doPI()
     201                            return doPI
    202202 
    203203                       case '/': 
     
    225225                                   ++q; 
    226226 
    227                             if (q >= text.end
    228                                 return doUnexpectedEOF
     227                            if (q >= e
     228                                return endOfInput
    229229 
    230230                            if (*q is '>') 
     
    234234                               return type = XmlTokenType.EndElement; 
    235235                               } 
    236                             return doUnexpected(">"); 
     236                            return doExpected(">", q); 
    237237                       } 
    238238 
     
    253253                       ++q; 
    254254                if (q >= e) 
    255                     return doUnexpectedEOF
     255                    return endOfInput
    256256 
    257257                if (*q is ':') 
     
    262262                   while (*q > 63 || text.attributeName[*q]) 
    263263                          ++q; 
    264                    if (q >= e) 
    265                        return doUnexpectedEOF; 
    266264 
    267265                   localName = p[0 .. q - p]; 
     
    277275                   while (*++q <= 32) {} 
    278276                   if (q >= e) 
    279                        return doUnexpectedEOF
     277                       return endOfInput
    280278                   } 
    281279 
     
    284282                   while (*++q <= 32) {} 
    285283                   if (q >= e) 
    286                        return doUnexpectedEOF
     284                       return endOfInput
    287285 
    288286                   auto quote = *q; 
     
    300298                                  return type = XmlTokenType.Attribute; 
    301299                                  } 
    302                                return doUnexpectedEOF;  
     300                               return endOfInput;  
    303301 
    304302                          default:  
    305                                return doUnexpected("\' or \""); 
     303                               return doExpected("\' or \"", q); 
    306304                          } 
    307305                   } 
    308306                 
    309                 return doUnexpected (q[0..1]); 
     307                return doUnexpected (q[0..1], q); 
    310308        } 
    311309 
     
    322320                   return type = XmlTokenType.EndEmptyElement; 
    323321                   } 
    324                 return doUnexpected("/>");                
     322                return doExpected("/>", text.point);                
    325323       } 
    326324         
     
    336334                      { 
    337335                      if (! text.forwardLocate('-'))  
    338                             return doUnexpectedEOF
     336                            return endOfInput
    339337 
    340338                      if (text[0..3] == "-->")  
     
    348346                      } 
    349347 
    350                 return doUnexpectedEOF
     348                return endOfInput
    351349        } 
    352350         
     
    362360                      { 
    363361                      if (! text.forwardLocate(']'))  
    364                             return doUnexpectedEOF
     362                            return endOfInput
    365363                 
    366364                      if (text[0..3] == "]]>")  
     
    374372                      } 
    375373 
    376                 return doUnexpectedEOF
     374                return endOfInput
    377375        } 
    378376         
     
    390388                      { 
    391389                      if (! text.forwardLocate('\?'))  
    392                             return doUnexpectedEOF
     390                            return endOfInput
    393391 
    394392                      if (text.point[1] == '>')  
     
    400398                      ++text.point; 
    401399                      } 
    402                 return doUnexpectedEOF
     400                return endOfInput
    403401        } 
    404402         
     
    433431 
    434432                if (! text.good) 
    435                       return doUnexpectedEOF
     433                      return endOfInput
    436434                return XmlTokenType.Doctype; 
    437435        } 
     
    441439        ***********************************************************************/ 
    442440 
    443         private XmlTokenType doUnexpectedEOF() 
    444         { 
    445                 return error ("Unexpected EOF"); 
    446         } 
    447          
    448         /*********************************************************************** 
    449          
    450         ***********************************************************************/ 
    451  
    452         private XmlTokenType doUnexpected(char[] msg = null) 
    453         { 
    454                 return error ("Unexpected event " ~ msg ~ " " ~ Integer.toString(type)); 
    455         } 
    456          
    457         /*********************************************************************** 
    458          
    459         ***********************************************************************/ 
    460  
    461         private XmlTokenType doEndOfStream() 
    462         { 
     441        private XmlTokenType endOfInput () 
     442        { 
     443                if (depth) 
     444                    error ("Unexpected EOF"); 
     445 
    463446                return XmlTokenType.Done; 
    464447        } 
    465                
     448         
     449        /*********************************************************************** 
     450         
     451        ***********************************************************************/ 
     452 
     453        private XmlTokenType doUnexpected (char[] msg, Ch* p) 
     454        { 
     455                return position ("parse error :: unexpected  " ~ msg, p); 
     456        } 
     457         
     458        /*********************************************************************** 
     459         
     460        ***********************************************************************/ 
     461 
     462        private XmlTokenType doExpected (char[] msg, Ch* p) 
     463        { 
     464                return position ("parse error :: expected  " ~ msg ~ " instead of " ~ *p, p); 
     465        } 
     466         
     467        /*********************************************************************** 
     468         
     469        ***********************************************************************/ 
     470 
     471        private XmlTokenType position (char[] msg, Ch* p) 
     472        { 
     473                return error (msg ~ " at position " ~ Integer.toString(p-text.text.ptr)); 
     474        } 
     475 
    466476        /*********************************************************************** 
    467477         
     
    470480        private XmlTokenType error (char[] msg) 
    471481        { 
     482                err = true; 
    472483                errMsg = msg; 
    473                 err = true; 
    474484                throw new XmlException (msg); 
    475485        }