📄 string.h
字号:
#pragma once
//==========================================================================
// 常用操作宏
//==========================================================================
#ifndef COUNT
#define COUNT(x) sizeof(x)/sizeof(x[0])
#endif
#ifndef MIN
#define MIN(x,y) (((DWORD)(x)<(DWORD)(y))?(x):(y))
#endif
#ifndef MAX
#define MAX(x,y) (((DWORD)(x)>(DWORD)(y))?(x):(y))
#endif
#ifndef ASSERT_ADDRESS
#define ASSERT_ADDRESS(p,size) ASSERT((p)!=NULL && AfxIsValidAddress((p),(size),TRUE))
#endif
#ifndef GET_SAFE_STRING
#define GET_SAFE_STRING(str) ( (str)?(str):_T("") )
#endif
#ifndef GETFILESIZE
#define GETFILESIZE(fad) (( (fad).nFileSizeHigh << sizeof(DWORD) ) | (fad).nFileSizeLow)
#endif
// 开关标志是否“置位”了
#ifndef SWITCH_IS_FLAG
#define SWITCH_IS_FLAG(nConstFlag,nValue) ( ( (nConstFlag) & (nValue) ) == (nConstFlag) )
#endif
#ifndef DLL_INTERNAL
#define DLL_INTERNAL __declspec( dllexport )
#endif
// strncat 函数
#ifndef strncat_hw
#ifdef UNICODE
#define strncat_hw wcsncat
#else
#define strncat_hw strncat
#endif
#endif
// strrchr 函数
#ifndef strrchr_hw
#ifdef UNICODE
#define strrchr_hw wcsrchr
#else
#define strrchr_hw strrchr
#endif
#endif
// strchr 函数
#ifndef strchr_hw
#ifdef UNICODE
#define strchr_hw wcschr
#else
#define strchr_hw strchr
#endif
#endif
// strstr 函数
#ifndef strstr_hw
#ifdef UNICODE
#define strstr_hw wcsstr
#else
#define strstr_hw strstr
#endif
#endif
// sscanf 函数
#ifdef UNICODE
#define sscanf_hw swscanf
#else
#define sscanf_hw sscanf
#endif
// _vsnprintf 函数
#ifndef _vsnprintf_hw
#ifdef UNICODE
#define _vsnprintf_hw _vsnwprintf
#else
#define _vsnprintf_hw _vsnprintf
#endif
#endif
// sprintf 函数
#ifndef sprintf_hw
#ifdef UNICODE
#define sprintf_hw swprintf
#else
#define sprintf_hw sprintf
#endif
#endif
// _snprintf 函数
#ifndef _snprintf_hw
#ifdef UNICODE
#define _snprintf_hw _snwprintf
#else
#define _snprintf_hw _snprintf
#endif
#endif
// strtok 函数
#ifndef strtok_hw
#ifdef UNICODE
#define strtok_hw wcstok
#else
#define strtok_hw strtok
#endif
#endif
//
// 注意:如果是从 CString 中查找时 Find 千万不要用 LPCTSTR 或者 char* 变量,一定是要用 CString 变量
//
template<class T1, class T2>
int FindFromArray ( IN T1 &Ary, IN T2 Find )
{
int nCount = (int)Ary.GetSize();
for ( int i=0; i<nCount; i++ )
{
T2 tGetValue = Ary.GetAt(i);
if ( tGetValue == Find )
return i;
}
return -1;
}
enum
{
STRING_IS_MULTICHARS = 0, // 是多字节字符串
STRING_IS_UNICODE, // 是UNICODE字符串
STRING_IS_SOFTCODE, // 是和程序一样的字符串编码
};
class DLL_INTERNAL CMultiByteString
{
public:
CMultiByteString ( LPCTSTR lpszOrg, int nOrgStringEncodeType=STRING_IS_SOFTCODE, OUT char *buf=NULL, int size=0, OUT int *pnCount=NULL );
~CMultiByteString ();
char *GetBuffer()
{
if ( m_pszData ) return m_pszData;
return "";
}
int GetLength()
{
if ( m_pszData ) return (int)strlen(m_pszData);
return 0;
}
private:
char *m_pszData;
BOOL m_bNewBuffer;
};
DLL_INTERNAL CString Data2HexString ( char *data, int size, int nBytesPerLine=16 );
DLL_INTERNAL int ConvStringToHexData(CString csOrgStr, BYTE *szOutBuffer, int nOutBufferSize);
// hwSnprintf 函数
#ifdef UNICODE
#define hwSnprintf hwSnprintfW
#else
#define hwSnprintf hwSnprintfA
#endif
DLL_INTERNAL CString GetCompatibleString ( LPVOID lpszOrg, BOOL bOrgIsUncode );
DLL_INTERNAL int hwSnprintfA ( char* buffer, int count, char* format, ... );
DLL_INTERNAL int hwSnprintfW ( WCHAR* buffer, int count, WCHAR* format, ... );
DLL_INTERNAL BOOL StringToGUID ( LPCTSTR lpszGUID, GUID &Guid);
DLL_INTERNAL CString GUIDToString ( GUID &Guid );
DLL_INTERNAL CString FormatString ( LPCTSTR lpszStr, ... );
DLL_INTERNAL int CalcCharCount ( LPCTSTR lpszText, TCHAR chCalc );
DLL_INTERNAL CString GetOneLine ( CString &str, LPCTSTR lpszLineEndFlag=_T("\n"), BOOL bEndAsClrf=FALSE );
DLL_INTERNAL int FindGraphPos ( CString &csOrg, int nStartPos );
DLL_INTERNAL int FindNonGraphPos ( CString &csOrg, int nStartPos );
DLL_INTERNAL CString GetOneWord ( CString &csOrg, int nCaseChange=0 );
DLL_INTERNAL void DeleteAfterChar ( CString &csOrg, TCHAR cDel );
DLL_INTERNAL BOOL PartTwoWord ( IN CString &csOrg, OUT CString &csWord1, OUT CString &csWord2, IN TCHAR cPartChr=_T(':') );
DLL_INTERNAL CString IntToString ( int nValue, BOOL bUnsigned=TRUE );
DLL_INTERNAL CString FormatBytes ( double fFileSize );
DLL_INTERNAL TCHAR *hwStrChr ( LPCTSTR string, int c );
DLL_INTERNAL void ReplaceChineseStrToEnglish ( TCHAR *szBuf, TCHAR cReplace );
DLL_INTERNAL void CleanseString ( CString &cs, LPCTSTR lpszApp=NULL );
DLL_INTERNAL int PartStringAndAddToStrAry ( LPCTSTR pStr, CStringArray &StrAry, LPCTSTR seps=_T("\t\r\n") );
DLL_INTERNAL int PartStringAndAddToStrAry ( LPCTSTR pStr, CStringArray &StrAry, TCHAR nPartFlag );
DLL_INTERNAL int PartDigitOrSpecifyCharAndAddToStrAry ( LPCTSTR pStr, CStringArray &StrAry, TCHAR *seps=NULL );
DLL_INTERNAL int PartStringAndAddToStrAry ( LPCTSTR lpszStr, CStringArray &StrAry, TCHAR nFirstFlag, TCHAR nSecondFlag );
DLL_INTERNAL int StrFind ( LPCTSTR lpszOrg, int nStart, TCHAR cFind, ... );
DLL_INTERNAL void UIntAry2StrAry ( IN CUIntArray &UIntAry, OUT CStringArray &StrAry );
DLL_INTERNAL CStringArray *SyncopateString ( char *szText, int SyncopateLength );
DLL_INTERNAL int FindSentenceSyncopatePostion ( char *szData, int nPreparePos );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -