📄 parser.cpp
字号:
} else { this->ref_state_ = ACEXML_ParserInt::IN_CONTENT; int length = this->parse_entity_reference(ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); if (length == 1) cdata_length++; } break; case '\x20': case '\x0D': case '\x0A': case '\x09':// if (this->validate_)// {// // Flush out any non-whitespace characters// if (cdata_length != 0)// {// cdata = this->obstack_.freeze ();// this->content_handler_->characters(cdata, 0, cdata_length// ACEXML_ENV_ARG_PARAMETER);// ACEXML_CHECK_RETURN (-1);// this->obstack_.unwind (cdata);// cdata_length = 0;// }// ++cdata_length;// this->obstack_.grow (ch);// while (1)// {// ch = this->peek();// if (ch == '\x20' || ch == '\x0D' || ch == '\x0A' ||// ch == '\x09')// {// ch = this->get();// this->obstack_.grow (ch);// continue;// }// break;// }// cdata = this->obstack_.freeze ();// this->content_handler_->ignorableWhitespace (cdata, 0,// cdata_length// ACEXML_ENV_ARG_PARAMETER);// ACEXML_CHECK_RETURN (-1);// this->obstack_.unwind (cdata);// cdata_length = 0;// break;// } // Fall thru... default: ++cdata_length; this->obstack_.grow (ch); } } ACE_NOTREACHED (return 0;)}intACEXML_Parser::parse_cdata (ACEXML_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ((ACEXML_SAXException)){ if (this->parse_token (ACE_TEXT ("[CDATA[")) < 0) { this->fatal_error(ACE_TEXT ("Expecting '[CDATA[' at beginning of CDATA ") ACE_TEXT ("section") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } ACEXML_Char ch; int datalen = 0; ACEXML_Char *cdata = 0; while (1) { ch = this->get (); // Anything goes except the sequence "]]>". if (ch == ']' && this->peek() == ']') { ACEXML_Char temp = ch; ch = this->get(); if (ch == ']' && this->peek() == '>') { ch = this->get(); cdata = this->obstack_.freeze (); this->content_handler_->characters (cdata, 0, datalen ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); this->obstack_.unwind(cdata); return 0; } this->obstack_.grow (temp); ++datalen; } this->obstack_.grow (ch); ++datalen; }; ACE_NOTREACHED (return -1);}intACEXML_Parser::parse_entity_decl (ACEXML_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ((ACEXML_SAXException)){ ACEXML_Char nextch = 0; if ((this->parse_token (ACE_TEXT ("NTITY")) < 0) || this->skip_whitespace_count (&nextch) == 0) { this->fatal_error (ACE_TEXT ("Expecting keyword ENTITY followed by a ") ACE_TEXT ("space") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } int is_GEDecl = 1; if (nextch == '%') // This is a PEDecl. { is_GEDecl = 0; this->get (); // consume the '%' if (this->skip_whitespace_count (&nextch) == 0) { this->fatal_error (ACE_TEXT ("Expecting space between % and ") ACE_TEXT ("entity name") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } } ACEXML_Char *entity_name = this->parse_name (); if (entity_name == 0) { this->fatal_error (ACE_TEXT ("Invalid entity name") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } if (this->skip_whitespace_count (&nextch) == 0) { this->fatal_error (ACE_TEXT ("Expecting space between entity name and ") ACE_TEXT ("entityDef") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } int retval = 0; if (nextch == '\'' || nextch == '"') { ACEXML_Char *entity_value = 0; if (this->parse_entity_value (entity_value ACEXML_ENV_ARG_PARAMETER) != 0) { this->fatal_error(ACE_TEXT ("Invalid EntityValue") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } if (is_GEDecl) retval = this->internal_GE_.add_entity (entity_name, entity_value); else retval = this->internal_PE_.add_entity (entity_name, entity_value); if (retval < 0) { this->fatal_error (ACE_TEXT ("Internal Parser Error in adding") ACE_TEXT ("Entity to map") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } else if (retval == 1) { this->warning (ACE_TEXT ("Duplicate entity found") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } } else { ACEXML_Char *systemid, *publicid; this->parse_external_id (publicid, systemid ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); if (systemid == 0) { this->fatal_error(ACE_TEXT ("Invalid SystemLiteral") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } this->skip_whitespace_count (&nextch); if (nextch == 'N') // NDATA section followed { if (is_GEDecl == 0) { this->fatal_error(ACE_TEXT ("Invalid NDataDecl in PEDef") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } if ((this->parse_token (ACE_TEXT ("NDATA")) < 0) || this->skip_whitespace_count (&nextch) == 0) { this->fatal_error(ACE_TEXT ("Expecting keyword NDATA followed ") ACE_TEXT ("by a space") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } ACEXML_Char *ndata = this->parse_name (); if (this->validate_) // [VC: Notation Declared] { if (!this->notations_.resolve_entity (ndata)) { this->fatal_error (ACE_TEXT ("Undeclared Notation name") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } this->dtd_handler_->unparsedEntityDecl(entity_name, publicid, systemid, ndata ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } } else { if (is_GEDecl) retval = this->external_GE_.add_entity (entity_name, systemid); else retval = this->external_PE_.add_entity (entity_name, systemid); if (retval < 0) { this->fatal_error(ACE_TEXT ("Internal Parser Error") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } else if (retval == 1) this->warning(ACE_TEXT ("Duplicate external entity") ACEXML_ENV_ARG_PARAMETER); if (is_GEDecl) retval = this->external_GE_.add_entity (entity_name, publicid); else retval = this->external_PE_.add_entity (entity_name, publicid); if (retval < 0) { this->fatal_error(ACE_TEXT ("Internal Parser Error") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } else if (retval == 1) this->warning (ACE_TEXT ("Duplicate entity definition") ACEXML_ENV_ARG_PARAMETER); } } // End of ENTITY definition if (this->skip_whitespace() != '>') { this->fatal_error(ACE_TEXT ("Expecting '>' at end of entityDef") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } return 0;}intACEXML_Parser::parse_attlist_decl (ACEXML_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ((ACEXML_SAXException)){ if (this->parse_token (ACE_TEXT ("ATTLIST")) < 0) { this->fatal_error(ACE_TEXT ("Expecting keyword 'ATTLIST'") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } int count = check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); if (!count) { this->fatal_error(ACE_TEXT ("Expecting space between ATTLIST and ") ACE_TEXT ("element name") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } ACEXML_Char *element_name = this->parse_name (); if (element_name == 0) { this->fatal_error(ACE_TEXT ("Invalid element Name in attlistDecl") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } ACEXML_Char fwd = 0; count = this->skip_whitespace_count (&fwd); // Parse AttDef* while (fwd != '>') { if (!this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER) && !count) this->fatal_error(ACE_TEXT ("Expecting space between element ") ACE_TEXT ("name and AttDef") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); this->skip_whitespace_count (&fwd); if (fwd == '>') break; count = this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); this->parse_attname (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); count = this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); if (!count) { this->fatal_error(ACE_TEXT ("Expecting space between AttName and ") ACE_TEXT ("AttType") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } this->parse_atttype (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); count = this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); if (!count) { this->fatal_error(ACE_TEXT ("Expecting space between AttType and") ACE_TEXT (" DefaultDecl") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } this->parse_defaultdecl (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); count = this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); this->skip_whitespace_count(&fwd); } this->get (); // consume closing '>' return 0;}intACEXML_Parser::check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_DECL){ ACEXML_Char fwd = '\xFF'; // Skip any leading whitespaces and store the number of such chars skipped int count = this->skip_whitespace_count (&fwd); if (fwd == 0) { this->get(); // Consume the 0 this->pop_context (0 ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); fwd = this->peek(); } if (fwd == '%') { this->get(); // Consume the % if (this->external_subset_) { this->parse_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } else { this->fatal_error(ACE_TEXT ("Illegal PERef within markupDecl") ACEXML_ENV_ARG_PARAMETER); ACEXML_CHECK_RETURN (-1); } } if (count)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -