text.h

00001 #pragma once
00002 
00003 #include <afxtempl.h>
00004 
00005 // extern CString ExplodeMin(CString str, CList<CString>& sl, TCHAR sep, int limit = 0);
00006 // extern CString Explode(CString str, CList<CString>& sl, TCHAR sep, int limit = 0);
00007 // extern CString Implode(CList<CString>& sl, TCHAR sep);
00008 
00009 template<class T, typename SEP>
00010 T Explode(T str, CList<T>& sl, SEP sep, int limit = 0)
00011 {
00012         sl.RemoveAll();
00013 
00014         for(int i = 0, j = 0; ; i = j+1)
00015         {
00016                 j = str.Find(sep, i);
00017 
00018                 if(j < 0 || sl.GetCount() == limit-1)
00019                 {
00020                         sl.AddTail(str.Mid(i).Trim());
00021                         break;
00022                 }
00023                 else
00024                 {
00025                         sl.AddTail(str.Mid(i, j-i).Trim());
00026                 }               
00027         }
00028 
00029         return sl.GetHead();
00030 }
00031 
00032 template<class T, typename SEP>
00033 T ExplodeMin(T str, CList<T>& sl, SEP sep, int limit = 0)
00034 {
00035         Explode(str, sl, sep, limit);
00036         POSITION pos = sl.GetHeadPosition();
00037         while(pos) 
00038         {
00039                 POSITION tmp = pos;
00040                 if(sl.GetNext(pos).IsEmpty())
00041                         sl.RemoveAt(tmp);
00042         }
00043         if(sl.IsEmpty()) sl.AddTail(T()); // eh
00044 
00045         return sl.GetHead();
00046 }
00047 
00048 template<class T, typename SEP>
00049 T Implode(CList<T>& sl, SEP sep)
00050 {
00051         T ret;
00052         POSITION pos = sl.GetHeadPosition();
00053         while(pos)
00054         {
00055                 ret += sl.GetNext(pos);
00056                 if(pos) ret += sep;
00057         }
00058         return(ret);
00059 }
00060 
00061 extern CString ExtractTag(CString tag, CMapStringToString& attribs, bool& fClosing);
00062 extern CStringA ConvertMBCS(CStringA str, DWORD SrcCharSet, DWORD DstCharSet);
00063 extern CStringA UrlEncode(CStringA str, bool fRaw = false);
00064 extern CStringA UrlDecode(CStringA str, bool fRaw = false);
00065 extern DWORD CharSetToCodePage(DWORD dwCharSet);
00066 extern CList<CString>& MakeLower(CList<CString>& sl);
00067 extern CList<CString>& MakeUpper(CList<CString>& sl);
00068 extern CList<CString>& RemoveStrings(CList<CString>& sl, int minlen, int maxlen);
00069 

Generated on Tue Dec 13 14:47:07 2005 for guliverkli by  doxygen 1.4.5