Overview
Comment: | Add -[finishedParsing] to OFXMLParser. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
58a72fc69b4fd67756521a7dacbd4802 |
User & Date: | js on 2010-12-09 19:40:34 |
Other Links: | manifest | tags |
Context
2010-12-09
| ||
23:45 | Add -[lineNumber] to OFXMLParser. check-in: 1e64693064 user: js tags: trunk | |
19:40 | Add -[finishedParsing] to OFXMLParser. check-in: 58a72fc69b user: js tags: trunk | |
19:19 | Add -[parseStream] to OFXMLParser. check-in: 964b6c41f0 user: js tags: trunk | |
Changes
Modified src/OFXMLParser.h from [58cfc81be7] to [6f9a183c8c].
︙ | ︙ | |||
163 164 165 166 167 168 169 170 171 172 173 174 175 176 | of_xml_parser_element_end_block_t elementEndHandler; of_xml_parser_string_block_t charactersHandler; of_xml_parser_string_block_t CDATAHandler; of_xml_parser_string_block_t commentHandler; of_xml_parser_unknown_entity_block_t unknownEntityHandler; #endif size_t level; } #ifdef OF_HAVE_PROPERTIES @property (retain) id <OFXMLParserDelegate> delegate; # ifdef OF_HAVE_BLOCKS @property (copy) of_xml_parser_processing_instructions_block_t processingInstructionsHandler; | > | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | of_xml_parser_element_end_block_t elementEndHandler; of_xml_parser_string_block_t charactersHandler; of_xml_parser_string_block_t CDATAHandler; of_xml_parser_string_block_t commentHandler; of_xml_parser_unknown_entity_block_t unknownEntityHandler; #endif size_t level; BOOL finishedParsing; } #ifdef OF_HAVE_PROPERTIES @property (retain) id <OFXMLParserDelegate> delegate; # ifdef OF_HAVE_BLOCKS @property (copy) of_xml_parser_processing_instructions_block_t processingInstructionsHandler; |
︙ | ︙ | |||
312 313 314 315 316 317 318 319 320 321 322 | /** * Parses the specified file. * * \param path The path to the file to parse */ - (void)parseFile: (OFString*)path; @end @interface OFObject (OFXMLParserDelegate) <OFXMLParserDelegate> @end | > > > > > | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | /** * Parses the specified file. * * \param path The path to the file to parse */ - (void)parseFile: (OFString*)path; /** * \return Whether the XML parser has finished parsing */ - (BOOL)finishedParsing; @end @interface OFObject (OFXMLParserDelegate) <OFXMLParserDelegate> @end |
Modified src/OFXMLParser.m from [e24ed84b06] to [8a551b940b].
︙ | ︙ | |||
190 191 192 193 194 195 196 197 198 199 200 201 202 203 | delegate = delegate_; } - (void)parseBuffer: (const char*)buf withSize: (size_t)size { size_t i, last = 0; for (i = 0; i < size; i++) lookup_table[state](self, selectors[state], buf, &i, &last); /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ if (size - last > 0 && state != OF_XMLPARSER_IN_TAG) [cache appendCStringWithoutUTF8Checking: buf + last | > > > > > > > > > > | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | delegate = delegate_; } - (void)parseBuffer: (const char*)buf withSize: (size_t)size { size_t i, last = 0; if (finishedParsing) { for (i = 0; i < size; i++) if (buf[i] != ' ' && buf[i] != '\t' && buf[i] != '\n' && buf[i] != '\r') @throw [OFMalformedXMLException newWithClass: isa]; return; } for (i = 0; i < size; i++) lookup_table[state](self, selectors[state], buf, &i, &last); /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ if (size - last > 0 && state != OF_XMLPARSER_IN_TAG) [cache appendCStringWithoutUTF8Checking: buf + last |
︙ | ︙ | |||
495 496 497 498 499 500 501 502 503 504 505 506 507 508 | [prefix release]; name = prefix = nil; *last = *i + 1; state = (buf[*i] == '>' ? OF_XMLPARSER_OUTSIDE_TAG : OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE); } /* Inside a tag, name found */ - (void)_parseInTagWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { | > > > | 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | [prefix release]; name = prefix = nil; *last = *i + 1; state = (buf[*i] == '>' ? OF_XMLPARSER_OUTSIDE_TAG : OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE); if ([previous count] == 0) finishedParsing = YES; } /* Inside a tag, name found */ - (void)_parseInTagWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { |
︙ | ︙ | |||
875 876 877 878 879 880 881 882 883 884 885 886 887 888 | state = OF_XMLPARSER_OUTSIDE_TAG; else level--; } *last = *i + 1; } - (OFString*)string: (OFString*)string containsUnknownEntityNamed: (OFString*)entity { #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (unknownEntityHandler != NULL) return unknownEntityHandler(self, entity); | > > > > > | 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 | state = OF_XMLPARSER_OUTSIDE_TAG; else level--; } *last = *i + 1; } - (BOOL)finishedParsing { return finishedParsing; } - (OFString*)string: (OFString*)string containsUnknownEntityNamed: (OFString*)entity { #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (unknownEntityHandler != NULL) return unknownEntityHandler(self, entity); |
︙ | ︙ |
Modified tests/OFXMLParserTests.m from [f82b21bdca] to [61a6d285b6].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /* * Copyright (c) 2008 - 2010 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #include "config.h" #include <string.h> #import "OFXMLParser.h" #import "OFString.h" #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFString.h" | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* * Copyright (c) 2008 - 2010 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #include "config.h" #include <stdlib.h> #include <string.h> #import "OFXMLParser.h" #import "OFString.h" #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFString.h" |
︙ | ︙ | |||
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | TEST(@"-[setDelegate:]", R([parser setDelegate: self])) /* Simulate a stream where we only get chunks */ len = strlen(str); for (j = 0; j < len; j+= 2) { if (j + 2 > len) [parser parseBuffer: str + j withSize: 1]; else [parser parseBuffer: str + j withSize: 2]; } TEST(@"Checking if everything was parsed", i == 32) [pool drain]; } @end | > > > > > > > > > > > | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | TEST(@"-[setDelegate:]", R([parser setDelegate: self])) /* Simulate a stream where we only get chunks */ len = strlen(str); for (j = 0; j < len; j+= 2) { if ([parser finishedParsing]) abort(); if (j + 2 > len) [parser parseBuffer: str + j withSize: 1]; else [parser parseBuffer: str + j withSize: 2]; } TEST(@"Checking if everything was parsed", i == 32) TEST(@"-[finishedParsing]", [parser finishedParsing]) TEST(@"Parsing whitespaces after the document", R([parser parseString: @" \t\r\n "])) EXPECT_EXCEPTION(@"Detection of junk after the document", OFMalformedXMLException, [parser parseString: @"a"]) [pool drain]; } @end |