📄 storestr.cpp
字号:
}
if ( nItem <= 1 ) return 0 ;
wchar_t **pPointerToName = (wchar_t**) malloc ( ( nItem ) * sizeof(wchar_t*) ) ;
if ( ! pPointerToName ) return 1 ;
wchar_t *szStringGet = szStart ;
for ( nCount = 0 ; nCount < nItem ; nCount ++ ) {
pPointerToName [ nCount ] = szStringGet ;
szStringGet = wcsend ( szStringGet ) + 1 ;
}
qsort ( pPointerToName, nItem, sizeof(wchar_t*), (QSORT_COMPARE_FUNCTION) CompareFunction ) ;
for ( nCount = 0 ; nCount < nItem ; nCount ++ ) {
StoredStringsTmp = StoreStringsW ( StoredStringsTmp, pPointerToName [ nCount ] ) ;
if ( StoredStringsTmp == STOREDSTRINGS_ERROR ) break ;
}
if ( StoredStringsTmp && StoredStringsTmp != STOREDSTRINGS_ERROR ) {
memmove ( szStart, GetFirstStringW ( StoredStringsTmp ), ( szStringGet - szStart ) * sizeof(wchar_t) ) ;
FreeStoredStringsW ( StoredStringsTmp ) ;
nResult = 0 ;
}
free ( pPointerToName ) ;
return nResult ;
}
// 偙傟埲崀偵捛壛偝傟偨暥帤楍偺傒 SortStoredStrings () 偱僜乕僩乮UNICODE斉乯
int MarkSortStartW ( STOREDSTRINGSW *StoredStrings ) {
if ( ! StoredStrings || StoredStrings == STOREDSTRINGS_ERROR ) return 1 ;
StoredStrings->szSortStart = StoredStrings->szWrite ;
StoredStrings->nSortStartCount = StoredStrings->nCount ;
return 0 ;
}
// MarkSortStart偱巜掕偝傟偨儅乕僋傪夝彍乮UNICODE斉乯
int UnmarkSortStartW ( STOREDSTRINGSW *StoredStrings ) {
if ( ! StoredStrings || StoredStrings == STOREDSTRINGS_ERROR ) return 1 ;
StoredStrings->szSortStart = NULL ;
StoredStrings->nSortStartCount = 0 ;
return 0 ;
}
// 僶僢僼傽偐傜儅乕僋偝傟偨嵟弶偺暥帤楍傪曉偡乮UNICODE斉乯
// 暥帤楍偑側偗傟偽丄NULL 傪曉偡
const wchar_t *GetFirstMarkedStringW ( STOREDSTRINGSW *StoredStrings ) {
if ( ! StoredStrings || StoredStrings == STOREDSTRINGS_ERROR ) return NULL ;
if ( StoredStrings->szSortStart ) return StoredStrings->szRead = StoredStrings->szSortStart ;
else return StoredStrings->szRead = StoredStrings->szStart ;
}
////////////////////////////////////////
// 斾妑娭悢乮CRT乯 //
////////////////////////////////////////
// 惓弴偱僜乕僩乮ANSI斉乯
int __cdecl CompareStoredStringsA ( const char **pArg1, const char **pArg2 ) {
return strcmp ( *pArg1, *pArg2 ) ;
}
// 媡弴偱僜乕僩乮ANSI斉乯
int __cdecl CompareStoredStringsRevA ( const char **pArg1, const char **pArg2 ) {
return - strcmp ( *pArg1, *pArg2 ) ;
}
// 惓弴偱僜乕僩乮UNICODE斉乯
int __cdecl CompareStoredStringsW ( const wchar_t **pArg1, const wchar_t **pArg2 ) {
return wcscmp ( *pArg1, *pArg2 ) ;
}
// 媡弴偱僜乕僩乮UNICODE斉乯
int __cdecl CompareStoredStringsRevW ( const wchar_t **pArg1, const wchar_t **pArg2 ) {
return - wcscmp ( *pArg1, *pArg2 ) ;
}
////////////////////////////////////////
// 斾妑娭悢乮LOCALE乯 //
////////////////////////////////////////
static int CompareStringSystemA ( LCID Locale, DWORD dwFlags, LPCSTR szSrc, int nSrc, LPCSTR szDst, int nDst ) ;
static int CompareStringSystemW ( LCID Locale, DWORD dwFlags, LPCWSTR szSrc, int nSrc, LPCWSTR szDst, int nDst ) ;
// 惓弴偱僜乕僩乮ANSI斉乯
int __cdecl CompareStoredStringsLocaleA ( const char **pArg1, const char **pArg2 ) {
return CompareStringSystemA ( LOCALE_SYSTEM_DEFAULT, 0, *pArg1, -1, *pArg2, -1 ) ;
}
// 媡弴偱僜乕僩乮ANSI斉乯
int __cdecl CompareStoredStringsLocaleRevA ( const char **pArg1, const char **pArg2 ) {
return - CompareStringSystemA ( LOCALE_SYSTEM_DEFAULT, 0, *pArg1, -1, *pArg2, -1 ) ;
}
// 惓弴偱僜乕僩乮UNICODE斉乯
int __cdecl CompareStoredStringsLocaleW ( const wchar_t **pArg1, const wchar_t **pArg2 ) {
return CompareStringSystemW ( LOCALE_SYSTEM_DEFAULT, 0, *pArg1, -1, *pArg2, -1 ) ;
}
// 媡弴偱僜乕僩乮UNICODE斉乯
int __cdecl CompareStoredStringsLocaleRevW ( const wchar_t **pArg1, const wchar_t **pArg2 ) {
return - CompareStringSystemW ( LOCALE_SYSTEM_DEFAULT, 0, *pArg1, -1, *pArg2, -1 ) ;
}
////////////////////////////////////////
// 斾妑娭悢乮NUMERICAL乯 //
////////////////////////////////////////
static int CompareStringLogicalA ( const char *szSrc, const char *szDst ) ;
static int CompareStringLogicalW ( const wchar_t *szSrc, const wchar_t *szDst ) ;
// 惓弴偱僜乕僩乮ANSI斉乯
int __cdecl CompareStoredStringsNumericalA ( const char **pArg1, const char **pArg2 ) {
return CompareStringLogicalA ( *pArg1, *pArg2 ) ;
}
// 媡弴偱僜乕僩乮ANSI斉乯
int __cdecl CompareStoredStringsNumericalRevA ( const char **pArg1, const char **pArg2 ) {
return - CompareStringLogicalA ( *pArg1, *pArg2 ) ;
}
// 惓弴偱僜乕僩乮UNICODE斉乯
int __cdecl CompareStoredStringsNumericalW ( const wchar_t **pArg1, const wchar_t **pArg2 ) {
return CompareStringLogicalW ( *pArg1, *pArg2 ) ;
}
// 媡弴偱僜乕僩乮UNICODE斉乯
int __cdecl CompareStoredStringsNumericalRevW ( const wchar_t **pArg1, const wchar_t **pArg2 ) {
return - CompareStringLogicalW ( *pArg1, *pArg2 ) ;
}
////////////////////////////////////////
// CompareString () //
////////////////////////////////////////
static int CompareStringSystemA ( LCID Locale, DWORD dwFlags, LPCSTR szSrc, int nSrc, LPCSTR szDst, int nDst ) {
int nResult = CompareStringA ( Locale, dwFlags, szSrc, nSrc, szDst, nDst ) ;
if ( nResult ) return nResult - CSTR_EQUAL ;
return 0 ;
}
static int CompareStringSystemW ( LCID Locale, DWORD dwFlags, LPCWSTR szSrc, int nSrc, LPCWSTR szDst, int nDst ) {
if ( IsNT () ) {
int nResult = CompareStringW ( Locale, dwFlags, szSrc, nSrc, szDst, nDst ) ;
if ( nResult ) return nResult - CSTR_EQUAL ;
return 0 ;
}
int nSrcA, nDstA ;
char *szSrcA = w2aduplen ( szSrc, nSrc, & nSrcA ) ;
char *szDstA = w2aduplen ( szDst, nDst, & nDstA ) ;
int nResult = 0 ;
if ( szSrcA && szDstA ) nResult = CompareStringA ( Locale, dwFlags, szSrcA, nSrcA, szDstA, nDstA ) ;
free ( szSrcA ) ;
free ( szDstA ) ;
if ( nResult ) return nResult - CSTR_EQUAL ;
return 0 ;
}
////////////////////////////////////////
// StrCmpLogical () //
////////////////////////////////////////
static int LoadShlwapiDll ( void ) {
#ifndef STRCMP_LOGICAL_TEST
if ( IsNT () ) {
if ( ! hShlwapi && ( hShlwapi = LoadLibraryW ( L"SHLWAPI.DLL" ) ) ) FreeLibraryOnDetach () ;
GETPROCADDRESS ( hShlwapi, STRCMPLOGICALW, StrCmpLogicalW ) ;
}
#else
fprintf ( stderr, "Testing StrCmpLogical...\n" ) ;
#endif
return 0 ;
}
// StrCmpLogicalW() 偺 ANSI斉
static int StrCmpLogicalA ( const char *szSrc, const char *szDst ) {
wchar_t *szSrcW = a2wdup ( szSrc ) ;
wchar_t *szDstW = a2wdup ( szDst ) ;
int nResult = 0 ;
if ( szSrcW && szDstW ) nResult = StrCmpLogicalW ( szSrcW, szDstW ) ;
free ( szSrcW ) ;
free ( szDstW ) ;
return nResult ;
}
static int CompareStringLogicalA ( const char *szSrc, const char *szDst ) {
if ( StrCmpLogicalW ) return StrCmpLogicalA ( szSrc, szDst ) ;
if ( ! szSrc || ! szDst ) return 0 ;
const char *szSrcStart = szSrc ;
const char *szDstStart = szDst ;
while ( *szSrc || *szDst ) {
if ( isascii ( *szSrc ) && isdigit ( *szSrc ) && isascii ( *szDst ) && isdigit ( *szDst ) ) {
unsigned long nSrc = strtoul ( szSrc, & szSrc, 10 ) ;
unsigned long nDst = strtoul ( szDst, & szDst, 10 ) ;
if ( nSrc < nDst ) return -1 ;
if ( nSrc > nDst ) return 1 ;
}
else if ( *szSrc && *szDst ) {
const char *szSrcSaved = szSrc ;
const char *szDstSaved = szDst ;
while ( *szSrc && ! ( isascii ( *szSrc ) && isdigit ( *szSrc ) ) ) szSrc ++ ;
while ( *szDst && ! ( isascii ( *szDst ) && isdigit ( *szDst ) ) ) szDst ++ ;
int nResult = CompareStringSystemA ( LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, szSrcSaved, (int) ( szSrc - szSrcSaved ), szDstSaved, (int) ( szDst - szDstSaved ) ) ;
if ( nResult ) return nResult ;
}
else {
if ( *szSrc ) return 1 ;
if ( *szDst ) return -1 ;
}
}
return CompareStringSystemA ( LOCALE_SYSTEM_DEFAULT, 0, szSrcStart, -1, szDstStart, -1 ) ;
}
static int CompareStringLogicalW ( const wchar_t *szSrc, const wchar_t *szDst ) {
if ( StrCmpLogicalW ) return StrCmpLogicalW ( szSrc, szDst ) ;
if ( ! szSrc || ! szDst ) return 0 ;
const wchar_t *szSrcStart = szSrc ;
const wchar_t *szDstStart = szDst ;
while ( *szSrc || *szDst ) {
if ( isascii ( *szSrc ) && isdigit ( *szSrc ) && isascii ( *szDst ) && isdigit ( *szDst ) ) {
unsigned long nSrc = wcstoul ( szSrc, & szSrc, 10 ) ;
unsigned long nDst = wcstoul ( szDst, & szDst, 10 ) ;
if ( nSrc < nDst ) return -1 ;
if ( nSrc > nDst ) return 1 ;
}
else if ( *szSrc && *szDst ) {
const wchar_t *szSrcSaved = szSrc ;
const wchar_t *szDstSaved = szDst ;
while ( *szSrc && ! ( isascii ( *szSrc ) && isdigit ( *szSrc ) ) ) szSrc ++ ;
while ( *szDst && ! ( isascii ( *szDst ) && isdigit ( *szDst ) ) ) szDst ++ ;
int nResult = CompareStringSystemW ( LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, szSrcSaved, (int) ( szSrc - szSrcSaved ), szDstSaved, (int) ( szDst - szDstSaved ) ) ;
if ( nResult ) return nResult ;
}
else {
if ( *szSrc ) return 1 ;
if ( *szDst ) return -1 ;
}
}
return CompareStringSystemW ( LOCALE_SYSTEM_DEFAULT, 0, szSrcStart, -1, szDstStart, -1 ) ;
}
////////////////////////////////////////
// 嫟捠娭悢 //
////////////////////////////////////////
static void __cdecl ExitProc ( void ) {
if ( hShlwapi ) FreeLibrary ( hShlwapi ) ;
hShlwapi = NULL ;
}
static int FreeLibraryOnDetach ( void ) {
#ifdef _USRDLL
return atexit ( ExitProc ) ;
#else
return 0 ;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -