Update of /cvsroot/adobe-source/sandbox/visual_refactor/adobe/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32297/visual_refactor/adobe/source
Modified Files:
xstr.cpp
Log Message:
References added to xstr; hex references still need work though
Index: xstr.cpp
===================================================================
RCS file: /cvsroot/adobe-source/sandbox/visual_refactor/adobe/source/xstr.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** xstr.cpp 18 Apr 2005 21:15:44 -0000 1.1
--- xstr.cpp 19 Apr 2005 20:59:32 -0000 1.2
***************
*** 248,251 ****
--- 248,252 ----
typedef store_t::value_type store_value_type;
typedef std::pair<store_iterator, store_iterator> store_range_pair_t;
+ typedef std::map<adobe::name_t, const char*, name_less_t> entity_map_t;
/*************************************************************************************************/
***************
*** 257,260 ****
--- 258,262 ----
static store_t* xstr_store_g = 0;
static node_t::attribute_set_t* default_context_g = 0;
+ static entity_map_t* entity_map_g = 0;
/*************************************************************************************************/
***************
*** 330,333 ****
--- 332,349 ----
xstr_store_g = &xstr_store_s;
default_context_g = &default_context_s;
+
+ // initialize the entity map
+
+ static entity_map_t entity_map_s;
+
+ entity_map_s[adobe::static_name_t("<")] = "<";
+ entity_map_s[adobe::static_name_t(">")] = ">";
+ entity_map_s[adobe::static_name_t("&")] = "&";
+ entity_map_s[adobe::static_name_t("'")] = "\'";
+ entity_map_s[adobe::static_name_t(""")] = "\"";
+ entity_map_s[adobe::static_name_t("©")] = "\xA9";
+ entity_map_s[adobe::static_name_t("®")] = "\xAE";
+
+ entity_map_g = &entity_map_s;
}
***************
*** 514,517 ****
--- 530,575 ----
/*************************************************************************************************/
+ void commit_content(adobe::name_t& name, std::string& content)
+ {
+ name = adobe::name_t(content.c_str(), content.size());
+
+ content = std::string();
+ }
+
+ /*************************************************************************************************/
+
+ void append_content(std::string& content, const char* first, const char* last)
+ {
+ content += std::string(first, last);
+ }
+
+ /*************************************************************************************************/
+
+ void translate_entity(std::string& content, const char* first, const char* last)
+ {
+ entity_map_t::const_iterator result(entity_map_g->find(adobe::name_t(first, last - first)));
+
+ if (result != entity_map_g->end())
+ content += result->second;
+ }
+
+ /*************************************************************************************************/
+
+ void translate_char(std::string& content, const char* first, const char* last)
+ {
+ std::string char_ref(first, last);
+
+ if (char_ref[2] == 'x')
+ {
+ // REVISIT (fbrereto) : Process hex digits
+ }
+ else
+ {
+ content += std::string::value_type(std::atoi(first + 2));
+ }
+ }
+
+ /*************************************************************************************************/
+
void push_and_clear_node(node_set_t& node_set, node_t& new_node)
{
***************
*** 542,545 ****
--- 600,604 ----
node_t::attribute_t cur_attribute;
node_t cur_node;
+ std::string cur_content;
// NOTE (fbrereto) : Naming conventions for these rules should follow XML 1.1 spec:
***************
*** 561,564 ****
--- 620,626 ----
boost::spirit::rule<> attribute; // http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-Attribute
boost::spirit::rule<> content; // http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-content
+ boost::spirit::rule<> reference; // http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-Reference
+ boost::spirit::rule<> entity_ref; // http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-EntityRef
+ boost::spirit::rule<> char_ref; // http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-CharRef
boost::spirit::rule<> att_value; // http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-AttValue
***************
*** 595,598 ****
--- 657,667 ----
};
+ boost::spirit::error_status<> clear_cur_content()
+ {
+ cur_content = std::string();
+
+ return boost::spirit::error_status<>(boost::spirit::error_status<>::fail);
+ }
+
boost::spirit::guard<parser_error_t> guard_m;
boost::spirit::assertion<parser_error_t> expect_open_token;
***************
*** 649,653 ****
element
= ( s_tag
! >> content[boost::bind(assign_name, boost::ref(cur_node.value_m), _1, _2)]
>> e_tag
)
--- 718,722 ----
element
= ( s_tag
! >> content[boost::bind(commit_content, boost::ref(cur_node.value_m), boost::ref(cur_content))]
>> e_tag
)
***************
*** 727,731 ****
content
! = *( ( boost::spirit::space_p | boost::spirit::print_p ) - boost::spirit::ch_p('<') )
;
--- 796,823 ----
content
! = guard_m
! (
! *(
! reference
! | (( boost::spirit::space_p | boost::spirit::print_p ) - boost::spirit::ch_p('<'))[boost::bind(append_content, boost::ref(cur_content), _1, _2)]
! )
! )[boost::bind(clear_cur_content, boost::ref(*this))]
! ;
!
!
! reference
! = entity_ref[boost::bind(translate_entity, boost::ref(cur_content), _1, _2)]
! | char_ref[boost::bind(translate_char, boost::ref(cur_content), _1, _2)]
! ;
!
!
! entity_ref
! = '&' >> name >> ';'
! ;
!
!
! char_ref
! = "&#" >> +boost::spirit::digit_p >> ';'
! | "&#x" >> +boost::spirit::xdigit_p >> ';'
;
|