⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.cpp

📁 ACE编程的一本经典BIBLE的源代码,喜欢网络编程的别错过
💻 CPP
📖 第 1 页 / 共 5 页
字号:

  ACE_NOTREACHED (return -1);
}

int
ACEXML_Parser::parse_external_dtd (ACEXML_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  this->ref_state_ = ACEXML_ParserInt::IN_EXT_DTD;
  ACEXML_Char* publicId = 0;
  ACEXML_Char* systemId = 0;
  if (this->parse_external_id (publicId, systemId
                               ACEXML_ENV_ARG_PARAMETER) != 0)
    {
      this->fatal_error (ACE_TEXT ("Error in parsing ExternalID")
                         ACEXML_ENV_ARG_PARAMETER);
      ACEXML_CHECK_RETURN (-1);
    }
  if (this->validate_)
    {
      ACEXML_Char* uri = this->normalize_systemid (systemId);
      ACE_Auto_Basic_Array_Ptr<ACEXML_Char> cleanup_uri (uri);
      ACEXML_InputSource* ip = 0;
      if (this->entity_resolver_)
        {
          ip = this->entity_resolver_->resolveEntity (publicId,
                                                      (uri ? uri : systemId)
                                                      ACEXML_ENV_ARG_PARAMETER);
          ACEXML_CHECK_RETURN (-1);
        }
      if (ip)
        {
          if (this->switch_input (ip, (uri ? uri : systemId), publicId) != 0)
            return -1;
        }
      else
        {
          ACEXML_StreamFactory factory;
          ACEXML_CharStream* cstream = factory.create_stream (uri ?
                                                              uri: systemId);
          if (!cstream) {
            this->fatal_error (ACE_TEXT ("Invalid input source")
                               ACEXML_ENV_ARG_PARAMETER);
            ACEXML_CHECK_RETURN (-1);
          }
          if (this->switch_input (cstream, systemId, publicId) != 0)
            return -1;
        }
      this->parse_external_subset (ACEXML_ENV_SINGLE_ARG_PARAMETER);
      ACEXML_CHECK_RETURN (-1);
    }
  return 0;
}


int
ACEXML_Parser::parse_external_subset (ACEXML_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  this->ref_state_ = ACEXML_ParserInt::IN_EXT_DTD;
  this->external_subset_ = 1;
  int nrelems = 0;
  ACEXML_Char nextch = this->skip_whitespace();
  do {
    switch (nextch)
      {
        case '<':
          nextch = this->get();
          switch (nextch)
            {
              case '!':
                nextch = this->peek();
                if (nextch == '[')
                  this->parse_conditional_section (ACEXML_ENV_SINGLE_ARG_PARAMETER);
                else
                  this->parse_markup_decl (ACEXML_ENV_SINGLE_ARG_PARAMETER);
                ACEXML_CHECK_RETURN (-1);
                break;
              case '?':
                nextch = this->peek();
                if (nextch == 'x')
                  this->parse_text_decl (ACEXML_ENV_SINGLE_ARG_PARAMETER);
                else
                  this->parse_processing_instruction (ACEXML_ENV_SINGLE_ARG_PARAMETER);
                ACEXML_CHECK_RETURN (-1);
                break;
              default:
                this->fatal_error (ACE_TEXT ("Invalid content in external DTD")
                                   ACEXML_ENV_ARG_PARAMETER);
                ACEXML_CHECK_RETURN (-1);
            }
          break;
        case '%':
          this->parse_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
          ACEXML_CHECK_RETURN (-1);
          break;
        case 0:
          nrelems = this->pop_context (0 ACEXML_ENV_ARG_PARAMETER);
          ACEXML_CHECK_RETURN (-1);
          if (nrelems == 1)
            return 0;
          break;
        default:
          this->fatal_error (ACE_TEXT ("Invalid content in external DTD")
                             ACEXML_ENV_ARG_PARAMETER);
          ACEXML_CHECK_RETURN (-1);
      }
    nextch = this->skip_whitespace();
  } while (1);
}

int
ACEXML_Parser::parse_conditional_section (ACEXML_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACEXML_Char ch = this->get ();
  int include = 0;
  if (ch != '[')
    {
      this->fatal_error(ACE_TEXT ("Internal Parser Error")
                        ACEXML_ENV_ARG_PARAMETER);
      ACEXML_CHECK_RETURN (-1);
    }
  ch = this->skip_whitespace();
  if (ch == '%')
    {
      this->parse_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
      ACEXML_CHECK_RETURN (-1);
      ch = this->skip_whitespace();
    }
  if (ch == 'I')
    {
      ch = this->get();
      switch (ch)
        {
          case 'N':
            if (this->parse_token (ACE_TEXT ("CLUDE")) < 0)
              {
                this->fatal_error (ACE_TEXT ("Expecting keyword INCLUDE in ")
                                   ACE_TEXT ("conditionalSect")
                                   ACEXML_ENV_ARG_PARAMETER);
                ACEXML_CHECK_RETURN (-1);
              }
            include = 1;
            break;
          case 'G':
            if (this->parse_token (ACE_TEXT ("GNORE")) < 0)
              {
                this->fatal_error (ACE_TEXT ("Expecting keyword IGNORE in ")
                                   ACE_TEXT ("conditionalSect")
                                   ACEXML_ENV_ARG_PARAMETER);
                ACEXML_CHECK_RETURN (-1);
              }
            include = 0;
            break;
          default:
            this->fatal_error (ACE_TEXT ("Invalid conditionalSect")
                               ACEXML_ENV_ARG_PARAMETER);
            ACEXML_CHECK_RETURN (-1);
        }
      ACEXML_Char fwd = '\xFF';
      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);
        }
    }
  else
    {
      this->fatal_error (ACE_TEXT ("Invalid conditionalSect")
                         ACEXML_ENV_ARG_PARAMETER);
      ACEXML_CHECK_RETURN (-1);
    }
  if (this->skip_whitespace() != '[')
    {
      this->fatal_error (ACE_TEXT ("Expecting '[' in conditionalSect")
                         ACEXML_ENV_ARG_PARAMETER);
      ACEXML_CHECK_RETURN (-1);
    }
  if (include)
    this->parse_includesect (ACEXML_ENV_SINGLE_ARG_PARAMETER);
  else
    this->parse_ignoresect (ACEXML_ENV_SINGLE_ARG_PARAMETER);
  ACEXML_CHECK_RETURN (-1);
  return 0;
}

int
ACEXML_Parser::parse_ignoresect (ACEXML_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACEXML_Char nextch = this->skip_whitespace();
  int count = 0;
  int done = 0;
  do {
    switch (nextch)
      {
        case '<':
          if (this->peek() == '!')
            {
              this->get();
              if (this->peek() == '[')
                {
                  this->get();
                  count++;
                }
            }
          break;
        case ']':
          if (this->peek() == ']')
            {
              this->get();
              if (this->peek() == '>')
                {
                  this->get();
                  if (count)
                    {
                      --count;
                      break;
                    }
                  done = 1;
                }
            }
          break;
        case 0: // [VC: Proper Conditional Section/PE Nesting]
          if (count != 0)
            {
              this->fatal_error (ACE_TEXT ("Invalid Conditional Section/PE ")
                                 ACE_TEXT ("Nesting ")
                                 ACEXML_ENV_ARG_PARAMETER);
              ACEXML_CHECK_RETURN (-1);
            }
        default:
          break;
      }
    if (done)
      break;
    nextch = this->get();
  } while (1);

  return 0;
}

int
ACEXML_Parser::parse_includesect (ACEXML_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACEXML_Char nextch = this->skip_whitespace();
  do {
    switch (nextch)
      {
        case '<':
          nextch = this->get();
          switch (nextch)
            {
              case '!':
                nextch = this->peek();
                if (nextch == '[')
                  this->parse_conditional_section (ACEXML_ENV_SINGLE_ARG_PARAMETER);
                else
                  this->parse_markup_decl (ACEXML_ENV_SINGLE_ARG_PARAMETER);
                ACEXML_CHECK_RETURN (-1);
                break;
              case '?':
                nextch = this->peek();
                this->parse_processing_instruction (ACEXML_ENV_SINGLE_ARG_PARAMETER);
                ACEXML_CHECK_RETURN (-1);
                break;
              default:
                this->fatal_error (ACE_TEXT ("Invalid includeSect")
                                   ACEXML_ENV_ARG_PARAMETER);
                ACEXML_CHECK_RETURN (-1);
            }
          break;
        case '%':
          this->parse_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
          ACEXML_CHECK_RETURN (-1);
          break;
        case 0: // [VC: Proper Conditional Section/PE Nesting]
          this->fatal_error (ACE_TEXT ("Invalid Conditional Section/PE ")
                             ACE_TEXT ("Nesting ")
                             ACEXML_ENV_ARG_PARAMETER);
          ACEXML_CHECK_RETURN (-1);
        case ']':
          if (this->peek() == ']')
            {
              nextch = this->get();
              if (this->peek() == '>')
                {
                  nextch = this->get();
                  return 0;
                }
            }
        default:
          this->fatal_error (ACE_TEXT ("Invalid includeSect")
                             ACEXML_ENV_ARG_PARAMETER);
          ACEXML_CHECK_RETURN (-1);
      }
    nextch = this->skip_whitespace();
  } while (1);
}

int
ACEXML_Parser::parse_markup_decl (ACEXML_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((ACEXML_SAXException))
{
  ACEXML_Char nextch = this->peek ();
  switch (nextch)
    {
      case 'E':         // An ELEMENT or ENTITY decl
        this->get ();
        nextch = this->peek ();
        switch (nextch)
          {
            case 'L':
              this->parse_element_decl (ACEXML_ENV_SINGLE_ARG_PARAMETER);
              ACEXML_CHECK_RETURN (-1);
              break;
            case 'N':
              this->parse_entity_decl (ACEXML_ENV_SINGLE_ARG_PARAMETER);
              ACEXML_CHECK_RETURN (-1);
              break;
            default:
              this->fatal_error(ACE_TEXT ("Expecting keyword ELEMENT/ENTITY")
                                ACEXML_ENV_ARG_PARAMETER);
              ACEXML_CHECK_RETURN (-1);
          }
        break;

      case 'A':         // An ATTLIST decl
        this->parse_attlist_decl (ACEXML_ENV_SINGLE_ARG_PARAMETER);
        ACEXML_CHECK_RETURN (-1);
        break;

      case 'N':         // A NOTATION decl
        this->parse_notation_decl (ACEXML_ENV_SINGLE_ARG_PARAMETER);
        ACEXML_CHECK_RETURN (-1);
        break;

      case '-':         // a comment.
        if (this->parse_comment () < 0)
          {
            this->fatal_error(ACE_TEXT ("Invalid comment")
                              ACEXML_ENV_ARG_PARAMETER);
            ACEXML_CHECK_RETURN (-1);
          }
        break;
      case 0: //  [VC: Proper Declaration/PE Nesting]
        this->fatal_error (ACE_TEXT ("Unexpected end-of-file")
                           ACEXML_ENV_ARG_PARAMETER);
        ACEXML_CHECK_RETURN (-1);
      default:
        this->fatal_error (ACE_TEXT ("Invalid markupDecl")
                           ACEXML_ENV_ARG_PARAMETER);
        ACEXML_CHECK_RETURN (-1);
    }
  return 0;
}

int

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -