diff options
| author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-24 02:13:46 +0100 | 
|---|---|---|
| committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-24 02:13:46 +0100 | 
| commit | 5a67fc7d682ddba6a862aacf616d02cd20b727eb (patch) | |
| tree | 34a6e34d835f70459f3cb6aed9543cc22319a92b /src/formats/osxml | |
| parent | 8891dea26a1653a003b4171155e155d3aa6689ae (diff) | |
start of branch, commit log will be rewritten
Diffstat (limited to 'src/formats/osxml')
| -rw-r--r-- | src/formats/osxml/OsxmlEventParser.cpp | 63 | ||||
| -rw-r--r-- | src/formats/osxml/OsxmlEventParser.hpp | 31 | 
2 files changed, 12 insertions, 82 deletions
diff --git a/src/formats/osxml/OsxmlEventParser.cpp b/src/formats/osxml/OsxmlEventParser.cpp index c9254b0..855f80d 100644 --- a/src/formats/osxml/OsxmlEventParser.cpp +++ b/src/formats/osxml/OsxmlEventParser.cpp @@ -25,7 +25,6 @@  #include <core/common/Variant.hpp>  #include <core/common/VariantReader.hpp>  #include <core/common/Utils.hpp> -#include <core/common/WhitespaceHandler.hpp>  #include "OsxmlAttributeLocator.hpp"  #include "OsxmlEventParser.hpp" @@ -57,17 +56,6 @@ public:  	std::vector<char> textBuf;  	/** -	 * Current whitespace buffer (for the trimming whitspace mode) -	 */ -	std::vector<char> whitespaceBuf; - -	/** -	 * Flag indicating whether a whitespace character was present (for the -	 * collapsing whitespace mode). -	 */ -	bool hasWhitespace; - -	/**  	 * Current character data start.  	 */  	size_t textStart; @@ -394,33 +382,17 @@ static void xmlCharacterDataHandler(void *ref, const XML_Char *s, int len)  	SourceLocation loc = xmlSyncLoggerPosition(p, ulen);  	// Fetch some variables for convenience -	const WhitespaceMode mode = parser->getWhitespaceMode();  	OsxmlEventParserData &data = parser->getData();  	std::vector<char> &textBuf = data.textBuf; -	std::vector<char> &whitespaceBuf = data.whitespaceBuf; -	bool &hasWhitespace = data.hasWhitespace; -	size_t &textStart = data.textStart; -	size_t &textEnd = data.textEnd; - -	size_t pos = loc.getStart(); -	for (size_t i = 0; i < ulen; i++, pos++) { -		switch (mode) { -			case WhitespaceMode::PRESERVE: -				PreservingWhitespaceHandler::append(s[i], pos, pos + 1, textBuf, -				                                    textStart, textEnd); -				break; -			case WhitespaceMode::TRIM: -				TrimmingWhitespaceHandler::append(s[i], pos, pos + 1, textBuf, -				                                  textStart, textEnd, -				                                  whitespaceBuf); -				break; -			case WhitespaceMode::COLLAPSE: -				CollapsingWhitespaceHandler::append(s[i], pos, pos + 1, textBuf, -				                                    textStart, textEnd, -				                                    hasWhitespace); -				break; -		} + +	// Update start and end position +	if (textBuf.empty()) { +		data.textStart = loc.getStart();  	} +	data.textEnd = loc.getEnd(); + +	// Insert the data into the text buffer +	textBuf.insert(textBuf.end(), &s[0], &s[ulen]);  }  /* Class OsxmlEvents */ @@ -430,11 +402,7 @@ OsxmlEvents::~OsxmlEvents() {}  /* Class OsxmlEventParser */  OsxmlEventParserData::OsxmlEventParserData() -    : depth(0), -      annotationEndTagDepth(-1), -      hasWhitespace(false), -      textStart(0), -      textEnd(0) +    : depth(0), annotationEndTagDepth(-1), textStart(0), textEnd(0)  {  } @@ -466,8 +434,6 @@ Variant OsxmlEventParserData::getText(SourceId sourceId)  	// Reset the text buffers  	textBuf.clear(); -	whitespaceBuf.clear(); -	hasWhitespace = false;  	textStart = 0;  	textEnd = 0; @@ -482,7 +448,6 @@ OsxmlEventParser::OsxmlEventParser(CharReader &reader, OsxmlEvents &events,      : reader(reader),        events(events),        logger(logger), -      whitespaceMode(WhitespaceMode::COLLAPSE),        data(new OsxmlEventParserData())  {  } @@ -532,16 +497,6 @@ void OsxmlEventParser::parse()  	}  } -void OsxmlEventParser::setWhitespaceMode(WhitespaceMode whitespaceMode) -{ -	this->whitespaceMode = whitespaceMode; -} - -WhitespaceMode OsxmlEventParser::getWhitespaceMode() const -{ -	return whitespaceMode; -} -  CharReader &OsxmlEventParser::getReader() const { return reader; }  Logger &OsxmlEventParser::getLogger() const { return logger; } diff --git a/src/formats/osxml/OsxmlEventParser.hpp b/src/formats/osxml/OsxmlEventParser.hpp index e39245f..e3fd5d4 100644 --- a/src/formats/osxml/OsxmlEventParser.hpp +++ b/src/formats/osxml/OsxmlEventParser.hpp @@ -32,8 +32,6 @@  #include <memory>  #include <string> -#include <core/common/Whitespace.hpp> -  namespace ousia {  // Forward declarations @@ -99,13 +97,10 @@ public:  	virtual void fieldEnd() = 0;  	/** -	 * Called whenever data is found. Whitespace data is handled as specified -	 * and the data has been parsed to the specified variant type. This function -	 * is not called if the parsing failed, the parser prints an error message -	 * instead. +	 * Called whenever string data is found.  	 * -	 * @param data is the already parsed data that should be passed to the -	 * handler. +	 * @param data is a Variant containing the string data that was found in the +	 * XML file.  	 */  	virtual void data(const Variant &data) = 0;  }; @@ -135,11 +130,6 @@ private:  	Logger &logger;  	/** -	 * Current whitespace mode. -	 */ -	WhitespaceMode whitespaceMode; - -	/**  	 * Data to be used by the internal functions.  	 */  	std::unique_ptr<OsxmlEventParserData> data; @@ -171,21 +161,6 @@ public:  	void parse();  	/** -	 * Sets the whitespace handling mode. -	 * -	 * @param whitespaceMode defines how whitespace in the data should be -	 * handled. -	 */ -	void setWhitespaceMode(WhitespaceMode whitespaceMode); - -	/** -	 * Returns the current whitespace handling mode. -	 * -	 * @return the currently set whitespace handling mode. -	 */ -	WhitespaceMode getWhitespaceMode() const; - -	/**  	 * Returns the internal CharReader reference.  	 *  	 * @return the CharReader reference.  | 
