최종완료보고 버전
This commit is contained in:
@@ -0,0 +1,235 @@
|
||||
#ifndef STRINGEX__H_
|
||||
#define STRINGEX__H_
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#pragma once
|
||||
|
||||
#else
|
||||
|
||||
//#ifndef __CYGWIN__
|
||||
int stricmp(const char * first, const char * last);
|
||||
int strnicmp(const char * first, const char * last, unsigned int count);
|
||||
char * strlwr(char * str);
|
||||
char * strupr(char * str);
|
||||
//#endif // __CYGWIN__
|
||||
|
||||
#endif
|
||||
|
||||
char * gets_hus(char * s, int n);
|
||||
|
||||
char * stristr(char * pszStr, char * pszSearch);
|
||||
extern inline const char * stristr(const char * pszStr, const char * pszSearch)
|
||||
{
|
||||
return (char *)stristr((char *)pszStr, (char *)pszSearch);
|
||||
}
|
||||
|
||||
extern inline char * strrstr(char * pszStr, char * pszSearch)
|
||||
{
|
||||
char * r = NULL;
|
||||
|
||||
if (!pszSearch[0])
|
||||
return (char *)pszStr + strlen(pszStr);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
char * p = strstr(pszStr, pszSearch);
|
||||
if (!p)
|
||||
return r;
|
||||
r = p;
|
||||
pszStr = p + 1;
|
||||
}
|
||||
}
|
||||
|
||||
char * StrIKeyword(char * string, char * strSearch);
|
||||
extern inline const char * StrIKeyword(const char * string, const char * strSearch)
|
||||
{
|
||||
return (char *)StrIKeyword((char *)string, (char *)strSearch);
|
||||
}
|
||||
|
||||
extern inline char * StrNCpy(char * pszBuf, const char * pszStr, size_t nCount)
|
||||
{
|
||||
char * pszResult = strncpy(pszBuf, pszStr, nCount);
|
||||
pszBuf[nCount] = '\0';
|
||||
return pszResult;
|
||||
}
|
||||
|
||||
const char * StrNStr(const char * string, const char * strSearch, int nCount = -1);
|
||||
const char * StrNIStr(const char * string, const char * strSearch, int nCount = -1);
|
||||
const char * StrRChr(const char * string, const char * strStart, char chUntil);
|
||||
const char * StrStrUntilChr(const char * string, const char * strSearch, char chUntil);
|
||||
const char * StrStrUntilStr(const char * string, const char * strSearch, const char * strUntil);
|
||||
|
||||
const char * StrBetweenCpy(const char * pSrc, const char * pszFront, const char * pszRear, char * pDst);
|
||||
size_t StrRemoveBetween(char * pszDst, const char * pszSrc, const char * pszFront, const char * pszRear);
|
||||
|
||||
int StrCountChar(const char * string, char ch);
|
||||
int StrCountStr(const char * string, const char * strSearch);
|
||||
int StrCountRow(const char * string);
|
||||
|
||||
char * StrTok(const char * pszSrc, const char * pszDelimit, char * pszTokenBuff); // This function is similar to strtok(), thread safe
|
||||
|
||||
void StrTrim(char ** ppsz, size_t nLength, bool bRemoveFront, bool bRemoveRear);
|
||||
const char * StrNTrimPtr(const char * pszSrc, int nSrcCount = -1);
|
||||
void StrNTrimCpy(char * pszDst, const char * pszSrc, int nSrcCount = -1);
|
||||
char * StrReadLine(char * pszDst, const char * pszSrc, int nCount = -1);
|
||||
|
||||
const char * StrReplace(const char * pszText, const char * pszKeyword, const char * pszReplace, int nMode = 0, int nCount = -1); // nMode : 0 = case sensitive, 1 = no case, 2 = keyword
|
||||
size_t StrReplace2(char * pszDst, const char * pszText, const char * pszKeyword, const char * pszReplace, int nMode = 0, int nCount = -1); // nMode : 0 = case sensitive, 1 = no case, 2 = keyword
|
||||
|
||||
extern inline bool IsNumeric(const char * psz)
|
||||
{
|
||||
const char * p = psz;
|
||||
while (*p)
|
||||
{
|
||||
if (*p < 48 || *p > 57)
|
||||
return false;
|
||||
p++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
extern inline bool IsZeroString(const char * psz)
|
||||
{
|
||||
if (*psz == '\0')
|
||||
return false;
|
||||
|
||||
while (*psz)
|
||||
{
|
||||
if (*psz != '0')
|
||||
return false;
|
||||
|
||||
psz++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
extern inline int HexToI(char ch)
|
||||
{
|
||||
if ((ch >= '0') && (ch <= '9'))
|
||||
return ch-'0';
|
||||
else if ((ch >= 'a') && (ch <= 'f'))
|
||||
return ch-'a'+10;
|
||||
else if ((ch >= 'A') && (ch <= 'F'))
|
||||
return ch-'A'+10;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern inline bool IsHex(char ch)
|
||||
{
|
||||
return (((ch>='0') && (ch <='9')) || ((ch>='a') && (ch <='f')) || ((ch >='A') && (ch <='F')));
|
||||
}
|
||||
|
||||
extern inline int AToH(char * psz)
|
||||
{
|
||||
int i = 0;
|
||||
while (*psz && IsHex(*psz))
|
||||
{
|
||||
i = i * 0x10 + HexToI(*psz);
|
||||
psz++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
#if 0
|
||||
extern inline bool HexStrToVec(std::vector<uint8_t> * pVec, const char * pszHex)
|
||||
{
|
||||
uint8_t nValue;
|
||||
size_t nCount = strlen(pszHex);
|
||||
|
||||
for (size_t i = 0; i < nCount; i += 2)
|
||||
{
|
||||
nValue = HexToI(pszHex[i]) * 0x10;
|
||||
nValue += HexToI(pszHex[i + 1]);
|
||||
|
||||
pVec->push_back(nValue);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
extern inline void CharToHex(char * pszDst, const char ch, bool bUpperCase = false)
|
||||
{
|
||||
char chCase;
|
||||
if (bUpperCase)
|
||||
chCase = 'A';
|
||||
else
|
||||
chCase = 'a';
|
||||
|
||||
pszDst[0] = (ch >> 4) & 0x0f;
|
||||
pszDst[1] = ch & 0x0f;
|
||||
|
||||
if (pszDst[0] >= 10)
|
||||
pszDst[0] = pszDst[0] - 10 + chCase;
|
||||
else
|
||||
pszDst[0] = pszDst[0] + '0';
|
||||
|
||||
if (pszDst[1] >= 10)
|
||||
pszDst[1] = pszDst[1] - 10 + chCase;
|
||||
else
|
||||
pszDst[1] = pszDst[1] + '0';
|
||||
|
||||
pszDst[2] = '\0';
|
||||
}
|
||||
|
||||
//extern inline void ArrayToHexString(HString * pstrConverted, const unsigned char * pArray, size_t nSize, bool bUpperCase = false)
|
||||
//{
|
||||
// char szHex[4];
|
||||
// for (int i = 0; i < nSize; i++)
|
||||
// {
|
||||
// CharToHex(szHex, pArray[i]);
|
||||
// *pstrConverted += szHex;
|
||||
// }
|
||||
//}
|
||||
|
||||
// aaa\r\nbbb -> aaa\0bbb
|
||||
extern inline char * StrSlice(char * pszBuffer)
|
||||
{
|
||||
for (unsigned int i = 0; pszBuffer[i]; i++)
|
||||
{
|
||||
if (pszBuffer[i] == '\r' && pszBuffer[i + 1] == '\n')
|
||||
{
|
||||
pszBuffer[i] = '\0';
|
||||
return (pszBuffer + i + 2);
|
||||
}
|
||||
else if (pszBuffer[i] == '\n' || pszBuffer[i] == '\r')
|
||||
{
|
||||
pszBuffer[i] = '\0';
|
||||
return (pszBuffer + i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern inline char * StrTokenSlice(char * pszLine, char cDelimiter)
|
||||
{
|
||||
for (unsigned int i = 0; pszLine[i]; i++)
|
||||
{
|
||||
if (pszLine[i] == cDelimiter)
|
||||
{
|
||||
pszLine[i] = '\0';
|
||||
return (pszLine + i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const void * memmem_hus(const void * pMem, size_t nMemSize, const void * pKeymem, size_t nKeymemSize);
|
||||
|
||||
#endif // STRINGEX__H_
|
||||
Reference in New Issue
Block a user