#endif // __XSDK_H__
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "xsdk.h"
#include "xsdk_string.h"
//------------------------------------------------------------------------------
char * TrimLeft(char * p_lpszString, char p_chTrimChar /*= 0x00*/)
{
long lIndex = 0L, lStringLen = 0L;
assert(p_lpszString != NULL);
for ( lIndex = 0L;
p_lpszString[lIndex] != 0x00
&& ((p_chTrimChar == 0x00 && (p_lpszString[lIndex] == ' ' || p_lpszString[lIndex] == '\t') )
|| (p_chTrimChar != 0x00 && p_lpszString[lIndex] == p_chTrimChar));
lIndex++)
{
}
if ( lIndex > 0L && p_lpszString[lIndex] != 0x00)
{
lStringLen = (long)strlen(p_lpszString + lIndex);
memcpy((void *)p_lpszString, p_lpszString + lIndex, lStringLen + 1L);
}
else if ( p_lpszString[lIndex] == 0x00)
{
p_lpszString[0] = 0x00;
}
return p_lpszString;
}
//------------------------------------------------------------------------------
char * TrimRight(char * p_lpszString, char p_chTrimChar /*= 0x00*/)
{
int lIndex = 0L, lStringLen = 0L;
assert(p_lpszString != NULL);
lStringLen = (long)strlen(p_lpszString);
for ( lIndex = lStringLen - 1L;
lIndex >= 0L
&& ((p_chTrimChar == 0x00 && (p_lpszString[lIndex] == ' ' || p_lpszString[lIndex] == '\t') )
|| (p_chTrimChar != 0x00 && p_lpszString[lIndex] == p_chTrimChar));
lIndex--)
{
}
lIndex = (lIndex < 0L ? 0L : lIndex + 1L);
p_lpszString[lIndex] = 0x00;
return p_lpszString;
}
//------------------------------------------------------------------------------
char * Trim(char * p_lpszString, char p_chTrimChar /*= 0x00*/)
{
return TrimLeft(TrimRight(p_lpszString, p_chTrimChar), p_chTrimChar);
}
//------------------------------------------------------------------------------
char * FilterChar(char * p_lpszString, char p_chFilterChar /*= 0x00*/)
{
long lBIndex = 0L, lFIndex = 0L;
assert(p_lpszString != NULL);
for ( lBIndex = 0L, lFIndex = 0L; p_lpszString[lFIndex] != 0x00; lFIndex++)
{
if ( (p_chFilterChar == 0x00 && (p_lpszString[lFIndex] == ' ' || p_lpszString[lFIndex] == '\t') )
|| (p_chFilterChar != 0x00 && p_lpszString[lFIndex] == p_chFilterChar) )
{
continue;
}
p_lpszString[lBIndex++] = p_lpszString[lFIndex];
}
p_lpszString[lBIndex] = 0x00;
return p_lpszString;
}
//------------------------------------------------------------------------------
char * ReplaceString(char * p_lpszDestBuff, long p_lDestBuffSize,
const char * p_lpszString, const char * p_lpszFindStr, const char * p_lpszReplStr)
{
long lStringLen = 0L, lFindStrLen = 0L, lReplStrLen = 0L;
char * lpszSubStr = NULL;
assert(p_lpszDestBuff != NULL && p_lDestBuffSize > 0L);
assert(p_lpszString != NULL && p_lpszFindStr != NULL && p_lpszReplStr != NULL);
lStringLen = (long)strlen(p_lpszString);
lFindStrLen = (long)strlen(p_lpszFindStr);
lReplStrLen = (long)strlen(p_lpszReplStr);
if ( lStringLen == 0L || p_lDestBuffSize < lStringLen || p_lDestBuffSize <= (lStringLen - lFindStrLen + lReplStrLen) )
{
p_lpszDestBuff[0] = 0x00;
goto __end;
}
if ( p_lpszDestBuff != p_lpszString)
{
memcpy((void *)p_lpszDestBuff, (void *)p_lpszString, sizeof(char) * (lStringLen + 1L));
}
lpszSubStr = strstr(p_lpszDestBuff, p_lpszFindStr);
if ( lpszSubStr != NULL)
{
if ( lReplStrLen > lFindStrLen)
{
long lSubStrLen = (long)strlen(lpszSubStr);
long lOffset = lReplStrLen - lFindStrLen;
for ( ; lSubStrLen >= lFindStrLen; lSubStrLen--)
{
lpszSubStr[lSubStrLen + lOffset] = lpszSubStr[lSubStrLen];
}
//memcpy((void *)(lpszSubStr + lReplStrLen), (void *)(lpszSubStr + lFindStrLen),
// sizeof(char) * (long((p_lpszDestBuff + lStringLen) - (lpszSubStr + lFindStrLen)) + 1L));
}
memcpy((void *)lpszSubStr, (void *)p_lpszReplStr, sizeof(char) * lReplStrLen);
if ( lReplStrLen < lFindStrLen)
{
long lIndex = 0L;
long lMoveSize = (long)strlen(lpszSubStr + lFindStrLen);
long lOffset = lReplStrLen - lFindStrLen;
for ( lIndex = 0L; lIndex <= lMoveSize; lIndex++ )
{
lpszSubStr[lFindStrLen + lIndex + lOffset] = lpszSubStr[lFindStrLen + lIndex];
}
//memcpy((void *)(lpszSubStr + lReplStrLen), (void *)(lpszSubStr + lFindStrLen),
// sizeof(char) * (long((p_lpszDestBuff + lStringLen) - (lpszSubStr + lFindStrLen)) + 1L));
}
}
__end:
return lpszSubStr == NULL ? lpszSubStr : lpszSubStr + lReplStrLen;
}
// add by liusg 2015-09-02 for 调整日志目录
//------------------------------------------------------------------------------
char * CircleReplaceString(char * p_lpszDestBuff, long p_lDestBuffSize,
const char * p_lpszString, const char * p_lpszFindStr, const char * p_lpszReplStr)
{
long lStringLen = 0L, lFindStrLen = 0L, lReplStrLen = 0L;
char * lpszSubStr = NULL;
assert(p_lpszDestBuff != NULL && p_lDestBuffSize > 0L);
assert(p_lpszString != NULL && p_lpszFindStr != NULL && p_lpszReplStr != NULL);
lStringLen = (long)strlen(p_lpszString);
lFindStrLen = (long)strlen(p_lpszFindStr);
lReplStrLen = (long)strlen(p_lpszReplStr);
if ( lStringLen == 0L || p_lDestBuffSize < lStringLen || p_lDestBuffSize <= (lStringLen - lFindStrLen + lReplStrLen) )
{
p_lpszDestBuff[0] = 0x00;
goto __end;
}
if ( p_lpszDestBuff != p_lpszString)
{
memcpy((void *)p_lpszDestBuff, (void *)p_lpszString, sizeof(char) * (lStringLen + 1L));
}
lpszSubStr = strstr(p_lpszDestBuff, p_lpszFindStr);
while ( lpszSubStr != NULL)
{
if ( lReplStrLen > lFindStrLen)
{
long lSubStrLen = (long)strlen(lpszSubStr);
long lOffset = lReplStrLen - lFindStrLen;
for ( ; lSubStrLen >= lFindStrLen; lSubStrLen--)
{
lpszSubStr[lSubStrLen + lOffset] = lpszSubStr[lSubStrLen];
}
//memcpy((void *)(lpszSubStr + lReplStrLen), (void *)(lpszSubStr + lFindStrLen),
// sizeof(char) * (long((p_lpszDestBuff + lStringLen) - (lpszSubStr + lFindStrLen)) + 1L));
}
memcpy((void *)lpszSubStr, (void *)p_lpszReplStr, sizeof(char) * lReplStrLen);
if ( lReplStrLen < lFindStrLen)
{
long lIndex = 0L;
long lMoveSize = (long)strlen(lpszSubStr + lFindStrLen);
long lOffset = lReplStrLen - lFindStrLen;
for ( lIndex = 0L; lIndex <= lMoveSize; lIndex++ )
{
lpszSubStr[lFindStrLen + lIndex + lOffset] = lpszSubStr[lFindStrLen + lIndex];
}
//memcpy((void *)(lpszSubStr + lReplStrLen), (void *)(lpszSubStr + lFindStrLen),
// sizeof(char) * (long((p_lpszDestBuff + lStringLen) - (lpszSubStr + lFindStrLen)) + 1L));
}
lpszSubStr = strstr(p_lpszDestBuff, p_lpszFindStr);
}
__end:
return lpszSubStr == NULL ? lpszSubStr : lpszSubStr + lReplStrLen;
}
// end add
//------------------------------------------------------------------------------
char * PrefixalStringSpace(char * p_lpszDestBuff, long p_lDestBuffSize,
const char * p_lpszString, const char * p_lpszPrefixStr,
char p_chMidSeparator /*= '='*/, char p_chSeparator /*= ','*/,
bool p_bMatchCase /*= false*/)
{
bool bMatched = false;
long lPrefixLen = 0L, lSubStrLen = 0L;
char * lpszSubStr = NULL, * lpszSeparator = NULL;
assert(p_lpszDestBuff != NULL && p_lDestBuffSize > 0L);
memset( (void *) p_lpszDestBuff, 0x00, sizeof(char) * p_lDestBuffSize);
lpszSubStr = StrStrEx(p_lpszString, p_lpszPrefixStr, p_bMatchCase, true);
if ( lpszSubStr != NULL)
{
lPrefixLen = (long)strlen(p_lpszPrefixStr);
lpszSubStr += lPrefixLen;
for ( ; lpszSubStr[0] != p_chMidSeparator && (lpszSubStr[0] == '\t'); lpszSubStr++);
bMatched = (lpszSubStr[0] == p_chMidSeparator) ? true : false;
lpszSubStr += (bMatched == true) ? sizeof(char) * 1L : 0L;
}
if ( bMatched == true)
{
lpszSeparator = strchr(lpszSubStr, p_chSeparator);
lSubStrLen = lpszSeparator != NULL ? sizeof(char) * min((p_lDestBuffSize - 1), (long)(lpszSeparator - lpszSubStr) )
: sizeof(char) * min((p_lDestBuffSize - 1), (long)strlen(lpszSubStr));
memcpy((void *)p_lpszDestBuff, (void *)lpszSubStr, lSubStrLen);
}
return p_lpszDestBuff;
}
//------------------------------------------------------------------------------
char * PrefixalString(char * p_lpszDestBuff, long p_lDestBuffSize,
const char * p_lpszString, const char * p_lpszPrefixStr,
char p_chMidSeparator /*= '='*/, char p_chSeparator /*= ','*/,
bool p_bMatchCase /*= false*/, bool p_bTrimSpace /*= true*/)
{
bool bMatched = false;
long lPrefixLen = 0L, lSubStrLen = 0L;
char * lpszSubStr = NULL, * lpszSeparator = NULL;
assert(p_lpszDestBuff != NULL && p_lDestBuffSize > 0L);
memset( (void *) p_lpszDestBuff, 0x00, sizeof(char) * p_lDestBuffSize);
lpszSubStr = StrStrEx(p_lpszString, p_lpszPrefixStr, p_bMatchCase, true);
if ( lpszSubStr != NULL)
{
lPrefixLen = (long)strlen(p_lpszPrefixStr);
lpszSubStr += lPrefixLen;
for ( ; lpszSubStr[0] != p_chMidSeparator && (lpszSubStr[0] == ' ' || lpszSubStr[0] == '\t'); lpszSubStr++);
bMatched = (lpszSubStr[0] == p_chMidSeparator) ? true : false;
lpszSubStr += (bMatched == true) ? sizeof(char) * 1L : 0L;
}
if ( bMatched == true)
{
lpszSeparator = strchr(lpszSubStr, p_chSeparator);
lSubStrLen = lpszSeparator != NULL ? sizeof(char) * min((p_lDestBuffSize - 1), (long)(lpszSeparator - lpszSubStr) )
: sizeof(char) * min((p_lDestBuffSize - 1), (long)strlen(lpszSubStr));
memcpy((void *)p_lpszDestBuff, (void *)lpszSubStr, lSubStrLen);
}
if ( p_bTrimSpace == true && p_lpszDestBuff[0] != 0x00)
{
Trim(p_lpszDestBuff);
}
return p_lpszDestBuff;
}
//------------------------------------------------------------------------------
char * SubStringN(char * p_lpszDestBuff, long p_lDestBuffSize,
const char * p_lpszString, int p_iN, char p_chSeparator /*= ','*/,
bool p_bTrimSpace /*= false*/)
{
int iN = 0;
long lIndex = 0L, lDestBuffIdx = 0L;
assert(p_lpszDestBuff != NULL && p_lDestBuffSize > 0L);
memset( (void *) p_lpszDestBuff, 0x00, sizeof(char) * p_lDestBuffSize);
iN = p_iN;
for ( lIndex = 0L; iN >= 0 && p_lpszString[lIndex] != 0x00 && lDestBuffIdx < (p_lDestBuffSize - 1L); lIndex++ )
{
if ( p_lpszString[lIndex] == p_chSeparator)
{
iN--;
}
else if ( iN == 0)
{
p_lpszDestBuff[lDestBuffIdx++] = p_lpszString[lIndex];
}
}
if ( p_bTrimSpace == true && p_lpszDestBuff[0] != 0x00)
{
Trim(p_lpszDestBuff);
}
return p_lpszDestBuff;
}
//------------------------------------------------------------------------------
char * StrStrEx(const char * p_lpszString, const char * p_lpszSubStr,
bool p_bMatchCase /*= false*/, bool p_bMatchWord /*= false*/)
{
long lSubStrLen = 0L;
char * lpszSubStr = NULL, * lpszSubStrUpr = NULL, * lpszSubStrLwr = NULL, * lpszCursor = NULL;
assert(p_lpszString != NULL && p_lpszSubStr != NULL);
lpszCursor = (char *)p_lpszString;
lSubStrLen = ((p_bMatchCase == false || p_bMatchWord == true) ? (long)strlen(p_lpszSubStr) : 0L);
do
{
if ( p_bMatchCase == false)
{
lpszSubStrUpr = strchr(lpszCursor, toupper(p_lpszSubStr[0]));
lpszSubStrLwr = strchr(lpszCursor, tolower(p_lpszSubStr[0]));
if ( lpszSubStrUpr == NULL && lpszSubStrLwr == NULL)
{
lpszSubStr = NULL;
break;
}
else if ( lpszSubStrLwr == NULL)
{
lpszCursor = lpszSubStrUpr;
}
else if ( lpszSubStrUpr == NULL)
{
lpszCursor = lpszSubStrLwr;
}
else if ( (long)(lpszSubStrLwr - lpszSubStrUpr) > 0L)
{
lpszCursor = lpszSubStrUpr;
}
else
{
lpszCursor = lpszSubStrLwr;
}
if ( memicmp(lpszCursor, p_lpszSubStr, lSubStrLen) == 0)
{
if ( p_bMatchWord == false
|| (lpszCursor == p_lpszString
&& isalpha(*(lpszCursor + lSubStrLen)) == 0
&& isdigit(*(lpszCursor + lSubStrLen)) == 0)
|| (lpszCursor != p_lpszString
&& isalpha(*(lpszCursor - 1)) == 0
&& isdigit(*(lpszCursor - 1)) == 0
&& isalpha(*(lpszCursor + lSubStrLen)) == 0
&& isdigit(*(lpszCursor + lSubStrLen)) == 0) )
{
lpszSubStr = lpszCursor;
break;
}
}
lpszCursor++;
}
else
{
lpszCursor = strstr(lpszCursor, p_lpszSubStr);
if ( lpszCursor != NULL)
{
if ( p_bMatchWord == false
|| (lpszCursor == p_lpszString
&& isalpha(*(lpszCursor + lSubStrLen)) == 0
&& isdigit(*(lpszCursor + lSubStrLen)) == 0)
|| (lpszCursor != p_lpszString
&& isalpha(*(lpszCursor - 1)) == 0
&& isdigit(*(lpszCursor - 1)) == 0
&& isalpha(*(lpszCursor + lSubStrLen)) == 0
&& isdigit(*(lpszCursor + lSubStrLen)) == 0) )
{
lpszSubStr = lpszCursor;
break;
}
lpszCursor += lSubStrLen;
}
else
{
lpszSubStr = NULL;
break;
}
}
} while ( true);
return lpszSubStr;
}
//------------------------------------------------------------------------------
unsigned char * H2A(unsigned char * p_lpszString, const unsigned char * p_lpszHex, int p_iLength)
{
int iIndex = 0, iByte = 0;
for ( iIndex = 0; iIndex < p_iLength; iIndex++)
{
iByte = (p_lpszHex[iIndex] & 0xF0) >> 4;
p_lpszString[iIndex * 2] = iByte > 0x09 ? iByte + 0x41 - 0x0A : iByte + 0x30;
iByte = (p_lpszHex[iIndex] & 0x0F);
p_lpszString[iIndex * 2 + 1] = iByte > 0x09 ? iByte + 0x41 - 0x0A : iByte + 0x30;
}
return p_lpszString;
}
//------------------------------------------------------------------------------
unsigned char * A2H(unsigned char * p_lpszHex, const unsigned char * p_lpszString, int p_iLength)
{
int iIndex = 0;
for ( iIndex = 0; iIndex < p_iLength; iIndex++)
{
p_lpszHex[iIndex] = p_lpszString[iIndex * 2] <= 0x39 ? p_lpszString[iIndex * 2] - 0x30
: p_lpszString[iIndex * 2] - 0x41 + 0x0A;
p_lpszHex[iIndex] = p_lpszHex[iIndex] << 4;
p_lpszHex[iIndex] += p_lpszString[iIndex * 2 + 1] <= 0x39 ? p_lpszString[iIndex * 2 + 1] - 0x30
: p_lpszString[iIndex * 2 + 1] - 0x41 + 0x0A;
}
return p_lpszHex;
}
long GetValue (char *src, char *dest, int num, char ch)
{
char *s0 = dest;
dest[0] = 0;
while ( *src != 0 && *src != '\0' && num != 1)
{
if ( *src == ch)
{
num--;
}
src++;
}
while ( *src != 0 && *src != '\0' && *src != ch)
{
*s0++ = *src++;
}
*s0 = 0;
if ( num != 1)
{
return -1;
}
else
{
Trim(dest);
return 0;
}
}
// ***************************************************************
// 名称 : fCpy, 字符串复制
// 描述 : 参数与strnpcy, strcpy一致, 是两者的替代品.
// 替代strncpy时, 注意p_iCnt的大小已含'\0', 且会自动缀上'\0';
// 替代strcpy时, 只送前2个参数即可.
// 入参 : char *p_zDest 目标字符串
// size_t p_iCnt 目标字符串存储空间大小, 默认为0
// 如果>0, 则类同于strncpy
// 如果==0, 则等效于strcpy
// 出参 : const char *p_zSrc 源字符串
// 返回值 : 目标字符串(与strncpy, strcpy相同)
// 曾用名 : fStrncpy
// 修改历史 :
inline char *fCpy(char *p_zDest, const char *p_zSrc, size_t p_iCnt)
{
if ( p_iCnt > 0) {
p_zDest[p_iCnt - 1] = '\0';
return strncpy( p_zDest, p_zSrc, p_iCnt - 1);
}
else {
return strcpy(p_zDest, p_zSrc);
}
}
// ***************************************************************
// 名称 : fCpyT, 复制尾部n位
// 描述 : 复制. 若源串太长, 截断左侧多出的字符. 允许源串和目标串overlap.
// 入参 : char *p_zDest 目标字符串
// size_t p_iCnt 目标字符串存储空间大小, 默认为0
// 如果>0, 则类同于strncpy, 但左截断
// 如果==0, 则等效于strcpy
// 出参 : const char *p_zSrc 源字符串
// 返回值 : 目标字符串
// 曾用名 :
// 修改历史 :
char *fCpyT(char *p_zDest, const char *p_zSrc, size_t p_iCnt)
{
// 如果==0, 则等效于strcpy
if ( p_iCnt == 0) {
if ( p_zSrc != p_zDest) {
strcpy(p_zDest, p_zSrc);
}
return p_zDest;
}
// 如果>0, 则类同于strncpy, 但左截断
int iStart = strlen(p_zSrc) - (p_iCnt - 1);
if ( p_zSrc == p_zDest) {
if ( iStart > 0) {
std::string sMid = p_zSrc;
fCpy(p_zDest, sMid.c_str() + iStart, p_iCnt);
}
}
else {
if ( iStart > 0) {
fCpy(p_zDest, p_zSrc + iStart, p_iCnt);
}
else {
fCpy(p_zDest, p_zSrc, p_iCnt);
}
}
return p_zDest;
}
// ***************************************************************
// 名称 : fCmp, 字符串比较
// 描述 : 参数与strncmp, strcmp一致, 是两者的替代品.
// 入参 : const char *p_zStr1 字符串1
// const char *p_zStr2 字符串2
// size_t p_iCnt 比较长度, 默认为0
// 如果>0, 则等效于strncmp
// 如果==0, 则等效于strcmp
// 返回值 : 相同返回true, 否则返回false (与strncmp, strcmp的返回值不同!)
// 曾用名 :
// 修改历史 :
inline bool fCmp(const char *p_zStr1, const char *p_zStr2, size_t p_iCnt)
{
if (p_iCnt > 0) {
return (strncmp(p_zStr1, p_zStr2, p_iCnt) == 0) ? true : false;
}
else {
return (strcmp(p_zStr1, p_zStr2) == 0) ? true : false;
}
}
// ***************************************************************
// 名称 : fLTrim, 左修整(按指定字符)
// 描述 : 删除字符串头部的某字符的串
// 参数 : char *p_zStr 要操作的串
// char p_cChr 要删除的字符
// 返回值 : 所操作的串
// 曾用名 : ltrimchr, rtrim
// 修改历史 :
char *fLTrim(char *p_zStr, char p_cChr)
{
int i = 0, len = 0;
len = (int)strlen( p_zStr );
for( i = 0; i < len && p_zStr[i] == p_cChr; i++ );
if( i > 0 ) {
// mod by dongjj 2008-03-06 // strcpy( p_zStr , p_zStr + i );
memmove(p_zStr, p_zStr + i, len); // 存在overlap,这时如果用strcpy,其behavior未定义
}
return p_zStr;
}
// ***************************************************************
// 名称 : fRTrim, 右修整(按指定字符)
// 描述 : 删除字符串尾部的某字符的串
// 参数 : char *p_zStr 要操作的串
// char p_cChr 要删除的字符
// 返回值 : 所操作的串
// 曾用名 : rtrimchr, rtrim
// 修改历史 :
char *fRTrim(char *p_zStr, char p_cChr)
{
int i = 0, len = 0;
len = (int)strlen( p_zStr ) - 1;
for( i = len; i >= 0 && p_zStr[i] == p_cChr; i-- )
p_zStr[i] = 0;
return p_zStr;
}
// ***************************************************************
// 名称 : fTrim, 修整(按指定字符)
// 描述 : 删除字符串头尾部的某字符的串
// 参数 : char *p_zStr 要操作的串
// char p_cChr 要删除的字符
// 返回值 : 所操作的串
// 曾用名 : alltrimchr, alltrim, API_alltrim, fAllTrim
// 修改历史 :
char *fTrim(char *p_zStr, char p_cChr)
{
fLTrim(p_zStr, p_cChr);
fRTrim(p_zStr, p_cChr);
return p_zStr;
}
// ***************************************************************
// 名称 : fGetFineDateTime, 取当前日期时间
// 描述 : 根据格式要求,返回不同的日期时间格式(可以比fGetDateTime更精细)
// 参数 : char *p_zDateTime 保存当前日期时间的串,要求足够大空间
// const char *p_zFormat 日期时间格式,支持的格式与strftime相同,如:"%Y%m%d", "%Y-%m-%d", "%H%M%S", "%H:%M:%S"
// 比fGetDateTime更精细,能给出毫秒值。格式描述上,引入%s表示3位毫秒值。
// 当前实际支持的格式为: "%H:%M:%S", "%H:%M:%S.%s"
// 返回值 : 返回当前日期时间。格式不能识别时,返回空串
// 曾用名 : GetTimeStr(参数对调,格式描述调整为与strftime相同,
// 如"HH:MM:SS"调整为"%H:%M:%S","HH:MM:SS.sss"调整为"%H:%M:%S.%s")
// 修改历史 :
char *fGetFineDateTime(char *p_zDateTime, const char *p_zFormat)
{
struct tm *tTm = NULL;
struct timeb tb = {0};
ftime(&tb);
tTm = localtime(&(tb.time));
if (strcmp(p_zFormat, "%H:%M:%S") == 0) {
sprintf(p_zDateTime, "%02d:%02d:%02d", tTm->tm_hour, tTm->tm_min, tTm->tm_sec);
}
else if (strcmp(p_zFormat, "%H:%M:%S.%s") == 0) {
sprintf(p_zDateTime, "%02d:%02d:%02d.%03d", tTm->tm_hour, tTm->tm_min, tTm->tm_sec, tb.millitm);
}
else {
strcpy(p_zDateTime, "");
}
return p_zDateTime;
}
// FUNCTION: Get the current tick.
// RETURN: The current tick, which in milliseconds.
__int64 CurrentTick( void )
{
struct timeb tb = {0};
ftime(&tb);
return __int64(tb.time) * 1000 + tb.millitm; // Note: in vc2010, you can use "%I64d" or "%I64u" when call printf.
// return tb.time;
}
// ***************************************************************
// 名称 : GetKeyValue, 获取一组Key-Value对。
// 描述 : 获取第一组Key-Value对。
// 参数 : char *p_zKey Key缓冲区
// int p_iKeyLen Key缓冲区的长度
// char *p_zValue Value缓冲区
// int p_iValueLen Value缓冲区的长度
// const char *p_szSource 源数据字符串
// const char *p_szKeyChr Key与Value之间的分隔符
// const char *p_zValChr Key-Value对之间的分隔符
// 返回值 : 源数据串的下一个位置。没有下一个位置时,返回NULL。
// 曾用名 :
// 修改历史 : 2016-04-03 用 fGetValueByName 改版而成
char *GetKeyValue(char *p_zKey, int p_iKeyLen
, char *p_zValue, int p_iValueLen
, const char *p_szSource
, const char *p_szKeyChr
, const char *p_zValChr)
{
char *pNewSource = (char *)p_szSource;
// 取Key
{
char *pKeyEnd = strstr(pNewSource, p_szKeyChr);
if (pKeyEnd == NULL)
{
return NULL; // 没有找到更多Key,返回NULL
}
fCpy(p_zKey, pNewSource, ((pKeyEnd - pNewSource) < p_iKeyLen) ? (pKeyEnd - pNewSource) + 1 : p_iKeyLen);
pNewSource = pKeyEnd + 1;
}
// 取Value
{
char *pValueEnd = strstr(pNewSource, p_zValChr);
if (pValueEnd == NULL)
{
fCpy(p_zValue, pNewSource, p_iValueLen);
pNewSource = pNewSource + strlen(pNewSource);
}
else
{
const int iValueLen = pValueEnd - pNewSource;
fCpy(p_zValue, pNewSource, (iValueLen < p_iValueLen) ? iValueLen + 1 : p_iValueLen);
pNewSource = pValueEnd + 1;
}
}
return pNewSource;
}