diff --git a/README b/README index b186998..0aa0cf7 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -libStreamedXML http://www.lwithers.me.uk/projects/libStreamedXML/ +libStreamedXML ======================================================================== (c)2006, Laurence Withers, . Released under the GNU GPLv2. See file COPYING or @@ -11,8 +11,4 @@ To build: ./make.sh To install: ./make.sh install (you might want to set PREFIX, by default it's /usr/local) -Dependencies ------------- - -libutf8++ - http://www.lwithers.me.uk/projects/libutf8++/ +@TODO@ diff --git a/make.sh b/make.sh index f3f44d8..856f0d0 100755 --- a/make.sh +++ b/make.sh @@ -64,7 +64,6 @@ OUTPUT_DIRS="obj html" # none no special processing happens before each file # C #line directives are inserted before each file # and VERSION, VERMAJOR etc. are #defined -# Ch Like C, but for header files (no VERSION #defines) # make_monolithic() { if [ $# -ne 2 ] @@ -83,9 +82,6 @@ make_monolithic() { then HASHLINE=1 VERDEFINE=1 - elif [ "$2" == "Ch" ] - then - HASHLINE=1 elif [ "$2" == "none" ] then HASHLINE=0 # dummy command @@ -265,7 +261,7 @@ else targets="$@" fi -for func in ${targets} +for func in "${targets}" do case ${func} in clean) diff --git a/scripts/.gitignore b/scripts/.gitignore index a540f48..ce33425 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -1,6 +1,5 @@ build.c++.app build.c++.lib -build.c++.qtapp build.c++.tests build.c.app build.c.lib diff --git a/src/libStreamedXML/BottomHeader.h b/src/libStreamedXML/BottomHeader.h index fbf44c3..4bbc273 100644 --- a/src/libStreamedXML/BottomHeader.h +++ b/src/libStreamedXML/BottomHeader.h @@ -5,7 +5,3 @@ */ #endif -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/Callback.h b/src/libStreamedXML/Callback.h index 5ed5617..78f2add 100644 --- a/src/libStreamedXML/Callback.h +++ b/src/libStreamedXML/Callback.h @@ -177,9 +177,8 @@ public: /*! \brief Entity reference. \param name The name of the entity being referred to. - \param[out] value The expanded text. - \retval true if the entity is valid. - \retval false if the entity is not valid. + \returns The expanded text. + \throws UnknownEntity if the entity is unknown. This function is called whenever an entity reference is encountered, and \a expandEntities is \a true in your parser. The five standard @@ -187,18 +186,12 @@ public: but anything else will be passed to this function. */ - virtual bool entityRef(const std::wstring& name, std::wstring& value) + virtual std::wstring entityRef(const std::wstring& name) { - (void)name; - (void)value; - return false; + throw UnknownEntity(name); } }; }; -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/Decoder.cpp b/src/libStreamedXML/Decoder.cpp index 4eecb09..2a0d6fb 100644 --- a/src/libStreamedXML/Decoder.cpp +++ b/src/libStreamedXML/Decoder.cpp @@ -62,7 +62,3 @@ void Decoder::restart() } -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/Decoder.h b/src/libStreamedXML/Decoder.h index d62a93b..6f220bb 100644 --- a/src/libStreamedXML/Decoder.h +++ b/src/libStreamedXML/Decoder.h @@ -70,7 +70,3 @@ private: } -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/Exceptions.cpp b/src/libStreamedXML/Exceptions.cpp index ee909e6..68c079b 100644 --- a/src/libStreamedXML/Exceptions.cpp +++ b/src/libStreamedXML/Exceptions.cpp @@ -8,14 +8,14 @@ namespace lsx { -Exception::Exception(const std::wstring& reason, int line, int col) - : reason(reason), line(line), col(col) +Exception::Exception(const std::wstring& reason) + : reason(reason) { } -const char* Exception::what() const throw() +const char* Exception::what() { if(utf8Reason.empty()) utf8Reason = utf8::encode(reason, true); return utf8Reason.c_str(); @@ -23,46 +23,39 @@ const char* Exception::what() const throw() -NotWellFormed::NotWellFormed(const std::wstring& error, int line, int col) - : Exception(format(error, line, col), line, col), error(error) +NotWellFormed::NotWellFormed(const std::wstring& error) + : Exception(format(error)), error(error) { } -std::wstring NotWellFormed::format(const std::wstring& error, int line, int col) +std::wstring NotWellFormed::format(const std::wstring& error) { std::wostringstream ost; - ost << L"Streamed XML is not well formed:" - << L"\n line : " << line + 1 - << L"\n column: " << col + 1 - << L"\n reason: " << error; + ost << L"Streamed XML is not well formed:\n" + << error; return ost.str(); } -UnknownEntity::UnknownEntity(const std::wstring& name, int line, int col) - : Exception(format(name, line, col), line, col), name(name) +UnknownEntity::UnknownEntity(const std::wstring& name) + : Exception(format(name)), name(name) { } -std::wstring UnknownEntity::format(const std::wstring& name, int line, int col) +std::wstring UnknownEntity::format(const std::wstring& name) { std::wostringstream ost; - ost << L"Encountered an unknown entity in the Streamed XML:" - << L"\n line : " << line + 1 - << L"\n column: " << col + 1 - << L"\n name : " << name; + ost << L"Encountered an unknown entity named '" + << name + << L"' in the Streamed XML."; return ost.str(); } } -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/Exceptions.h b/src/libStreamedXML/Exceptions.h index fbabf73..398c51d 100644 --- a/src/libStreamedXML/Exceptions.h +++ b/src/libStreamedXML/Exceptions.h @@ -14,38 +14,30 @@ This class is the base class of all exceptions. It simply provides a mechanism f message; more specific details must be stored in base classes. */ -class Exception : public std::exception { +class Exception { public: /*! \brief Constructor. \param reason Reason for the exception. - \param line Line number of input (starting from 0). - \param col Column of input (starting from 0). The constructor simply stores the reason for the exception, which may be later accessed for reporting to the user. */ - Exception(const std::wstring& reason, int line, int col); + Exception(const std::wstring& reason); /// Destructor. virtual ~Exception() throw() { } /// Find what caused the error. - virtual const char* what() const throw(); + virtual const char* what(); /// Reason for the exception. const std::wstring reason; - - /// Line on which the exception occurred (starting from 0). - const int line; - - /// Column on which the exception occurred (starting from 0). - const int col; private: - mutable std::string utf8Reason; + std::string utf8Reason; }; @@ -53,20 +45,18 @@ private: /// Thrown when XML is not well formed. class NotWellFormed : public Exception { private: - static std::wstring format(const std::wstring& error, int line, int col); + static std::wstring format(const std::wstring& error); public: /*! \brief Constructor. \param error Reason for the error. - \param line Line on which the exception occurred. - \param col Column on which the exception occurred. The constructor will store the reason for the error. It will also prepare a suitable message for the Exception base class. */ - NotWellFormed(const std::wstring& error, int line, int col); + NotWellFormed(const std::wstring& error); /// Destructor. virtual ~NotWellFormed() throw() @@ -81,20 +71,18 @@ public: /// Thrown when an unknown entity is referred to. class UnknownEntity : public Exception { private: - static std::wstring format(const std::wstring& name, int line, int col); + static std::wstring format(const std::wstring& name); public: /*! \brief Constructor. \param name Name of the unknown entity. - \param line Line on which the exception occurred. - \param col Column on which the exception occurred. - + The constructor will store the name of the unknown entity. It will also prepare a suitable message for the Exception base class. */ - UnknownEntity(const std::wstring& name, int line, int col); + UnknownEntity(const std::wstring& name); /// Destructor. virtual ~UnknownEntity() throw() @@ -107,7 +95,3 @@ public: } -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/ForwardDeclare.h b/src/libStreamedXML/ForwardDeclare.h index 113253c..d3ad008 100644 --- a/src/libStreamedXML/ForwardDeclare.h +++ b/src/libStreamedXML/ForwardDeclare.h @@ -22,7 +22,3 @@ class UnknownEntity; } -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/Parser.cpp b/src/libStreamedXML/Parser.cpp index ee6f0f6..f6efd56 100644 --- a/src/libStreamedXML/Parser.cpp +++ b/src/libStreamedXML/Parser.cpp @@ -37,8 +37,6 @@ void Parser::reset() skipNextNewline = false; state = StateNone; restartCount = 0; - line = 0; - col = 0; } @@ -61,7 +59,7 @@ void Parser::feedChar(wchar_t ch) #define ERROR(_reason) do { \ state = StateError; \ - throw NotWellFormed(_reason, line, col); \ + throw NotWellFormed(_reason); \ }while(0) if(ch == xmlRestartMarker[restartCount]) { if(++restartCount == 11) { @@ -86,15 +84,11 @@ void Parser::feedChar(wchar_t ch) skipNextNewline = true; ch = L'\n'; c = ClassWhitespace; - ++line; - col = 0; goto doBuffer; case 0x2028: ch = L'\n'; c = ClassWhitespace; - ++line; - col = 0; break; case L' ': @@ -107,8 +101,6 @@ void Parser::feedChar(wchar_t ch) if(skipNextNewline) return; ch = L'\n'; c = ClassWhitespace; - ++line; - col = 0; break; case L':': @@ -163,26 +155,26 @@ doBuffer: break; case ClassOpenTag: - state = StateOpen; if(!buffer.empty()) callback->whiteSpace(buffer); + state = StateOpen; buffer.clear(); break; case ClassEntity: if(expandEntities) { if(!elementDepth) ERROR(L"Entities cannot appear at stream level."); - state = StateEntity; if(!buffer.empty()) callback->whiteSpace(buffer); buffer.clear(); parsingAttr = false; + state = StateEntity; break; } // fall through default: if(!elementDepth) ERROR(L"Content cannot appear at stream level."); - state = StateData; if(!buffer.empty()) callback->whiteSpace(buffer); + state = StateData; buffer = ch; break; } @@ -191,16 +183,16 @@ doBuffer: case StateData: switch(c) { case ClassOpenTag: - state = StateOpen; callback->content(buffer); buffer.clear(); + state = StateOpen; break; case ClassEntity: - state = StateEntity; callback->content(buffer); buffer.clear(); parsingAttr = false; + state = StateEntity; break; default: @@ -225,9 +217,9 @@ doBuffer: case StateCDATA2: if(ch == L'>') { - state = StateNone; callback->cdata(buffer); buffer.clear(); + state = StateNone; } else if(ch == L']') { buffer += ch; } else { @@ -298,9 +290,9 @@ doBuffer: case StatePI2: if(ch != L'>') ERROR(L"Invalid target for PI"); else { - state = StateNone; callback->PI(buffer2, L""); buffer.clear(); + state = StateNone; } break; @@ -311,15 +303,12 @@ doBuffer: case StatePI3: if(ch == L'>') { - state = StateNone; callback->PI(buffer2, buffer); buffer.clear(); - } else if(ch == '?') { - buffer += L'?'; + state = StateNone; } else { buffer += L'?'; buffer += ch; - state = StatePIData; } break; @@ -354,15 +343,14 @@ doBuffer: else { buffer += L'-'; buffer += ch; - state = StateComment; } break; case StateComment3: if(ch != L'>') ERROR(L"`--' not valid in comments"); - state = StateNone; callback->comment(buffer); buffer.clear(); + state = StateNone; break; case StateElemName: @@ -382,10 +370,10 @@ doBuffer: switch(ch) { case L'>': elemStack.push_back(buffer); - state = StateNone; - buffer.clear(); callback->element(buffer, elemAttrs); + state = StateNone; ++elementDepth; + buffer.clear(); break; case L'/': @@ -412,9 +400,9 @@ doBuffer: switch(ch) { case L'>': elemStack.push_back(elemName); - state = StateNone; - buffer.clear(); callback->element(elemName, elemAttrs); + buffer.clear(); + state = StateNone; ++elementDepth; break; @@ -474,10 +462,10 @@ doBuffer: if(ch == L'/') { state = StateNeedClose; } else if(ch == L'>') { - state = StateNone; - buffer.clear(); callback->element(elemName, elemAttrs); elemStack.push_back(elemName); + buffer.clear(); + state = StateNone; ++elementDepth; } else ERROR(L"Invalid character after attribute."); break; @@ -486,10 +474,10 @@ doBuffer: case StateNeedClose: if(ch != L'>') ERROR(L"Stray `/' in open tag."); - state = StateNone; - buffer.clear(); callback->element(elemName, elemAttrs); callback->closeTag(elemName); + buffer.clear(); + state = StateNone; break; case StateClose: @@ -513,9 +501,9 @@ doBuffer: if(ch != L'>') ERROR(L"Invalid character in close tag name."); if(elemStack.back() != buffer) ERROR(L"Mismatched close tag."); elemStack.pop_back(); - state = StateNone; - buffer.clear(); callback->closeTag(buffer); + buffer.clear(); + state = StateNone; --elementDepth; } break; @@ -525,9 +513,9 @@ doBuffer: if(ch != L'>') ERROR(L"Invalid data in close tag."); if(elemStack.back() != elemName) ERROR(L"Mismatched close tag."); elemStack.pop_back(); - state = StateNone; - buffer.clear(); callback->closeTag(elemName); + buffer.clear(); + state = StateNone; --elementDepth; break; @@ -578,7 +566,6 @@ doBuffer: break; } #undef ERROR - ++col; } @@ -590,16 +577,9 @@ std::wstring Parser::entityRef(const std::wstring& ent) if(ent == L"apos") return L"'"; if(ent == L"lt") return L"<"; if(ent == L"gt") return L">"; - - std::wstring result; - if(callback->entityRef(ent, result)) return result; - throw UnknownEntity(ent, line, col); + return callback->entityRef(ent); } } -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/Parser.h b/src/libStreamedXML/Parser.h index b0567fc..78f1493 100644 --- a/src/libStreamedXML/Parser.h +++ b/src/libStreamedXML/Parser.h @@ -120,9 +120,6 @@ private: bool skipNextNewline; int elementDepth, xmlCount, restartCount; - // for reporting errors - int line, col; - public: /*! \brief Constructor. @@ -224,7 +221,3 @@ public: } -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/TopHeader.h b/src/libStreamedXML/TopHeader.h index 4c33456..837f7c2 100644 --- a/src/libStreamedXML/TopHeader.h +++ b/src/libStreamedXML/TopHeader.h @@ -14,7 +14,3 @@ #include #include #include -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/TopSource.cpp b/src/libStreamedXML/TopSource.cpp index 5a08e5c..2ef09e7 100644 --- a/src/libStreamedXML/TopSource.cpp +++ b/src/libStreamedXML/TopSource.cpp @@ -8,7 +8,3 @@ // Below are all the includes used throughout the library. -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/ diff --git a/src/libStreamedXML/build.lib b/src/libStreamedXML/build.lib index 086ab44..b685b96 100644 --- a/src/libStreamedXML/build.lib +++ b/src/libStreamedXML/build.lib @@ -31,7 +31,7 @@ then echo " Compiling" SONAME="${libStreamedXML_BASE}.so.${SOMAJOR}.${SOMINOR}" - do_cmd ${CXX} ${CFLAGS} -Iobj -shared -fpic -o "${libStreamedXML}" \ + do_cmd ${CXX} ${CFLAGS} -shared -fpic -o "${libStreamedXML}" \ -Wl,-soname,${SONAME} \ ${SRC} ${SO_EXTRA} || return 1 diff --git a/src/libStreamedXML/build.monolithic b/src/libStreamedXML/build.monolithic index cc582d4..2a05e4b 100644 --- a/src/libStreamedXML/build.monolithic +++ b/src/libStreamedXML/build.monolithic @@ -9,7 +9,7 @@ MONOLITHIC_TESTS="src/libStreamedXML/build.lib src/libStreamedXML/build.monolith if [ -z "${libStreamedXML_MONOLITHIC}" ] then MONOLITHIC_SOURCE="$(echo src/libStreamedXML/{TopHeader,ForwardDeclare,Exceptions,Callback,Parser,Decoder,BottomHeader}.h)" - make_monolithic ${HDR} Ch || return 1 + make_monolithic ${HDR} C || return 1 MONOLITHIC_SOURCE="$(echo src/libStreamedXML/{TopSource,Exceptions,Parser,Decoder}.cpp)" make_monolithic ${SRC} C || return 1 diff --git a/src/libStreamedXML/soversion b/src/libStreamedXML/soversion index c4c84a8..b706c89 100644 --- a/src/libStreamedXML/soversion +++ b/src/libStreamedXML/soversion @@ -11,7 +11,7 @@ # be bumped on a binary-incompatible release. They are both single # integers. SOMAJOR=0 -SOMINOR=1 +SOMINOR=0 # SOMICRO is bumped every time there is a binary-compatible release. -SOMICRO=3 +SOMICRO=0 diff --git a/version b/version index a0ec19b..1eaadc1 100644 --- a/version +++ b/version @@ -11,8 +11,8 @@ # expected to be in 'major.minor.micro' format. It can optionally be # suffixed with a string. VERMAJOR=1 -VERMINOR=2 -VERMICRO=8 +VERMINOR=1 +VERMICRO=0 VEREXTRA="" # kate: replace-trailing-space-save true; space-indent true; tab-width 4;