示例#1
0
//--------------------------------------------------------------------------
static int make_words(char *line, char **words, int maxwords)
{
  while ( qisspace(*line) )
    line++;
  int i;
  for ( i=0; *line && i < maxwords; i++ )
  {
    words[i] = line;
    while ( !qisspace(*line) && *line != '\0' )
      line++;
    if ( *line != '\0' )
      *line++ = '\0';
    while ( qisspace(*line) )
      line++;
  }
  return i;
}
示例#2
0
result_t XmlDocument::load(Buffer_base *source)
{
    std::string strBuf;
    result_t hr;

    source->toString(strBuf);

    if (!m_isXml)
    {
        _parser p(strBuf);
        const char *ptr;

        while ((ptr = qstristr(p.now(), "<meta")) != NULL && qisspace(ptr[5]))
        {
            bool bContentType = false;
            std::string content;

            p.pos = (int32_t)(ptr - p.string + 5);
            while (true)
            {
                std::string key, value;

                p.skipSpace();
                p.getWord(key, '=', '>');

                if (key.empty())
                    break;

                if (p.want('='))
                {
                    if (p.want('\"'))
                    {
                        p.getString(value, '\"', '>');
                        p.want('\"');
                    }
                    else
                        p.getWord(value, '>');
                }

                if (!qstricmp(key.c_str(), "charset"))
                {
                    m_encoding = value;
                    break;
                }
                else if (!qstricmp(key.c_str(), "content"))
                    content = value;
                else if (!qstricmp(key.c_str(), "http-equiv") &&
                         !qstricmp(value.c_str(), "Content-Type"))
                    bContentType = true;
            }

            if (bContentType && !content.empty())
            {
                _parser p1(content);

                while (true)
                {
                    std::string key, value;

                    p1.skipSpace();
                    p1.getWord(key, ';', '=');

                    if (key.empty())
                        break;

                    if (p1.want('='))
                        p1.getWord(value, ';');

                    p1.want(';');

                    if (!qstricmp(key.c_str(), "charset"))
                    {
                        m_encoding = value;
                        break;
                    }
                }
            }

            if (!m_encoding.empty())
                break;
        }

        if (!m_encoding.empty())
        {
            encoding_iconv conv(m_encoding.c_str());
            conv.decode(strBuf, strBuf);
        }
    }

    hr = load(strBuf.c_str());
    if (hr < 0)
        return hr;

    return 0;
}