#define MyNew(size) VirtualAlloc(NULL,(size),MEM_COMMIT,PAGE_READWRITE) #define MyDelete(p,size) VirtualFree((p),size,MEM_DECOMMIT) template <class TYPE> BOOLEAN __stdcall TestChar(TYPE ch1,TYPE ch2) { if(ch1 == ch2) return TRUE; if(ch1 < 91 && ch1 > 64) if( ch2 - ch1 == 32) return TRUE; if(ch2 < 91 && ch2 > 64) if( ch1 - ch2 == 32) return TRUE; return FALSE; } template <class TYPE> BOOLEAN __stdcall IsNum(TYPE ch) { if(ch <= 0x39 && ch >= 0x30) return TRUE; return FALSE; } template <class TYPE> int __stdcall MyStrLen(TYPE* pStr) { int i = 0; while(pStr[i++] != 0); return i-1; } template <class TYPE> BOOLEAN __stdcall MyStrCmpi(TYPE* pSour,TYPE* pDes,int uNum) //字符串比较,比较指定长度 忽略大小写 //相等 返回 TURE,不等返回 FALSE { if(uNum == -1) { int i = 0; do if(!TestChar(pSour[i] , pDes[i++])) return FALSE; while(pSour[i] != 0 && pDes[i] != NULL); return TRUE; } else { while((--uNum)>=0) if(!TestChar(pSour[uNum] , pDes[uNum])) return FALSE; return TRUE; } } template <class TYPE> BOOLEAN __stdcall MyStrCmp(TYPE* pSour,TYPE* pDes,int uNum) { if(uNum == -1) { int i = 0; do if(pSour[i] != pDes[i++]) return FALSE; while(pSour[i] != 0 && pDes[i] != NULL); return TRUE; } else { while((--uNum)>=0) if(pSour[uNum] != pDes[uNum]) return FALSE; return TRUE; } } template <class TYPE> ULONG MyStrFindLastChar(TYPE* szStr,TYPE ch) //找出字符串中最后一个字符出现的位置(从0开始) { ULONG i = 0; ULONG last = 0; while(szStr[i] != 0) { if(szStr[i] == ch) { last = i; } ++i; } if(last == 0 && szStr[0] != ch) return -1; return last; } template <class TYPE> ULONG MyStrFindFirstChar(TYPE* szStr,TYPE ch) //找出字符串中第一个字符出现的位置(从0开始) { ULONG i = 0; while(szStr[i] != 0) { if(szStr[i] == ch) { return i; } ++i; } return -1; } template <class TYPE> ULONG MyStrFindSub(TYPE* szStr,TYPE* szSub) //找出字符串中的子串 { int uLenStr = MyStrLen(szStr); int uLenSub = MyStrLen(szSub); for(int i = 0;i< uLenStr-uLenSub;i++) { if(MyStrCmp(szStr+i,szSub,uLenSub)) return i; } return -1; } template <class TYPE> ULONG MyStrFindSubi(TYPE* szStr,TYPE* szSub) //找出字符串中的子串 { int uLenStr = MyStrLen(szStr); int uLenSub = MyStrLen(szSub); for(int i = 0;i<=uLenStr-uLenSub;i++) { if(MyStrCmpi(szStr+i,szSub,uLenSub)) return i; } return -1; }