split majority of helpers and rewrite a few heinous functions
This commit is contained in:
79
src/conv.cpp
79
src/conv.cpp
@@ -293,82 +293,3 @@ void EscapeUnallowedChars(std::string &s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string unescapeHtmlUtf8(const std::string &data)
|
||||
{
|
||||
std::string result;
|
||||
for (size_t i = 0, j; i < data.length(); ++i)
|
||||
{
|
||||
if (data[i] == '&' && data[i+1] == '#' && (j = data.find(';', i)) != std::string::npos)
|
||||
{
|
||||
int n = atoi(&data.c_str()[i+2]);
|
||||
if (n >= 0x800)
|
||||
{
|
||||
result += (0xe0 | ((n >> 12) & 0x0f));
|
||||
result += (0x80 | ((n >> 6) & 0x3f));
|
||||
result += (0x80 | (n & 0x3f));
|
||||
}
|
||||
else if (n >= 0x80)
|
||||
{
|
||||
result += (0xc0 | ((n >> 6) & 0x1f));
|
||||
result += (0x80 | (n & 0x3f));
|
||||
}
|
||||
else
|
||||
result += n;
|
||||
i = j;
|
||||
}
|
||||
else
|
||||
result += data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void StripHtmlTags(std::string &s)
|
||||
{
|
||||
bool erase = 0;
|
||||
for (size_t i = s.find("<"); i != std::string::npos; i = s.find("<"))
|
||||
{
|
||||
size_t j = s.find(">", i)+1;
|
||||
s.replace(i, j-i, "");
|
||||
}
|
||||
Replace(s, "'", "'");
|
||||
Replace(s, "&", "&");
|
||||
Replace(s, """, "\"");
|
||||
Replace(s, " ", " ");
|
||||
for (size_t i = 0; i < s.length(); ++i)
|
||||
{
|
||||
if (erase)
|
||||
{
|
||||
s.erase(s.begin()+i);
|
||||
erase = 0;
|
||||
}
|
||||
if (s[i] == 13) // ascii code for windows line ending, get rid of this shit
|
||||
{
|
||||
s[i] = '\n';
|
||||
erase = 1;
|
||||
}
|
||||
else if (s[i] == '\t')
|
||||
s[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void Trim(std::string &s)
|
||||
{
|
||||
if (s.empty())
|
||||
return;
|
||||
|
||||
size_t b = 0;
|
||||
size_t e = s.length()-1;
|
||||
|
||||
while (s[e] == ' ' || s[e] == '\n')
|
||||
--e;
|
||||
++e;
|
||||
if (e != s.length())
|
||||
s.resize(e);
|
||||
|
||||
while (s[b] == ' ' || s[b] == '\n')
|
||||
++b;
|
||||
if (b != 0)
|
||||
s = s.substr(b);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user