#ifdef _MSC_VER #pragma warning(disable : 4786) #endif #include #include #include #include #include #include template string_type normalise_whitespace(const string_type& ch) { std::string value = string_adaptor::asStdString(ch); return string_adaptor::construct_from_utf8(normalise_whitespace >(ch)); } // normalise_whitespace template<> std::string normalise_whitespace >(const std::string& ch) { std::string value(ch); std::string::const_iterator i = value.begin(), ie = value.end(); std::string::iterator p = value.begin(), pe = value.end(); // string leading space while((i != ie) && (Arabica::XML::is_space(static_cast(*i)))) ++i; while(i != ie) { while((i != ie) && (!Arabica::XML::is_space(static_cast(*i)))) *p++ = *i++; while((i != ie) && (Arabica::XML::is_space(static_cast(*i)))) ++i; if(i != ie) *p++ = Arabica::Unicode::SPACE; } // while ... if(p != ie) *p++ = 0; return value; } // normalise_whitespace template > class basic_WhitespaceStripper : public SAX::basic_XMLFilterImpl { public: typedef string_type stringT; typedef SAX::basic_XMLFilterImpl XMLFilterT; basic_WhitespaceStripper() { } virtual void characters(const stringT& ch) { XMLFilterT::characters(normalise_whitespace(ch)); } // characters virtual void ignorableWhitespace(const stringT& ch) { } // ignorableWhitespace }; // class basic_WhitespaceStripper int main(int argc, char* argv[]) { std::cout << "tests go here" << std::endl; std::ostringstream output; std::ostringstream output2; SAX::Writer writer2(output2, 2); basic_WhitespaceStripper stripper; SAX::Writer writer(output, 4); SAX::XMLReader parser; SAX::CatchErrorHandler eh; writer.setParent(parser); writer.setErrorHandler(eh); stripper.setParent(writer); writer2.setParent(stripper); writer2.setErrorHandler(eh); std::stringstream ss; ss << "

Woo

"; SAX::InputSource is(ss); writer2.parse(is); std::cout << "1: " << output.str() << std::endl; std::cout << "2: " << output2.str() << std::endl; return 0; } // main // end of file