Overview
Comment: | Add -[lineNumber] to OFXMLParser. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
1e64693064fba209c5f2db1f69330854 |
User & Date: | js on 2010-12-09 23:45:06 |
Other Links: | manifest | tags |
Context
2010-12-10
| ||
01:19 | Bring some consistency into the style of configure.ac. check-in: 851dce0bce user: js tags: trunk | |
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 | |
Changes
Modified src/OFXMLParser.h from [6f9a183c8c] to [4ec07ce01d].
︙ | ︙ | |||
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; BOOL finishedParsing; } #ifdef OF_HAVE_PROPERTIES @property (retain) id <OFXMLParserDelegate> delegate; # ifdef OF_HAVE_BLOCKS @property (copy) of_xml_parser_processing_instructions_block_t | > > | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | 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; size_t lineNumber; BOOL lastCarriageReturn; BOOL finishedParsing; } #ifdef OF_HAVE_PROPERTIES @property (retain) id <OFXMLParserDelegate> delegate; # ifdef OF_HAVE_BLOCKS @property (copy) of_xml_parser_processing_instructions_block_t |
︙ | ︙ | |||
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 | > > > > > | 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | /** * Parses the specified file. * * \param path The path to the file to parse */ - (void)parseFile: (OFString*)path; /** * \return The current line number */ - (size_t)lineNumber; /** * \return Whether the XML parser has finished parsing */ - (BOOL)finishedParsing; @end @interface OFObject (OFXMLParserDelegate) <OFXMLParserDelegate> @end |
Modified src/OFXMLParser.m from [8a551b940b] to [d446a92ae5].
︙ | ︙ | |||
141 142 143 144 145 146 147 148 149 150 151 152 153 154 | namespaces = [[OFMutableArray alloc] init]; pool = [[OFAutoreleasePool alloc] init]; dict = [OFMutableDictionary dictionaryWithKeysAndObjects: @"xml", @"http://www.w3.org/XML/1998/namespace", @"xmlns", @"http://www.w3.org/2000/xmlns/", nil]; [namespaces addObject: dict]; [pool release]; } @catch (id e) { [self release]; @throw e; } return self; | > > > | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | namespaces = [[OFMutableArray alloc] init]; pool = [[OFAutoreleasePool alloc] init]; dict = [OFMutableDictionary dictionaryWithKeysAndObjects: @"xml", @"http://www.w3.org/XML/1998/namespace", @"xmlns", @"http://www.w3.org/2000/xmlns/", nil]; [namespaces addObject: dict]; lineNumber = 1; [pool release]; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ | |||
201 202 203 204 205 206 207 | buf[i] != '\n' && buf[i] != '\r') @throw [OFMalformedXMLException newWithClass: isa]; return; } | | > > > > > > > > > > > > | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | buf[i] != '\n' && buf[i] != '\r') @throw [OFMalformedXMLException newWithClass: isa]; return; } for (i = 0; i < size; i++) { size_t j = i; lookup_table[state](self, selectors[state], buf, &i, &last); /* Ensure we don't count this character twice */ if (i != j) continue; if (buf[i] == '\r' || (buf[i] == '\n' && !lastCarriageReturn)) lineNumber++; lastCarriageReturn = (buf[i] == '\r' ? YES : NO); } /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ if (size - last > 0 && state != OF_XMLPARSER_IN_TAG) [cache appendCStringWithoutUTF8Checking: buf + last length: size - last]; } |
︙ | ︙ | |||
888 889 890 891 892 893 894 895 896 897 898 899 900 901 | state = OF_XMLPARSER_OUTSIDE_TAG; else level--; } *last = *i + 1; } - (BOOL)finishedParsing { return finishedParsing; } - (OFString*)string: (OFString*)string | > > > > > | 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 | state = OF_XMLPARSER_OUTSIDE_TAG; else level--; } *last = *i + 1; } - (size_t)lineNumber { return lineNumber; } - (BOOL)finishedParsing { return finishedParsing; } - (OFString*)string: (OFString*)string |
︙ | ︙ |
Modified tests/OFXMLParserTests.m from [61a6d285b6] to [542c5c5171].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" #import "TestsAppDelegate.h" static OFString *module = @"OFXMLParser"; static int i = 0; enum event_type { PROCESSING_INSTRUCTIONS, TAG_START, TAG_END, STRING, | > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFExceptions.h" #import "TestsAppDelegate.h" static OFString *module = @"OFXMLParser"; static OFXMLParser *parser; static int i = 0; enum event_type { PROCESSING_INSTRUCTIONS, TAG_START, TAG_END, STRING, |
︙ | ︙ | |||
58 59 60 61 62 63 64 | [string isEqual: @"p?i"]) break; case 3: TEST(msg, et == TAG_START && [name isEqual: @"root"] && prefix == nil && ns == nil && [attrs count] == 0) break; case 4: | | | > | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | [string isEqual: @"p?i"]) break; case 3: TEST(msg, et == TAG_START && [name isEqual: @"root"] && prefix == nil && ns == nil && [attrs count] == 0) break; case 4: TEST(msg, et == STRING && [string isEqual: @"\n\n "]) break; case 5: TEST(msg, et == CDATA && [string isEqual: @"f<]]]oo"] && [parser lineNumber] == 3) break; case 6: TEST(msg, et == TAG_START && [name isEqual: @"bar"] && prefix == nil && ns == nil && attrs == nil) break; case 7: TEST(msg, et == TAG_END && [name isEqual: @"bar"] && |
︙ | ︙ | |||
312 313 314 315 316 317 318 | return nil; } - (void)XMLParserTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; | < | | | 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | return nil; } - (void)XMLParserTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; const char *str = "<?xml version='1.0'?><?p?i?>" "<!DOCTYPE <<><<>>>><root>\r\r" " <![CDATA[f<]]]oo]]><bar/>\n" " <foobar xmlns='urn:objfw:test:foobar'>\r\n" " <qux xmlns:foo='urn:objfw:test:foo'>\n" " <foo:bla foo:bla = 'bla' blafoo='foo'>\n" " <blup foo:qux='asd' quxqux='test'/>\n" " <bla:bla\r\rxmlns:bla\r=\t\"urn:objfw:test:bla\" qux='qux'\r\n" " bla:foo='blafoo'/>\n" " <abc xmlns='urn:objfw:test:abc' abc='abc' foo:abc='abc'/>\n" " </foo:bla>\n" |
︙ | ︙ | |||
349 350 351 352 353 354 355 | [parser parseBuffer: str + j withSize: 1]; else [parser parseBuffer: str + j withSize: 2]; } | | > | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | [parser parseBuffer: str + j withSize: 1]; else [parser parseBuffer: str + j withSize: 2]; } TEST(@"Checking if everything was parsed", i == 32 && [parser lineNumber] == 18) 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 |