Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXhmikosR <xhmikosr@users.sourceforge.net>2010-04-09 18:12:59 +0400
committerXhmikosR <xhmikosr@users.sourceforge.net>2010-04-09 18:12:59 +0400
commitefbc9d9043ff8ff92716ddd00a5f61412d535593 (patch)
tree8f3e621f756cf1f5b4d64d97964c7e7abd8aaf08 /src/DSUtil/text.cpp
parentdf6b139a6d9027156f614b68687e039e3a5854db (diff)
revert r1783
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1785 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/DSUtil/text.cpp')
-rw-r--r--src/DSUtil/text.cpp239
1 files changed, 115 insertions, 124 deletions
diff --git a/src/DSUtil/text.cpp b/src/DSUtil/text.cpp
index eb4e358e5..99d61f702 100644
--- a/src/DSUtil/text.cpp
+++ b/src/DSUtil/text.cpp
@@ -19,7 +19,7 @@ CString Explode(CString str, CAtlList<CString>& sl, TCHAR sep, int limit)
sl.AddTail(tmp);
if(limit > 0 && sl.GetCount() == limit-1)
{
- if(j+1 < str.GetLength())
+ if(j+1 < str.GetLength())
{
CString tmp = str.Mid(j+1);
tmp.TrimLeft(sep); tmp.TrimRight(sep);
@@ -44,7 +44,7 @@ CString ExplodeMin(CString str, CAtlList<CString>& sl, TCHAR sep, int limit)
{
Explode(str, sl, sep, limit);
POSITION pos = sl.GetHeadPosition();
- while(pos)
+ while(pos)
{
POSITION tmp = pos;
if(sl.GetNext(pos).IsEmpty())
@@ -70,160 +70,151 @@ CString Implode(CAtlList<CString>& sl, TCHAR sep)
DWORD CharSetToCodePage(DWORD dwCharSet)
{
- if(dwCharSet == CP_UTF8) return CP_UTF8;
- if(dwCharSet == CP_UTF7) return CP_UTF7;
- CHARSETINFO cs = {0};
- ::TranslateCharsetInfo((DWORD *)dwCharSet, &cs, TCI_SRCCHARSET);
- return cs.ciACP;
+ if(dwCharSet == CP_UTF8) return CP_UTF8;
+ if(dwCharSet == CP_UTF7) return CP_UTF7;
+ CHARSETINFO cs={0};
+ ::TranslateCharsetInfo((DWORD *)dwCharSet, &cs, TCI_SRCCHARSET);
+ return cs.ciACP;
}
CStringA ConvertMBCS(CStringA str, DWORD SrcCharSet, DWORD DstCharSet)
{
- WCHAR* utf16 = DNew WCHAR[str.GetLength()+1];
- memset(utf16, 0, (str.GetLength() + 1)*sizeof(WCHAR));
+ WCHAR* utf16 = DNew WCHAR[str.GetLength()+1];
+ memset(utf16, 0, (str.GetLength()+1)*sizeof(WCHAR));
- CHAR* mbcs = DNew CHAR[str.GetLength()*6+1];
- memset(mbcs, 0, str.GetLength() * 6 + 1);
+ CHAR* mbcs = DNew CHAR[str.GetLength()*6+1];
+ memset(mbcs, 0, str.GetLength()*6+1);
- int len = MultiByteToWideChar(
- CharSetToCodePage(SrcCharSet), 0,
- str.GetBuffer(str.GetLength()), str.GetLength(),
- utf16, (str.GetLength() + 1) * sizeof(WCHAR));
+ int len = MultiByteToWideChar(
+ CharSetToCodePage(SrcCharSet), 0,
+ str.GetBuffer(str.GetLength()), str.GetLength(),
+ utf16, (str.GetLength()+1)*sizeof(WCHAR));
- len = WideCharToMultiByte(
- CharSetToCodePage(DstCharSet), 0,
- utf16, len,
- mbcs, str.GetLength() * 6,
- NULL, NULL);
+ len = WideCharToMultiByte(
+ CharSetToCodePage(DstCharSet), 0,
+ utf16, len,
+ mbcs, str.GetLength()*6,
+ NULL, NULL);
- str = mbcs;
+ str = mbcs;
- delete [] utf16;
- delete [] mbcs;
+ delete [] utf16;
+ delete [] mbcs;
- return str;
+ return str;
}
CStringA UrlEncode(CStringA str, bool fRaw)
{
- CStringA urlstr;
-
- for(size_t i = 0; i < str.GetLength(); i++)
- {
- CHAR c = str[i];
- if(fRaw && c == '+') urlstr += "%2B";
- else if(c > 0x20 && c < 0x7f && c != '&') urlstr += c;
- else if(c == 0x20) urlstr += fRaw ? ' ' : '+';
- else
- {
- CStringA tmp;
- tmp.Format("%%%02x", (BYTE)c);
- urlstr += tmp;
- }
- }
-
- return urlstr;
+ CStringA urlstr;
+
+ for(size_t i = 0; i < str.GetLength(); i++)
+ {
+ CHAR c = str[i];
+ if(fRaw && c == '+') urlstr += "%2B";
+ else if(c > 0x20 && c < 0x7f && c != '&') urlstr += c;
+ else if(c == 0x20) urlstr += fRaw ? ' ' : '+';
+ else {CStringA tmp; tmp.Format("%%%02x", (BYTE)c); urlstr += tmp;}
+ }
+
+ return urlstr;
}
CStringA UrlDecode(CStringA str, bool fRaw)
{
- str.Replace("&amp;", "&");
-
- CHAR* s = str.GetBuffer(str.GetLength());
- CHAR* e = s + str.GetLength();
- CHAR* s1 = s;
- CHAR* s2 = s;
- while(s1 < e)
- {
- CHAR s11 = (s1 < e - 1) ? (__isascii(s1[1]) && isupper(s1[1]) ? tolower(s1[1]) : s1[1]) : 0;
- CHAR s12 = (s1 < e - 2) ? (__isascii(s1[2]) && isupper(s1[2]) ? tolower(s1[2]) : s1[2]) : 0;
-
- if(*s1 == '%' && s1 < e - 2
- && (s1[1] >= '0' && s1[1] <= '9' || s11 >= 'a' && s11 <= 'f')
- && (s1[2] >= '0' && s1[2] <= '9' || s12 >= 'a' && s12 <= 'f'))
- {
- s1[1] = s11;
- s1[2] = s12;
- *s2 = 0;
- if(s1[1] >= '0' && s1[1] <= '9') *s2 |= s1[1] - '0';
- else if(s1[1] >= 'a' && s1[1] <= 'f') *s2 |= s1[1] - 'a' + 10;
- *s2 <<= 4;
- if(s1[2] >= '0' && s1[2] <= '9') *s2 |= s1[2] - '0';
- else if(s1[2] >= 'a' && s1[2] <= 'f') *s2 |= s1[2] - 'a' + 10;
- s1 += 2;
- }
- else
- {
- *s2 = *s1 == '+' && !fRaw ? ' ' : *s1;
- }
-
- s1++;
- s2++;
- }
-
- str.ReleaseBuffer(s2 - s);
-
- return str;
+ str.Replace("&amp;", "&");
+
+ CHAR* s = str.GetBuffer(str.GetLength());
+ CHAR* e = s + str.GetLength();
+ CHAR* s1 = s;
+ CHAR* s2 = s;
+ while(s1 < e)
+ {
+ CHAR s11 = (s1 < e-1) ? (__isascii(s1[1]) && isupper(s1[1]) ? tolower(s1[1]) : s1[1]) : 0;
+ CHAR s12 = (s1 < e-2) ? (__isascii(s1[2]) && isupper(s1[2]) ? tolower(s1[2]) : s1[2]) : 0;
+
+ if(*s1 == '%' && s1 < e-2
+ && (s1[1] >= '0' && s1[1] <= '9' || s11 >= 'a' && s11 <= 'f')
+ && (s1[2] >= '0' && s1[2] <= '9' || s12 >= 'a' && s12 <= 'f'))
+ {
+ s1[1] = s11;
+ s1[2] = s12;
+ *s2 = 0;
+ if(s1[1] >= '0' && s1[1] <= '9') *s2 |= s1[1]-'0';
+ else if(s1[1] >= 'a' && s1[1] <= 'f') *s2 |= s1[1]-'a'+10;
+ *s2 <<= 4;
+ if(s1[2] >= '0' && s1[2] <= '9') *s2 |= s1[2]-'0';
+ else if(s1[2] >= 'a' && s1[2] <= 'f') *s2 |= s1[2]-'a'+10;
+ s1 += 2;
+ }
+ else
+ {
+ *s2 = *s1 == '+' && !fRaw ? ' ' : *s1;
+ }
+
+ s1++;
+ s2++;
+ }
+
+ str.ReleaseBuffer(s2 - s);
+
+ return str;
}
CString ExtractTag(CString tag, CMapStringToString& attribs, bool& fClosing)
{
- tag.Trim();
- attribs.RemoveAll();
-
- fClosing = !tag.IsEmpty() ? tag[0] == '/' : false;
- tag.TrimLeft('/');
-
- int i = tag.Find(' ');
- if(i < 0) i = tag.GetLength();
- CString type = tag.Left(i).MakeLower();
- tag = tag.Mid(i).Trim();
-
- while((i = tag.Find('=')) > 0)
- {
- CString attrib = tag.Left(i).Trim().MakeLower();
- tag = tag.Mid(i + 1);
- for(i = 0; i < tag.GetLength() && _istspace(tag[i]); i++);
- tag = i < tag.GetLength() ? tag.Mid(i) : _T("");
- if(!tag.IsEmpty() && tag[0] == '\"')
- {
- tag = tag.Mid(1);
- i = tag.Find('\"');
- }
- else i = tag.Find(' ');
- if(i < 0) i = tag.GetLength();
- CString param = tag.Left(i).Trim();
- if(!param.IsEmpty())
- attribs[attrib] = param;
- tag = i + 1 < tag.GetLength() ? tag.Mid(i + 1) : _T("");
- }
-
- return(type);
+ tag.Trim();
+ attribs.RemoveAll();
+
+ fClosing = !tag.IsEmpty() ? tag[0] == '/' : false;
+ tag.TrimLeft('/');
+
+ int i = tag.Find(' ');
+ if(i < 0) i = tag.GetLength();
+ CString type = tag.Left(i).MakeLower();
+ tag = tag.Mid(i).Trim();
+
+ while((i = tag.Find('=')) > 0)
+ {
+ CString attrib = tag.Left(i).Trim().MakeLower();
+ tag = tag.Mid(i+1);
+ for(i = 0; i < tag.GetLength() && _istspace(tag[i]); i++);
+ tag = i < tag.GetLength() ? tag.Mid(i) : _T("");
+ if(!tag.IsEmpty() && tag[0] == '\"') {tag = tag.Mid(1); i = tag.Find('\"');}
+ else i = tag.Find(' ');
+ if(i < 0) i = tag.GetLength();
+ CString param = tag.Left(i).Trim();
+ if(!param.IsEmpty())
+ attribs[attrib] = param;
+ tag = i+1 < tag.GetLength() ? tag.Mid(i+1) : _T("");
+ }
+
+ return(type);
}
CAtlList<CString>& MakeLower(CAtlList<CString>& sl)
{
- POSITION pos = sl.GetHeadPosition();
- while(pos) sl.GetNext(pos).MakeLower();
- return sl;
+ POSITION pos = sl.GetHeadPosition();
+ while(pos) sl.GetNext(pos).MakeLower();
+ return sl;
}
CAtlList<CString>& MakeUpper(CAtlList<CString>& sl)
{
- POSITION pos = sl.GetHeadPosition();
- while(pos) sl.GetNext(pos).MakeUpper();
- return sl;
+ POSITION pos = sl.GetHeadPosition();
+ while(pos) sl.GetNext(pos).MakeUpper();
+ return sl;
}
CAtlList<CString>& RemoveStrings(CAtlList<CString>& sl, int minlen, int maxlen)
{
- POSITION pos = sl.GetHeadPosition();
- while(pos)
- {
- POSITION tmp = pos;
- CString& str = sl.GetNext(pos);
- int len = str.GetLength();
- if(len < minlen || len > maxlen) sl.RemoveAt(tmp);
- }
- return sl;
+ POSITION pos = sl.GetHeadPosition();
+ while(pos)
+ {
+ POSITION tmp = pos;
+ CString& str = sl.GetNext(pos);
+ int len = str.GetLength();
+ if(len < minlen || len > maxlen) sl.RemoveAt(tmp);
+ }
+ return sl;
}