написал свои функции для работы со строками а именно substr,strpos и delete. сильно прошу не пинать, т.к. писал для своих нужд и кое где могут быть нагруженные места(неоптимизированные), могут быть ошибки и т.д. Code: /* String Works Library (C) CodeMaster aka RealCoder 2011 */ #include <windows.h> //макросы #define _DECL_SZ_(name,size) char *name=(char *)malloc(size); ZeroMemory(name,size); #define _DECL_HEAP_(name,size) void *name=malloc(size); ZeroMemory(name,size); /*поиск подстроки в строке*/ int strpos(char *symb,char *str) { unsigned long dwBegin=0;// начальный символ на проверку unsigned long dwEnd=0;//конечный символ на проверку _DECL_SZ_(szSub,lstrlen(symb));//предпологаемая строка do{ for(int i=dwBegin;i<lstrlen(str);i++)// ищем первый символ { if( str[i] == symb[0] )//если нашли { dwBegin=i;//присваиваем значение break;//выходим из цикла } if(i==(lstrlen(str)-1)) return -1;//если прошли до конца, но так и не нашли - возвращаем -1 } dwEnd=lstrlen(symb)+dwBegin;//вычисляем конечный символ if (dwEnd>lstrlen(str)) return -1;//если предполагаемый конечный символ за пределами строки - вернем -1 memcpy(szSub,(void *)((unsigned long)str+dwBegin),strlen(symb));//выделяем предпологаемую строку szSub[strlen(symb)]='\0';//прерываем нулем if(memcmp(szSub,symb,strlen(symb))!=0) dwBegin++;//увеличиваем счетчик } while(memcmp(szSub,symb,strlen(symb))!=0);//пока предпологаемая строка не совпадет с искомой return dwBegin;//возвращаем позицию первого символа } /*выделение подстроки*/ bool substr(char *szSource,int iStart,int iCount, LPSTR &szResult) { if( ((iStart+iCount)>lstrlen(szSource)))//чтоб не вылезти за пределы строки проверим индекс и длину { return false;//если их сумма больше длины строки - вернем FALSE } memcpy(szResult,(void *)((unsigned long)szSource+iStart),iCount);//собственно само копирование szResult[iCount]='\0';//прерываем нулем return true;//вернем true; } /*удаление куска строки*/ bool strdelete(char *szString,int iStart,int iCount,LPSTR &szResult) { if(iCount>lstrlen(szString)) return false;//проверка длины _DECL_HEAP_(lpBeg,iStart);//до удаляемого фрагмента memcpy(lpBeg,szString,iStart);//запоминаем _DECL_HEAP_(lpEnd,strlen(szString)-iStart-iCount);//после удаляемого фрагмента memcpy(lpEnd,(void *)((unsigned long)szString+iStart+iCount),lstrlen(szString)-iStart-iCount);//запоминаем ZeroMemory(szResult,strlen(szString));//очищаем старую строку memcpy(szResult,lpBeg,iStart);//копируем первый фрагмент memcpy((void *)((unsigned long)szResult+iStart),lpEnd,lstrlen(szString)-iStart-iCount);//копируем второй фрагмент szResult[lstrlen(szString)-iCount]='\0';//прерываем строку if(lstrlen(szResult)==lstrlen(szString)-iCount) return true; else return false;//проверяем длину }
Твой код относится скорее к C, причем реализация платформозависимая. http://www.cplusplus.com/reference/string/string/substr/ http://www.cplusplus.com/reference/string/string/find/ http://www.cplusplus.com/reference/string/string/clear/
ну получается я для winapi на си сделал просто когда -то писал ddos-бот на windows api понадобилось получать команду с адмнинки типа [cmd]ddos dom2.ru 80[/cmd] И выпарсивать из тэга cmd команду. вот и написал, т.к. если юзать рантайм либы придется таскать с собой некоторые dll-ки либо статическу линковку юзать....
В контексте тягаемых тобой функций, вызов стандартных для C аналогов не сделал бы погоды в плане размера.
Для твоего strpos есть в libc strstr. substr - strncpy. а удаление части строки - просто в то место, с которого хочешь удалить ставишь \0.
В добавление ко всему вышесказанному, в крайнем случае (такого не может быть), можно было бы просто дернуть ИСХОДНИКИ функций из опенсурсного glibc... А уж если ты решил использовать windows API то специально для тебя есть множество функций работы со строками из Shlwapi.dll... + посмотри экспорт ntdll/ntoskrnl (strtol,memset...)
Code: lstrcat C:\WINDOWS\system32\dllcache\kernel32.dll lstrcatA C:\WINDOWS\system32\dllcache\kernel32.dll lstrcatW C:\WINDOWS\system32\dllcache\kernel32.dll lstrcmp C:\WINDOWS\system32\dllcache\kernel32.dll lstrcmpA C:\WINDOWS\system32\dllcache\kernel32.dll lstrcmpW C:\WINDOWS\system32\dllcache\kernel32.dll lstrcmpi C:\WINDOWS\system32\dllcache\kernel32.dll lstrcmpiA C:\WINDOWS\system32\dllcache\kernel32.dll lstrcmpiW C:\WINDOWS\system32\dllcache\kernel32.dll lstrcpy C:\WINDOWS\system32\dllcache\kernel32.dll lstrcpyA C:\WINDOWS\system32\dllcache\kernel32.dll lstrcpyW C:\WINDOWS\system32\dllcache\kernel32.dll lstrcpyn C:\WINDOWS\system32\dllcache\kernel32.dll lstrcpynA C:\WINDOWS\system32\dllcache\kernel32.dll lstrcpynW C:\WINDOWS\system32\dllcache\kernel32.dll lstrlen C:\WINDOWS\system32\dllcache\kernel32.dll lstrlenA C:\WINDOWS\system32\dllcache\kernel32.dll lstrlenW C:\WINDOWS\system32\dllcache\kernel32.dll ------------------------------------------------------------------------ _strcmpi C:\WINDOWS\system32\dllcache\ntdll.dll _stricmp C:\WINDOWS\system32\dllcache\ntdll.dll _strlwr C:\WINDOWS\system32\dllcache\ntdll.dll _strnicmp C:\WINDOWS\system32\dllcache\ntdll.dll _strupr C:\WINDOWS\system32\dllcache\ntdll.dll strcat C:\WINDOWS\system32\dllcache\ntdll.dll strchr C:\WINDOWS\system32\dllcache\ntdll.dll strcmp C:\WINDOWS\system32\dllcache\ntdll.dll strcpy C:\WINDOWS\system32\dllcache\ntdll.dll strcspn C:\WINDOWS\system32\dllcache\ntdll.dll strlen C:\WINDOWS\system32\dllcache\ntdll.dll strncat C:\WINDOWS\system32\dllcache\ntdll.dll strncmp C:\WINDOWS\system32\dllcache\ntdll.dll strncpy C:\WINDOWS\system32\dllcache\ntdll.dll strpbrk C:\WINDOWS\system32\dllcache\ntdll.dll strrchr C:\WINDOWS\system32\dllcache\ntdll.dll strspn C:\WINDOWS\system32\dllcache\ntdll.dll strstr C:\WINDOWS\system32\dllcache\ntdll.dll strtol C:\WINDOWS\system32\dllcache\ntdll.dll strtoul C:\WINDOWS\system32\dllcache\ntdll.dll wcsstr C:\WINDOWS\system32\dllcache\ntdll.dll ------------------------------------------------------------------------ StrChrA C:\WINDOWS\system32\dllcache\shell32.dll StrChrIA C:\WINDOWS\system32\dllcache\shell32.dll StrChrIW C:\WINDOWS\system32\dllcache\shell32.dll StrChrW C:\WINDOWS\system32\dllcache\shell32.dll StrCmpNA C:\WINDOWS\system32\dllcache\shell32.dll StrCmpNIA C:\WINDOWS\system32\dllcache\shell32.dll StrCmpNIW C:\WINDOWS\system32\dllcache\shell32.dll StrCmpNW C:\WINDOWS\system32\dllcache\shell32.dll StrCpyNA C:\WINDOWS\system32\dllcache\shell32.dll StrCpyNW C:\WINDOWS\system32\dllcache\shell32.dll StrNCmpA C:\WINDOWS\system32\dllcache\shell32.dll StrNCmpIA C:\WINDOWS\system32\dllcache\shell32.dll StrNCmpIW C:\WINDOWS\system32\dllcache\shell32.dll StrNCmpW C:\WINDOWS\system32\dllcache\shell32.dll StrNCpyA C:\WINDOWS\system32\dllcache\shell32.dll StrNCpyW C:\WINDOWS\system32\dllcache\shell32.dll StrRChrA C:\WINDOWS\system32\dllcache\shell32.dll StrRChrIA C:\WINDOWS\system32\dllcache\shell32.dll StrRChrIW C:\WINDOWS\system32\dllcache\shell32.dll StrRChrW C:\WINDOWS\system32\dllcache\shell32.dll StrRStrA C:\WINDOWS\system32\dllcache\shell32.dll StrRStrIA C:\WINDOWS\system32\dllcache\shell32.dll StrRStrIW C:\WINDOWS\system32\dllcache\shell32.dll StrRStrW C:\WINDOWS\system32\dllcache\shell32.dll StrStrA C:\WINDOWS\system32\dllcache\shell32.dll StrStrIA C:\WINDOWS\system32\dllcache\shell32.dll StrStrIW C:\WINDOWS\system32\dllcache\shell32.dll StrStrW C:\WINDOWS\system32\dllcache\shell32.dll ---------------------------------------------------------------------- StrCmpCA C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpCW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpICA C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpICW C:\WINDOWS\system32\dllcache\shlwapi.dll SHStrDupA C:\WINDOWS\system32\dllcache\shlwapi.dll SHStrDupW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCSpnA C:\WINDOWS\system32\dllcache\shlwapi.dll StrCSpnIA C:\WINDOWS\system32\dllcache\shlwapi.dll StrCSpnIW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCSpnW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCatBuffA C:\WINDOWS\system32\dllcache\shlwapi.dll StrCatBuffW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCatChainW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCatW C:\WINDOWS\system32\dllcache\shlwapi.dll StrChrA C:\WINDOWS\system32\dllcache\shlwapi.dll StrChrIA C:\WINDOWS\system32\dllcache\shlwapi.dll StrChrIW C:\WINDOWS\system32\dllcache\shlwapi.dll StrChrNIW C:\WINDOWS\system32\dllcache\shlwapi.dll StrChrNW C:\WINDOWS\system32\dllcache\shlwapi.dll StrChrW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpIW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpLogicalW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpNA C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpNIA C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpNIW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpNW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCmpW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCpyNW C:\WINDOWS\system32\dllcache\shlwapi.dll StrCpyW C:\WINDOWS\system32\dllcache\shlwapi.dll StrDupA C:\WINDOWS\system32\dllcache\shlwapi.dll StrDupW C:\WINDOWS\system32\dllcache\shlwapi.dll StrSpnA C:\WINDOWS\system32\dllcache\shlwapi.dll StrSpnW C:\WINDOWS\system32\dllcache\shlwapi.dll StrStrA C:\WINDOWS\system32\dllcache\shlwapi.dll StrStrIA C:\WINDOWS\system32\dllcache\shlwapi.dll StrStrIW C:\WINDOWS\system32\dllcache\shlwapi.dll StrStrNIW C:\WINDOWS\system32\dllcache\shlwapi.dll StrStrNW C:\WINDOWS\system32\dllcache\shlwapi.dll StrStrW C:\WINDOWS\system32\dllcache\shlwapi.dll StrToInt64ExA C:\WINDOWS\system32\dllcache\shlwapi.dll StrToInt64ExW C:\WINDOWS\system32\dllcache\shlwapi.dll StrToIntA C:\WINDOWS\system32\dllcache\shlwapi.dll StrToIntExA C:\WINDOWS\system32\dllcache\shlwapi.dll StrToIntExW C:\WINDOWS\system32\dllcache\shlwapi.dll StrToIntW C:\WINDOWS\system32\dllcache\shlwapi.dll StrTrimA C:\WINDOWS\system32\dllcache\shlwapi.dll StrTrimW C:\WINDOWS\system32\dllcache\shlwapi.dll ----------------------------------------------------------------------