예제 #1
0
bool XmlEncode(std::wstring& data, int nMaxCount)
{
    if ((int)data.size() > nMaxCount)
    {
        data = data.substr(0, nMaxCount);
    }

    size_t nCount = 0;
    std::wstring buffer;
    buffer.reserve(data.size());
    for (size_t pos = 0; pos != data.size(); ++pos)
    {
        if (data[pos] == L'\n' || data[pos] == L'\r')
        {
            nCount = pos;
            break;
        }
        else if (data[pos] == L'&')
        {
            buffer.append(L"&");
        }
        else if (data[pos] == L'\"')
        {
            buffer.append(L""");
        }
        else if (data[pos] == L'\'')
        {
            buffer.append(L"'");
        }
        else if (data[pos] == L'<')
        {
            buffer.append(L"&lt;");
        }
        else if (data[pos] == L'>')
        {
            buffer.append(L"&gt;");
        }
        else if (data[pos] == L'\\')
        {
            buffer.append(L"\\\\");
        }
        else
        {
            buffer.append(&data[pos], 1);
        }
    }

    data.swap(buffer);

    return nCount > 0;
}
예제 #2
0
void CPOFile::AdjustEOLs(std::wstring& str)
{
	std::wstring result;
	std::wstring::size_type pos = 0;
	for ( ; ; ) // while (true)
	{
		std::wstring::size_type next = str.find(L"\\r\\n", pos);
		result.append(str, pos, next-pos);
		if( next != std::string::npos )
		{
			result.append(L"\\n");
			pos = next + 4; // 4 = sizeof("\\r\\n")
		}
		else
		{
			break;  // exit loop
		}
	}
	str.swap(result);
	result.clear();
	pos = 0;

	for ( ; ; ) // while (true)
	{
		std::wstring::size_type next = str.find(L"\\n", pos);
		result.append(str, pos, next-pos);
		if( next != std::string::npos )
		{
			result.append(L"\\r\\n");
			pos = next + 2; // 2 = sizeof("\\n")
		}
		else
		{
			break;  // exit loop
		}
	}
	str.swap(result);
}
예제 #3
0
void SearchReplace(std::wstring& str, const std::wstring& toreplace, const std::wstring& replacewith)
{
    std::wstring result;
    std::wstring::size_type pos = 0;
    for (;;)    // while (true)
    {
        std::wstring::size_type next = str.find(toreplace, pos);
        result.append(str, pos, next-pos);
        if (next != std::string::npos)
        {
            result.append(replacewith);
            pos = next + toreplace.size();
        }
        else
        {
            break;  // exit loop
        }
    }
    str.swap(result);
}