From 2ec19c1875597ce9f54f7efe271c4096b484866d Mon Sep 17 00:00:00 2001 From: Myun2 Date: Sat, 31 Jul 2010 04:15:54 +0900 Subject: [PATCH] =?utf8?q?sized=5Fcharbuf.hpp:=20to=5Fstring()=E3=82=92con?= =?utf8?q?st=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=81=AB=E3=80=82=20roast?= =?utf8?q?=5Fxml/roast=5Fxml=5Fsax=5Fparser.hpp:=20sax=5Fcallback=5Fsample?= =?utf8?q?=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/str/sized_charbuf.hpp | 2 +- .../roast/xml/roast_xml/roast_xml_sax_parser.hpp | 42 +++++++++++++++++++++- roast/test/lexical_test/parser_test.cpp | 3 +- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/roast/include/roast/str/sized_charbuf.hpp b/roast/include/roast/str/sized_charbuf.hpp index 9f31e931..5f7cd694 100644 --- a/roast/include/roast/str/sized_charbuf.hpp +++ b/roast/include/roast/str/sized_charbuf.hpp @@ -45,7 +45,7 @@ namespace roast sized_ccharbuf(T* ptr_in, size_t size_in) : _Base(ptr_in, size_in){} ///////////////////////////////////// - ::std::string to_string() + ::std::string to_string() const { return ::std::string(ptr, size); } diff --git a/roast/include/roast/xml/roast_xml/roast_xml_sax_parser.hpp b/roast/include/roast/xml/roast_xml/roast_xml_sax_parser.hpp index 86dc1eb2..705911d5 100644 --- a/roast/include/roast/xml/roast_xml/roast_xml_sax_parser.hpp +++ b/roast/include/roast/xml/roast_xml/roast_xml_sax_parser.hpp @@ -152,7 +152,47 @@ namespace roast sax_parser(const char* s) : _Base(s) {} }; - //////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////// + + + class sax_callback_sample + { + private: + ::std::string m_indent; + public: + void attribute( const sized_ccharbuf &attr_name, const sized_ccharbuf &attr_value ) + { + printf("%sattr: %s=\"%s\"\n", + m_indent.c_str(), + attr_name.to_string().c_str(), + attr_value.to_string().c_str() ); + } + + void comment( const sized_ccharbuf &s ) + { + printf("%scomment: \"%s\"\n", + m_indent.c_str(), + s.to_string().c_str() ); + } + + void text( const sized_ccharbuf &s ) + { + printf("%stext: \"%s\"\n", + m_indent.c_str(), + s.to_string().c_str() ); + } + void start_element( const sized_ccharbuf &s ) + { + printf("%s\n", m_indent.c_str(), m_indent.c_str()); + } + }; + + ////////////////////////////////////////////////////////////////////////////////////////// } } diff --git a/roast/test/lexical_test/parser_test.cpp b/roast/test/lexical_test/parser_test.cpp index 2930877f..f622e776 100644 --- a/roast/test/lexical_test/parser_test.cpp +++ b/roast/test/lexical_test/parser_test.cpp @@ -17,7 +17,8 @@ int main() fread(work,BUFF_SIZE,1,fp); //roast_xml::dom_parser wss("aaa"); - roast_xml::sax_parser sax(work); + roast_xml::sax_parser< + roast_xml::sax_callback_sample> sax(work); sax.analyze(); return 0; -- 2.11.0