Update UNRAR.H
[xy_vsfilter.git] / src / dsutil / text.h
blob14cd1149aa126233d9eb15930e88d8be6ef1c7d9
1 #pragma once
3 #include <atlcoll.h>
5 // extern CString ExplodeMin(CString str, CAtlList<CString>& sl, TCHAR sep, int limit = 0);
6 // extern CString Explode(CString str, CAtlList<CString>& sl, TCHAR sep, int limit = 0);
7 // extern CString Implode(CAtlList<CString>& sl, TCHAR sep);
9 template<class T, typename SEP>
10 T Explode(T str, CAtlList<T>& sl, SEP sep, int limit = 0)
12 sl.RemoveAll();
14 for(int i = 0, j = 0; ; i = j+1)
16 j = str.Find(sep, i);
18 if(j < 0 || sl.GetCount() == limit-1)
20 sl.AddTail(str.Mid(i).Trim());
21 break;
23 else
25 sl.AddTail(str.Mid(i, j-i).Trim());
29 return sl.GetHead();
32 template<class T, typename SEP>
33 T ExplodeMin(T str, CAtlList<T>& sl, SEP sep, int limit = 0)
35 Explode(str, sl, sep, limit);
36 POSITION pos = sl.GetHeadPosition();
37 while(pos)
39 POSITION tmp = pos;
40 if(sl.GetNext(pos).IsEmpty())
41 sl.RemoveAt(tmp);
43 if(sl.IsEmpty()) sl.AddTail(T()); // eh
45 return sl.GetHead();
48 template<class T, typename SEP>
49 T Implode(CAtlList<T>& sl, SEP sep)
51 T ret;
52 POSITION pos = sl.GetHeadPosition();
53 while(pos)
55 ret += sl.GetNext(pos);
56 if(pos) ret += sep;
58 return(ret);
61 extern CString ExtractTag(CString tag, CMapStringToString& attribs, bool& fClosing);
62 extern CStringA ConvertMBCS(CStringA str, DWORD SrcCharSet, DWORD DstCharSet);
63 extern CStringA UrlEncode(CStringA str, bool fRaw = false);
64 extern CStringA UrlDecode(CStringA str, bool fRaw = false);
65 extern DWORD CharSetToCodePage(DWORD dwCharSet);
66 extern CAtlList<CString>& MakeLower(CAtlList<CString>& sl);
67 extern CAtlList<CString>& MakeUpper(CAtlList<CString>& sl);
68 extern CAtlList<CString>& RemoveStrings(CAtlList<CString>& sl, int minlen, int maxlen);