diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-06-06 07:52:12 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-06-06 07:52:12 +0000 |
commit | 5c3263289b3e10c49badd416e12075af0f2f294e (patch) | |
tree | 9d0b1f3bb167f794ec18466f94f7e8ce6b1d02fa /src | |
parent | 579a58106e541ef4a005eceaf4577048c69fa539 (diff) | |
download | libbu++-5c3263289b3e10c49badd416e12075af0f2f294e.tar.gz libbu++-5c3263289b3e10c49badd416e12075af0f2f294e.tar.bz2 libbu++-5c3263289b3e10c49badd416e12075af0f2f294e.tar.xz libbu++-5c3263289b3e10c49badd416e12075af0f2f294e.zip |
Added comment handling to the XML system. It just discards them completely, but
later it will retain them so that even after modifying the nodes the comments
could be kept in place so they aren't destroyed if something changes.
Also added necesarry functions to the XmlDocument that lets the tests run again
and fixes some issues with multiple ownernership when transfering the contents
to a new document.
Diffstat (limited to 'src')
-rw-r--r-- | src/test/xmlreadtest.cpp | 6 | ||||
-rw-r--r-- | src/xmldocument.cpp | 7 | ||||
-rw-r--r-- | src/xmldocument.h | 8 | ||||
-rw-r--r-- | src/xmlfilereader.cpp | 6 | ||||
-rw-r--r-- | src/xmlfilereader.h | 2 | ||||
-rw-r--r-- | src/xmlreader.cpp | 43 | ||||
-rw-r--r-- | src/xmlreader.h | 2 | ||||
-rw-r--r-- | src/xmlstringreader.cpp | 6 | ||||
-rw-r--r-- | src/xmlstringreader.h | 2 |
9 files changed, 68 insertions, 14 deletions
diff --git a/src/test/xmlreadtest.cpp b/src/test/xmlreadtest.cpp index 5fbd021..f6d8d8b 100644 --- a/src/test/xmlreadtest.cpp +++ b/src/test/xmlreadtest.cpp | |||
@@ -14,14 +14,14 @@ int main( int argc, char *argv[] ) | |||
14 | if( argv[1][0] == 'f' ) | 14 | if( argv[1][0] == 'f' ) |
15 | { | 15 | { |
16 | XmlFileReader r( argv[2], true ); | 16 | XmlFileReader r( argv[2], true ); |
17 | XmlFileWriter w( argv[3], "\t", r.getRoot() ); | 17 | XmlFileWriter w( argv[3], "\t", r.detatchRoot() ); |
18 | w.write(); | 18 | w.write(); |
19 | //XmlWriter::write( argv[3], r.getRoot(), "\t" ); | ||
20 | } | 19 | } |
21 | else if( argv[1][0] == 's' ) | 20 | else if( argv[1][0] == 's' ) |
22 | { | 21 | { |
23 | XmlStringReader r( argv[2], true ); | 22 | XmlStringReader r( argv[2], true ); |
24 | //XmlWriter::write( argv[3], r.getRoot(), "\t" ); | 23 | XmlWriter w( argv[3], "\t", r.detatchRoot() ); |
24 | w.write(); | ||
25 | } | 25 | } |
26 | 26 | ||
27 | return 0; | 27 | return 0; |
diff --git a/src/xmldocument.cpp b/src/xmldocument.cpp index 234ff81..32f1409 100644 --- a/src/xmldocument.cpp +++ b/src/xmldocument.cpp | |||
@@ -50,6 +50,13 @@ XmlNode *XmlDocument::getRoot() | |||
50 | return pRoot; | 50 | return pRoot; |
51 | } | 51 | } |
52 | 52 | ||
53 | XmlNode *XmlDocument::detatchRoot() | ||
54 | { | ||
55 | XmlNode *pTemp = pRoot; | ||
56 | pRoot = NULL; | ||
57 | return pTemp; | ||
58 | } | ||
59 | |||
53 | XmlNode *XmlDocument::getCurrent() | 60 | XmlNode *XmlDocument::getCurrent() |
54 | { | 61 | { |
55 | return pCurrent; | 62 | return pCurrent; |
diff --git a/src/xmldocument.h b/src/xmldocument.h index f9a8606..1a8eb52 100644 --- a/src/xmldocument.h +++ b/src/xmldocument.h | |||
@@ -148,6 +148,14 @@ public: | |||
148 | XmlNode *getRoot(); | 148 | XmlNode *getRoot(); |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Get a pointer to the root object of this XmlDocument, and remove the | ||
152 | * ownership from this object. | ||
153 | *@returns A pointer to an internally owned XmlNode. Do not delete this | ||
154 | * XmlNode. | ||
155 | */ | ||
156 | XmlNode *detatchRoot(); | ||
157 | |||
158 | /** | ||
151 | * Get the current context node, which could be the same as the root node. | 159 | * Get the current context node, which could be the same as the root node. |
152 | *@returns A pointer to an internally owned XmlNode. Do not delete this | 160 | *@returns A pointer to an internally owned XmlNode. Do not delete this |
153 | * XmlNode. | 161 | * XmlNode. |
diff --git a/src/xmlfilereader.cpp b/src/xmlfilereader.cpp index dd4bc82..9c0b7c1 100644 --- a/src/xmlfilereader.cpp +++ b/src/xmlfilereader.cpp | |||
@@ -55,10 +55,10 @@ char XmlFileReader::getChar( int nIndex ) | |||
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | void XmlFileReader::usedChar() | 58 | void XmlFileReader::usedChar( int nAmnt ) |
59 | { | 59 | { |
60 | if( fbDataIn.getLength() > 0 ) | 60 | if( fbDataIn.getLength()-nAmnt >= 0 ) |
61 | { | 61 | { |
62 | fbDataIn.usedData( 1 ); | 62 | fbDataIn.usedData( nAmnt ); |
63 | } | 63 | } |
64 | } | 64 | } |
diff --git a/src/xmlfilereader.h b/src/xmlfilereader.h index 3e996e6..24a6e28 100644 --- a/src/xmlfilereader.h +++ b/src/xmlfilereader.h | |||
@@ -39,7 +39,7 @@ public: | |||
39 | 39 | ||
40 | private: | 40 | private: |
41 | char getChar( int nIndex = 0 ); | 41 | char getChar( int nIndex = 0 ); |
42 | void usedChar(); | 42 | void usedChar( int nAmnt = 1 ); |
43 | FILE *fh; /**< The file handle. */ | 43 | FILE *fh; /**< The file handle. */ |
44 | FlexBuf fbDataIn; /**< The input buffer. */ | 44 | FlexBuf fbDataIn; /**< The input buffer. */ |
45 | }; | 45 | }; |
diff --git a/src/xmlreader.cpp b/src/xmlreader.cpp index 76c6258..70fd1d7 100644 --- a/src/xmlreader.cpp +++ b/src/xmlreader.cpp | |||
@@ -332,8 +332,7 @@ bool XmlReader::content() | |||
332 | } | 332 | } |
333 | setContent( fbContent.getData() ); | 333 | setContent( fbContent.getData() ); |
334 | } | 334 | } |
335 | usedChar(); | 335 | usedChar( 2 ); |
336 | usedChar(); | ||
337 | gcall( ws() ); | 336 | gcall( ws() ); |
338 | FlexBuf fbName; | 337 | FlexBuf fbName; |
339 | while( true ) | 338 | while( true ) |
@@ -368,6 +367,46 @@ bool XmlReader::content() | |||
368 | throw XmlException("Malformed close tag."); | 367 | throw XmlException("Malformed close tag."); |
369 | } | 368 | } |
370 | } | 369 | } |
370 | else if( getChar(1) == '!' ) | ||
371 | { | ||
372 | // We know it's a comment, let's see if it's proper | ||
373 | if( getChar(2) != '-' || | ||
374 | getChar(3) != '-' ) | ||
375 | { | ||
376 | // Not a valid XML comment | ||
377 | throw XmlException("Malformed comment start tag found."); | ||
378 | } | ||
379 | |||
380 | usedChar( 4 ); | ||
381 | |||
382 | // Now burn text until we find the close tag | ||
383 | for(;;) | ||
384 | { | ||
385 | if( getChar() == '-' ) | ||
386 | { | ||
387 | if( getChar( 1 ) == '-' ) | ||
388 | { | ||
389 | // The next one has to be a '>' now | ||
390 | if( getChar( 2 ) != '>' ) | ||
391 | { | ||
392 | throw XmlException("Malformed comment close tag found. You cannot have a '--' that isn't followed by a '>' in a comment."); | ||
393 | } | ||
394 | usedChar( 3 ); | ||
395 | break; | ||
396 | } | ||
397 | else | ||
398 | { | ||
399 | // Found a dash followed by a non dash, that's ok... | ||
400 | usedChar( 2 ); | ||
401 | } | ||
402 | } | ||
403 | else | ||
404 | { | ||
405 | // Burn comment chars | ||
406 | usedChar(); | ||
407 | } | ||
408 | } | ||
409 | } | ||
371 | else | 410 | else |
372 | { | 411 | { |
373 | if( fbContent.getLength() > 0 ) | 412 | if( fbContent.getLength() > 0 ) |
diff --git a/src/xmlreader.h b/src/xmlreader.h index 19e485a..4117dfd 100644 --- a/src/xmlreader.h +++ b/src/xmlreader.h | |||
@@ -57,7 +57,7 @@ private: | |||
57 | /** | 57 | /** |
58 | * Called to increment the current stream position by a single character. | 58 | * Called to increment the current stream position by a single character. |
59 | */ | 59 | */ |
60 | virtual void usedChar() = 0; | 60 | virtual void usedChar( int nAmnt = 1) = 0; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Automoton function: is whitespace. | 63 | * Automoton function: is whitespace. |
diff --git a/src/xmlstringreader.cpp b/src/xmlstringreader.cpp index 82caacd..211df78 100644 --- a/src/xmlstringreader.cpp +++ b/src/xmlstringreader.cpp | |||
@@ -29,10 +29,10 @@ char XmlStringReader::getChar( int nAdd ) | |||
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | void XmlStringReader::usedChar() | 32 | void XmlStringReader::usedChar( int nAmnt ) |
33 | { | 33 | { |
34 | if( nLength >= nIndex+1 ) | 34 | if( nLength >= nIndex+nAmnt ) |
35 | { | 35 | { |
36 | nIndex++; | 36 | nIndex += nAmnt; |
37 | } | 37 | } |
38 | } | 38 | } |
diff --git a/src/xmlstringreader.h b/src/xmlstringreader.h index 07da83c..19df427 100644 --- a/src/xmlstringreader.h +++ b/src/xmlstringreader.h | |||
@@ -40,7 +40,7 @@ public: | |||
40 | 40 | ||
41 | private: | 41 | private: |
42 | char getChar( int nIndex = 0 ); | 42 | char getChar( int nIndex = 0 ); |
43 | void usedChar(); | 43 | void usedChar( int nAmnt = 1 ); |
44 | const char *sString; /**< Internal pointer to the input string. */ | 44 | const char *sString; /**< Internal pointer to the input string. */ |
45 | int nIndex; /**< Our index into the string */ | 45 | int nIndex; /**< Our index into the string */ |
46 | int nLength; /**< The computed length of the string */ | 46 | int nLength; /**< The computed length of the string */ |