예제 #1
0
Utf8String Utf8String::from_utf8_slash_to_dot(Utf8String u) {
	return string_from_utf8<utf8::SlashToDot>(u.begin(), u.size());
}
예제 #2
0
파일: XMLWriter.cpp 프로젝트: Microsoft/pal
/*
**==============================================================================
**
**  Starting with this element, build the output string that represents the entire
**  tree from this point down, building on the passed in string.  In other words,
**  the tree is traversed, and each element has its own save() method called.
**
**==============================================================================
*/
void CXElement::Save(Utf8String& sOut, bool bAddIndentation, Utf8String& sIndentation)
{
    // Output our start tag.
    if (bAddIndentation)
    {
        sOut += sIndentation;
    }

    sOut += open_bracket;
    sOut += m_sName;

    // Output all the attributes and close the start tag.
    for (size_t j = m_listAttribute.size();  j > 0;  j--)
    {
        sOut += u8_space + m_listAttribute[j - 1]->m_sName + equals_with_quote;
        PutText(sOut, m_listAttribute[j - 1]->m_sValue);
        sOut += ending_quote;
    }

    if (m_sName[0] != single_question) // XML_INSTRUCTION
    {
        // If this was an empty tag (just the name and attributes), and there were no children
        // then just close the tag.
        if (m_sText.Empty() && m_listChild.empty())
        {
            sOut += close_bracket_with_term;

            if (m_LineSeparatorsOn)
            {
                sOut += crlf;
            }

            return;
        }
        else
        {
            sOut += close_bracket;
        }
    }
    else
    {
        sOut += close_bracket_with_question;
    }

    if (!m_listChild.empty() && m_LineSeparatorsOn)
    {
        sOut += crlf;
    }

    // Output the text.
    // *** DO NOT put a line separator at the end of this data, or add indentation to the front.
    //     If you do so, and the data happens to be string data, you will be adding an
    //     extra \n\r to the output that will not be parsed out on input.  Changing the
    //     data is generally considered bad practice.
    if (!m_sText.Empty())
    {
        PutText (sOut, m_sText);
    }

    // Output all the child elements.
    std::vector<pCXElement>::iterator i;
    for (i = m_listChild.begin();  i != m_listChild.end();  i++)
    {
        pCXElement singleElement = *i;

        // Call the child element's save() method.
        sIndentation += four_spaces;
        singleElement->Save(sOut, bAddIndentation, sIndentation);
        sIndentation = sIndentation.substr(0, sIndentation.size() - 4);
    }

    if (m_sName[0] != single_question) // XML_INSTRUCTION
    {
        if (m_sText.Empty() && bAddIndentation)
        {
            sOut += sIndentation;
        }

        // Output the end tag.
        sOut += open_with_slash + m_sName + close_bracket;
    }

    // And close us up
    if (m_LineSeparatorsOn)
    {
        sOut += crlf;
    }
}