18 INT_PTR
CharIndexA(
const char* Buffer,
const char* Inside )
20 INT_PTR ix = (Inside - Buffer);
25 INT_PTR
CharIndexW(
const wchar_t* Buffer,
const wchar_t* Inside )
27 INT_PTR ix = (Inside - Buffer);
37 char* __fastcall
strecpy(
register char* Dst,
register const char* Src )
39 while( *Src ) *Dst++ = *Src++;
68 wchar_t* __fastcall
wcsecpy(
register wchar_t* Dst,
register const wchar_t* Src )
70 while( *Src ) *Dst++ = *Src++;
77 char* __fastcall
strnecpy(
register char* Dst,
register const char* Src,
size_t n )
79 if ( n )
while( *Src && n-- ) *Dst++ = *Src++;
84 wchar_t* __fastcall
wcsnecpy(
register wchar_t* Dst,
register const wchar_t* Src,
size_t n )
86 if ( n )
while( *Src && n-- ) *Dst++ = *Src++;
96 char*
stristr(
const char* str,
const char* pattern )
98 if ( !*pattern )
return (
char*) str;
99 char* curr = (
char*) str;
102 register char* s = curr;
103 register char* pat = (
char*) pattern;
104 while( *s && *pat && (0 == (tolower(*s)-tolower(*pat))) ) {
107 if (!*pat)
return curr;
113 wchar_t*
wcsistr(
const wchar_t* str,
const wchar_t* pattern )
115 if ( !*pattern )
return (
wchar_t*) str;
116 wchar_t* curr = (
wchar_t*) str;
119 register wchar_t* s = curr;
120 register wchar_t* pat = (
wchar_t*) pattern;
121 while( *s && *pat && (0 == (towlower(*s)-towlower(*pat))) ) {
124 if (!*pat)
return curr;
134 char* __fastcall
strncpyz(
register char* Dst,
register const char* Src,
size_t Count )
137 while( *Src && --Count ) *Dst++ = *Src++;
142 wchar_t* __fastcall
wcsncpyz(
register wchar_t* Dst,
register const wchar_t* Src,
size_t Count )
144 wchar_t* result = Dst;
145 while( *Src && --Count ) *Dst++ = *Src++;
156 return Src ? (1 + wcslen( Src )) *
sizeof(WCHAR) : 0;
172 UINT Len = (UINT)_tcslen( Src );
173 TSTR Dup =
new TCHAR[ Len + 2 ];
174 if (!Dup) SetLastError( ERROR_OUTOFMEMORY );
185 TSTR pBuf =
new TCHAR[ nChar + 2 ];
186 if (pBuf) memset( pBuf, 0, (nChar+2)*
TCHAR_SIZE );
187 else SetLastError( ERROR_OUTOFMEMORY );
193 #ifndef HAVE_STRUCTURED_EH 198 DWORD xCode = GetExceptionCode();
208 UINT Len = (UINT) wcslen( Src );
209 LPWSTR Dup =
new WCHAR[ Len + 2 ];
210 if (!Dup) SetLastError( ERROR_OUTOFMEMORY );
221 #ifndef HAVE_STRUCTURED_EH 226 DWORD xCode = GetExceptionCode();
227 TRACE(
DP_ERROR,
_F(
"Exception %#x in operator delete[].\r\n"), xCode );
239 UINT Len = (UINT) strlen( Src );
241 if (Dup) strcpy( Dup, Src );
252 UINT Len = (UINT) wcslen( Src );
254 if (Dup) wcscpy( Dup, Src );
260 UINT size = nChar + 2;
283 static CHAR szBuf[ MAX_PATH ];
284 WideCharToMultiByte( CP_ACP,0, pwStr,-1, szBuf,MAX_PATH, NULL, NULL );
292 int len = WideCharToMultiByte( CodePg, 0, pWStr, -1, NULL, 0, NULL, NULL );
294 if (pDup) WideCharToMultiByte( CodePg, 0, pWStr, -1, pDup, len, NULL, NULL );
300 int len = MultiByteToWideChar( CodePg, MB_PRECOMPOSED, pAStr, -1, NULL, 0 );
302 if (pDup) MultiByteToWideChar( CodePg, MB_PRECOMPOSED, pAStr, -1, pDup, len );
312 static TCHAR sbuf[ MAX_PATH ];
316 Count =
dimof( sbuf );
318 if (!LoadString( hModule, Id, Buf, Count )) Buf[0] = 0;
331 WORD count = LoadStringW( hModule, Id, (
WSTR)&pwzStr, 0 );
332 if (!count) pwzStr = NULL;
333 if (pCount) *pCount = count;
341 UINT bundleNr = Id / 16 + 1;
342 UINT strNr = Id & 15, cbRes;
344 hModule, (
CSTR)(UINT_PTR) bundleNr, RT_STRING, Lang, &cbRes
348 for( UINT i = 0; i < strNr; i++ )
350 pwzStr += (1 + (
WORD)*pwzStr);
354 if (pCount) *pCount = ccStr;
372 wcsncpy( pzStr, rcStr, count );
374 #else // Translate to multibyte 375 WideCharToMultiByte( CP_ACP, 0, rcStr, count, pzStr, count, NULL, NULL );
400 ASTR pEnd = strchr( pStr, 0 );
401 if (!Action( pStr, Context ))
break;
409 PWSTR pStr = MultiSz;
414 PWSTR pEnd = wcschr( pStr, 0 );
415 if (!Action( pStr, Context ))
break;
425 register ACSTR pStr = MultiSz;
426 while( *pStr ) pStr = strchr( pStr, 0 ) + 1;
427 return UINT( 1 + UINT_PTR( pStr - MultiSz ));
432 register WCSTR pStr = MultiSz;
433 while( *pStr ) pStr = wcschr( pStr, 0 ) + 1;
434 return UINT( 1 + UINT_PTR( pStr - MultiSz ));
442 register ACSTR pStr = MultiSz;
446 pStr = strchr( pStr, 0 ) + 1;
454 register WCSTR pStr = MultiSz;
458 pStr = wcschr( pStr, 0 ) + 1;
469 register TSTR pSrc = pText;
470 register TSTR pDst = pText;
472 while( *pSrc && *pSrc !=
CR ) {
481 while( *pSrc && *pSrc !=
CR )
499 pEnd = _tcschr( pBegin,
LF );
500 if (pEnd) *pEnd++ = 0;
503 pEnd = _tcschr( pBegin, 0 );
508 if (ccSz) *ccSz = (UINT)
CharIndex( pText, pEnd );
519 pEnd = _tcschr( pEnd,0 );
534 if (pDup) memcpy( pDup, pzMulti, Len );
547 static TCHAR szBuf[ MAX_PATH ];
556 ccBuf =
dimof(szBuf);
560 _vstprintf_s( Buf, ccBuf, Fmt, va );
569 TSTR Svr, UINT ccSvr,
TSTR Share, UINT ccShare,
TSTR Path, UINT ccPath )
571 #define _INVALPARM ERROR_INVALID_PARAMETER // shorthand 583 TCHAR szUncPath[ 80+80+MAX_PATH ];
587 size_t offs = _tcsspn( szUncPath, _T(
"\\?.") );
588 CSTR pzServer = &szUncPath[ offs ];
592 ok = (0 != _tcsnicmp( pzServer, _T(
"UNC\\"), 4 ));
607 if (pzPath) *pzPath++ = 0;
611 size_t svrLen = _tcslen( pzServer );
612 size_t shrLen = _tcslen( pzShare );
614 ok = (ccSvr > svrLen) && (ccShare > shrLen);
615 bool havePath = (Path && pzPath);
616 if (ok && havePath) ok = (ccPath > _tcslen( pzPath ));
618 if (!ok) SetLastError( ERROR_INSUFFICIENT_BUFFER );
623 if (havePath)
_tcsncpyz( Path, pzPath, ccPath );
635 IN
CSTR ShareName, OUT
WSTR Server, UINT ccServer, OUT
WSTR Share, UINT ccShare )
637 TCHAR pzServer[80], pzShare[80];
645 wcsncpyz( Server, pzServer, ccServer );
646 wcsncpyz( Share, pzShare, ccShare );
648 MultiByteToWideChar( CP_ACP, 0, pzServer,-1, Server, ccServer );
649 MultiByteToWideChar( CP_ACP, 0, pzShare,-1, Share, ccShare );
663 return __GetRoot( Root, ccRoot, PathName );
670 static __thread_local TCHAR szPath[ MAX_PATH ];
672 CSTR pEnd = _tcschr( PathName, 0 ) - 1;
675 _tcscpy_s( szPath,
dimof(szPath), PathName );
676 szPath[ pEnd-PathName ] = 0;
684 static __thread_local TCHAR szPath[ MAX_PATH ];
686 TSTR pEnd = _tcschr( (
TSTR)PathName, 0 ) - 1;
689 _tcscpy_s( szPath,
dimof(szPath), PathName );
690 pEnd = &szPath[ pEnd-PathName+1 ];
691 *pEnd++ =
BSLASH; *pEnd = 0;
703 TSTR pzItem = _tcschr( Str, From );
708 TSTR pzNext = _tcschr( pzItem, From );
709 if (!pzNext) pzEnd = _tcschr( pzItem, 0 );
712 if (pCount) *pCount = count;
729 static const TCHAR _STARTBRACK = _T(
'[');
730 static const TCHAR _ENDBRACK = _T(
']');
731 static const TCHAR _ASTERISK = _T(
'*');
732 static const TCHAR _QUESTMARK = _T(
'?');
733 static const TCHAR _DASH =_T(
'-');
735 static int __cdecl as_is(
int ch ) {
return ch; }
746 int (__cdecl *_getcase)(
int ch ) = CaseSens ? as_is : toupper;
750 switch( p = _getcase( *Pattern++ ))
753 return *String ? false :
true;
769 if ( (c = *String++) == 0)
774 while( p = _getcase( *Pattern++ ))
781 p = _getcase( *Pattern );
782 if (p == 0 || p == _ENDBRACK)
785 if (c >= l && c <= p)
794 while( p && p != _ENDBRACK )
799 c = _getcase( *String++ );
816 struct __textDedupData
821 UINT nParts, nEmitted;
825 static bool __stdcall __addtoWordList(
TSTR Str, PVOID pData )
827 __textDedupData* pdd = (__textDedupData*) pData;
829 bool added = pdd->list->AddString( Str, pdd->caseSens );
834 static bool __stdcall __emitTextPart(
TSTR partStr, PVOID pData )
836 __textDedupData* pdd = (__textDedupData*) pData;
838 pdd->pzText =
_tcsecpy( pdd->pzText, partStr );
839 if (++pdd->nEmitted < pdd->nParts) *pdd->pzText++ = pdd->Sep;
848 ASTR Text, CHAR Separator,
bool caseSens,
bool emitSorted )
850 UINT Len = (UINT)_tcslen( Text );
851 bool endSep = (Text[Len-1] == Separator);
853 if (!endSep && IsBadWritePtr( &Text[Len+1],
TCHAR_SIZE ))
855 SetLastError( ERROR_INSUFFICIENT_BUFFER );
870 WordList partList( Count, Len, 4, 16 );
871 __textDedupData dd = { 0,0,0,0,0,0 };
874 dd.caseSens = caseSens;
881 for( UINT ix = 0, last = partList.
Count-1; ix < partList.
Count; ++ix )
884 if (ix < last) *pzPart++ = Separator;
891 dd.nParts = partList.
Count;
894 Len = (UINT)_tcslen( Text );
898 #endif//ndef _UNICODE 907 UINT strLen = (UINT)_tcslen( String );
908 UINT addLen = (UINT)_tcslen( Prolog );
909 UINT sepLen = Sep ? 1 : 0;
911 if (strLen + addLen + sepLen + 1 > ccBuf)
912 SetLastError( ERROR_INSUFFICIENT_BUFFER );
916 memmove( &String[ addLen + sepLen ], String, cbMove );
917 if (Sep) String[ addLen ] = Sep;
918 memcpy( String, Prolog, addLen *
TCHAR_SIZE );
919 newLen = strLen + addLen + sepLen;
927 UINT strLen = (UINT)_tcslen( String );
928 UINT addLen = (UINT)_tcslen( Epilog );
929 UINT sepLen = Sep ? 1 : 0;
931 if (strLen + addLen + sepLen + 1 > ccBuf)
932 SetLastError( ERROR_INSUFFICIENT_BUFFER );
935 memcpy( &String[ strLen + sepLen ], Epilog, addLen *
TCHAR_SIZE );
936 if (Sep) String[ strLen ] = Sep;
937 newLen = strLen + addLen + sepLen;
945 #ifndef NO_WINTERNAL // UNICODE_STRING 950 const PUNICODE_STRING String, BOOLEAN CaseInSensitive,
951 ULONG HashAlgorithm, PULONG HashValue
959 hMod = GetModuleHandleA(
"NTDLL" );
976 #endif//ndef NO_WINTERNAL 983 static TCHAR buffer[ MAX_PATH ];
984 static CCSTR hex = _T(
"0123456789ABCDEF");
990 bool usrbuf = (buf != NULL && size != 0);
997 bufrem =
dimof(buffer);
1000 if (dots && bufrem < 7) {
1001 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1005 if (dots) bufrem -= 4;
1006 for( *dst=0; len && bufrem; len--, bufrem -= 2 )
1008 if ((bufrem <= 4) && (len > 1))
1013 *dst++ = hex[ *data >> 4 ];
1014 *dst++ = hex[ *data & 0x0F ];
1022 if (dots)
for( len=3; len && bufrem > 1; len--, bufrem-- )
1025 return usrbuf ? buf : buffer;
1032 static TSTR _scatCh(
TSTR ps, TCHAR ch ) {
1033 *ps++ = ch; *ps = 0;
1039 static CCSTR sizePrefix = _T(
" kMGTPEZY");
1041 #if 1 // Changed to fpt calc (for consistency w IsoDataSizeStr) 1044 static TCHAR sbuf[40];
1045 CSTR pfx;
double size = (double) Size;
1046 for( pfx = sizePrefix; size >= 1000; size /= 1000, pfx++ );
1048 _stprintf( sbuf, _T(
"%0.2f %cB"), size, *pfx );
1051 #else // The legacy integer algorithm.. 1054 static TCHAR sbuf[40];
1055 CSTR pfx; ULONG frac = 0;
static const UINT DIV = 1000;
1056 for( pfx = sizePrefix; Size >= DIV; frac = Size % DIV, Size /= DIV, pfx++ );
1058 _stprintf( sbuf, _T(
"%lu.%lu %cB"), ULONG(Size), frac/100, *pfx );
1065 #if 1 // FIX: Take the performance hit of floating point calculation.. 1068 static TCHAR sbuf[40];
1069 CSTR pfx;
double size = (double)_Size;
1070 for( pfx = sizePrefix; size >= 1024; size /= 1024, pfx++ );
1072 _stprintf( sbuf, _T(
"%0.2f %ciB"), size, *pfx );
1075 #else // BUGBUG: This begets wrong value for peculiar corner case Size arguments. 1078 static TCHAR sbuf[40];
1080 CSTR pfx; ULONG frac = 0;
1082 for( pfx = sizePrefix; Size >= 1024; frac = Size & 0x3FF, Size >>= 10, pfx++ );
1084 _stprintf( sbuf, _T(
"%lu.%lu %ciB"), ULONG(_Size), frac/100, *pfx );
1094 static TCHAR sbuf[16];
1109 if (Attr & FILE_ATTRIBUTE_DIRECTORY) pz = _scatCh( pz, _T(
'D') );
1110 if (Attr & FILE_ATTRIBUTE_HIDDEN) pz = _scatCh( pz, _T(
'H') );
1111 if (Attr & FILE_ATTRIBUTE_READONLY) pz = _scatCh( pz, _T(
'R') );
1112 if (Attr & FILE_ATTRIBUTE_SYSTEM) pz = _scatCh( pz, _T(
'S') );
1113 if (Attr & FILE_ATTRIBUTE_ARCHIVE) pz = _scatCh( pz, _T(
'A') );
1115 if (Attr & FILE_ATTRIBUTE_COMPRESSED) pz = _scatCh( pz, _T(
'C') );
1116 if (Attr & FILE_ATTRIBUTE_ENCRYPTED) pz = _scatCh( pz, _T(
'E') );
1117 if (Attr & FILE_ATTRIBUTE_OFFLINE) pz = _scatCh( pz, _T(
'O') );
1118 if (Attr & FILE_ATTRIBUTE_REPARSE_POINT) pz = _scatCh( pz, _T(
'P') );
1119 if (Attr & FILE_ATTRIBUTE_SPARSE_FILE) pz = _scatCh( pz, _T(
'Z') );
1120 if (Attr & FILE_ATTRIBUTE_TEMPORARY) pz = _scatCh( pz, _T(
'T') );
1127 FileTimeToSystemTime( FTime, &st );
1133 static TCHAR sbuf[ 80 ];
1137 T.tm_sec = Time->wSecond;
1138 T.tm_min = Time->wMinute;
1139 T.tm_hour = Time->wHour;
1140 T.tm_mday = Time->wDay;
1141 T.tm_mon = Time->wMonth - 1;
1142 T.tm_year = Time->wYear - 1900;
1143 T.tm_wday = Time->wDayOfWeek;
1147 _tcsftime( sbuf,40, Fmt, &T );
1153 static TCHAR sbuf[ 80 ];
1159 if (SHGetFileInfo( FName, 0, &fi,
sizeof(fi), SHGFI_TYPENAME ))
1160 _tcscpy_s( sbuf,
dimof(sbuf), fi.szTypeName );
1173 static CCSTR pfix = _T(
"yzafpnum kMGTPEZY");
1174 static const int midIx = 8;
1199 static TCHAR sbuf[ 50 ];
1210 double val = (double) Value;
1213 _stprintf_s( sbuf,
dimof(sbuf), _T(
"%.*f %s"), nDecimals, val, Unit );
1214 else if (expo < -24 || expo > 24)
1215 _stprintf_s( sbuf,
dimof(sbuf), _T(
"%.*fe%i %s"), nDecimals, val, expo, Unit );
1218 pfixCh = pfix[ midIx + (expo/3) ];
1219 _stprintf_s( sbuf,
dimof(sbuf), _T(
"%.*f %c%s"), nDecimals, val, pfixCh, Unit );
1232 static TCHAR szBuf[ 64 ];
1233 static CCSTR S_GuidFmt = _T(
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");
1239 ccBuf =
dimof(szBuf);
1241 _stprintf_s( pzBuf, ccBuf, S_GuidFmt,
1242 riid.Data1, riid.Data2, riid.Data3, riid.Data4[0], riid.Data4[1],
1243 riid.Data4[2], riid.Data4[3], riid.Data4[4], riid.Data4[5],
1244 riid.Data4[6], riid.Data4[7]
1251 static TCHAR szBuf[ 128 ];
1253 TCHAR regPath[ 64 ];
1255 int len = _stprintf_s( regPath,
dimof(regPath), _T(
"Interface\\%s"), pzGuid );
1261 ccBuf =
dimof(szBuf);
1267 LONG cbData = ccBuf;
1269 cbData *=
sizeof(WCHAR);
1272 bool ok =
REG_OK( RegQueryValue( HKEY_CLASSES_ROOT, regPath, pzDst, &cbData ));
1273 if (!ok)
_tcsncpyz( pzBuf, pzGuid, ccBuf );
1280 static TCHAR szBuf[256];
1284 ccBuf =
dimof(szBuf);
1287 LPOLESTR poStr = NULL;
1288 HRESULT rc = OleRegGetUserType( riid, USERCLASSTYPE_SHORT, &poStr );
1289 if (FAILED( rc ) || !poStr)
1294 if (0 == wcsncmp( poStr, L
"CLSID_", 6 )) pzDst = pzBuf;
1297 pzDst =
_tcsecpy( pzBuf, _T(
"CLSID_") );
1303 WideCharToMultiByte( CP_ACP,0, poStr, -1, pzDst, ccBuf, NULL, NULL );
1306 if (poStr) CoTaskMemFree( poStr );
1312 static TCHAR szBuf[256];
1316 ccBuf =
dimof(szBuf);
1319 LPOLESTR poStr = NULL;
1320 HRESULT rc = OleRegGetUserType( riid, USERCLASSTYPE_APPNAME, &poStr );
1321 if (FAILED( rc ) || !poStr)
1328 WideCharToMultiByte( CP_ACP,0, poStr, -1, pzBuf, ccBuf, NULL, NULL );
1331 if (poStr) CoTaskMemFree( poStr );
1338 #ifndef NO_WINTERNAL // UNICODE_STRING 1342 puStr->Buffer = (PWSTR) pwzSrc;
1343 if (!pwzSrc) puStr->Length = puStr->MaximumLength = 0;
1346 puStr->Length = (USHORT) wcslen( pwzSrc ) *
sizeof(WCHAR);
1347 puStr->MaximumLength = puStr->Length +
sizeof(WCHAR);
1354 pStr->Buffer = (LPSTR) pzSrc;
1355 if (!pzSrc) pStr->Length = pStr->MaximumLength = 0;
1358 pStr->Length = (USHORT) strlen( pzSrc );
1359 pStr->MaximumLength = pStr->Length + 1;
1367 return (PUNICODE_STRING) Buffer;
1372 USHORT cbSrc = (USHORT)
wcsbytes( wzSrc );
1373 bool ok = (cbSrc <= puStr->MaximumLength);
1377 memcpy( puStr->Buffer, wzSrc, cbSrc );
1385 UINT cbBuf =
sizeof(UNICODE_STRING) + cbStr;
1387 PUNICODE_STRING pu = (PUNICODE_STRING)
mem_Alloc( cbBuf );
1390 pu->Length = 0; pu->MaximumLength = cbStr;
1391 pu->Buffer = PWSTR( pu + 1 );
1393 if (cbAlloc) *cbAlloc = cbBuf;
1397 #endif//ndef NO_WINTERNAL // UNICODE_STRING 1403 #ifndef NO_WINTERNAL // UNICODE_STRING 1433 Length = MaximumLength = 0;
1451 Length = Src ? (USHORT) strlen( Src ) : 0;
1452 bool ok = _allocBuf( Length );
1453 if (!ok) Length = 0;
1456 MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, Src, Length+1, Buffer, Length+1 );
1457 Length *=
sizeof(WCHAR);
1464 USHORT Len = Src.Length /
sizeof(WCHAR);
1465 USHORT Max = Src.MaximumLength /
sizeof(WCHAR);
1468 if (Src.Buffer[ Len ] != 0)
1470 if ((Max > Len) && !IsBadWritePtr( Src.Buffer + Len,
WCHAR_SIZE ))
1472 Src.Buffer[ Len ] = 0;
1477 if (_allocBuf( Len ))
1479 memcpy( Buffer, Src.Buffer, Src.Length );
1485 TRACE(
DP_ERROR,
_F(
"Alloc failed. Target will not be NUL terminated!\n") );
1493 shallow_Copy: _freeBuf();
1494 MaximumLength = Src.MaximumLength;
1495 Buffer = Src.Buffer;
1497 Length = Src.Length;
1519 bool UString::_allocBuf(
size_t nChar )
1521 static const size_t _CHUNK = 16;
1523 size_t nBytes = nChar *
sizeof(WCHAR);
1524 bool ok = ((
Flags & UF_OWN_BUFFER) && (MaximumLength > nBytes));
1527 nBytes +=
sizeof(WCHAR);
1528 MaximumLength = (USHORT)
ROUND_UP( nBytes, _CHUNK );
1529 if (!(
Flags & UF_OWN_BUFFER)) Buffer = NULL;
1531 if (!Buffer) Buffer = (PWSTR)
mem_Alloc( MaximumLength );
1532 else Buffer = (PWSTR)
mem_Realloc( Buffer, MaximumLength );
1534 ok = (Buffer != NULL);
1535 if (ok)
Flags |= UF_OWN_BUFFER;
1538 Length = MaximumLength = 0;
1539 Flags &= ~UF_OWN_BUFFER;
1545 void UString::_freeBuf()
1548 Length = MaximumLength = 0;
1549 Flags &= ~UF_OWN_BUFFER;
1553 #endif//ndef NO_WINTERNAL 1565 StgChunk = ChunkSize ? ChunkSize : 1024;
1592 #ifdef HAVE_STRUCTURED_EH 1605 #ifdef HAVE_STRUCTURED_EH 1607 DWORD xcode = GetExceptionCode();
1618 UINT len = UINT( 1 + strlen( Str ));
1623 #ifdef HAVE_STRUCTURED_EH 1627 memcpy( dup, Str, len );
1629 #ifdef HAVE_STRUCTURED_EH 1631 DWORD xcode = GetExceptionCode();
1644 #if 0 // UNDER CONSIDERATION. Initial alphatest passed.. 1646 template <
typename TCh>
1647 class TStringCache {
1655 TStringCache( UINT InitSize
DEF_(4096), UINT ChunkSize
DEF_(4096) )
1662 StgChunk = ChunkSize ? ChunkSize : 1024;
1663 StgSize = InitSize ?
ROUND_UP( InitSize, StgChunk ) : StgChunk;
1667 if (!Storage) StgSize = 0;
1677 TCh* DupStr( TCh* Str )
1680 TCh* _pz = Str;
while( *_pz != 0 ) _pz++;
1682 UINT nbytes = UINT_PTR(_pz) - UINT_PTR(Str) +
sizeof(TCh);
1683 UINT end = StgUsed + nbytes;
1684 if (end > StgSize) GrowStorage();
1687 #ifdef HAVE_STRUCTURED_EH 1690 dup = &Storage[ StgUsed ];
1691 memcpy( dup, Str, nbytes );
1693 #ifdef HAVE_STRUCTURED_EH 1695 DWORD xcode = GetExceptionCode();
1704 Storage[ StgUsed ] = 0;
1710 if (Storage) Storage[ StgUsed = 0 ] = 0;
1715 Storage = (TCh*)
mem_Free( Storage );
1716 StgSize = StgUsed = 0;
1719 int StorageSize() {
return StgSize; }
1720 int StorageUsed() {
return StgUsed; }
1723 UINT StgSize, StgUsed, StgChunk;
1727 UINT newSize = StgSize + StgChunk;
1728 #ifdef HAVE_STRUCTURED_EH 1741 #ifdef HAVE_STRUCTURED_EH 1743 DWORD xcode = GetExceptionCode();
1762 ListChunk = ListGrowBy ? ListGrowBy : 32;
1789 int newSize = newDim *
sizeof(
char*);
1793 bool ok = (tmp != NULL);
1808 int (*cmpfunc)(
const char *string1,
const char *string2 );
1809 cmpfunc = caseSens ? strcmp : _stricmp;
1813 int l = 0, r =
Count-1, m = 0, cmp = 0;
1816 m = l + (r - l) / 2;
1817 cmp = cmpfunc( Str,
Strings[ m ]);
1821 #if defined(__GNUC__) 1827 else if (cmp > 0) l = m + 1;
1833 #ifdef HAVE_STRUCTURED_EH 1839 cbMove = (
Count - m) *
sizeof(
char*);
1845 INT_PTR preDup = (INT_PTR)
Storage;
1847 INT_PTR offset = INT_PTR(
Storage) - preDup;
1854 for( UINT ix=0; ix <=
Count; ix++ )
1856 if (ix == UINT(m))
continue;
1863 #ifdef HAVE_STRUCTURED_EH 1865 DWORD xcode = GetExceptionCode();
1876 int (__stdcall *Compare)(
char* Key,
char* Str,
void* Ctx ),
1883 int l = 0, m = 0, r =
Count-1, cmp = 0;
1886 m = l + (r - l) / 2;
1887 cmp = Compare( Key,
Strings[ m ], Context );
1893 else if (cmp > 0) l = m + 1;
1901 #endif//def __cplusplus UINT MultiSzLengthW(WCSTR MultiSz)
UINT MultiSzLengthA(ACSTR MultiSz)
TSTR DuplicateMultiSz(CSTR pzMulti)
END_STRSAFE_OVERRIDE ACSTR _MBStr(WCSTR pwStr)
ULONG GetStringHash(WCSTR Str, ULONG Algorithm, bool caseSens)
WCSTR FindResourceStrEx(HMODULE hModule, UINT Id, LANGID Lang, PWORD pCount)
CSTR WithoutBackslash(CSTR PathName)
CSTR WithBackslash(CSTR PathName)
UINT EnumerateMultiSzA(ASTR MultiSz, PFnEnumMultiStringA Action, PVOID Context)
CSTR mem_FreeStr(CSTR Dup)
CSTR FileTimeStr(FILETIME *FTime, CSTR Fmt)
UINT MultiSzCountA(ACSTR MultiSz)
PUNICODE_STRING mem_AllocUniStr(WORD ccStr, PULONG cbAlloc)
CSTR FreeResourceStrEx(CSTR pzRcDupStr)
#define INIT_PACKED_UNICODE_STRING(pu, bufsize)
void * mem_Realloc(void *pBlk, size_t Bytes)
PUNICODE_STRING _InitUnicodeString(PUNICODE_STRING puStr, PCWSTR pwzSrc)
ASTR mem_ADupWStr(WCSTR pWStr, UINT CodePg, UINT ccExtra)
TSTR MultiCrLfToLf(TSTR pText)
void * mem_Alloc(size_t Bytes)
BEGIN_STRSAFE_OVERRIDE CSTR newStr(CSTR Src)
long double EngUnits(long double Value, int *pExpo)
#define BEGIN_STRSAFE_OVERRIDE
TSTR ReplaceStrChar(TSTR Str, TCHAR From, TCHAR To, OPTOUT UINT *pCount)
bool InitShellFunc(bool useOle=false, DWORD coFlag=COINIT_APARTMENTTHREADED)
bool SplitUncPath(CSTR UncPath, TSTR Svr, UINT ccSvr, TSTR Share, UINT ccShare, TSTR Path, UINT ccPath)
PUNICODE_STRING InitPackedUnicodeString(PVOID Buffer, USHORT cbBuffer)
TSTR newStrBuf(WORD nChar)
CSTR LoadStr(HMODULE hModule, UINT Id, TSTR Buf, UINT Count)
wchar_t *__fastcall wcsncpyz(register wchar_t *Dst, register const wchar_t *Src, size_t Count)
bool SplitNetShareName(IN CSTR ShareName, OUT WSTR Server, UINT ccServer, OUT WSTR Share, UINT ccShare)
bool(__stdcall * PFnEnumMultiStringW)(WSTR Str, PVOID Context)
WSTR mem_WDupAStr(ACSTR pAStr, UINT CodePg, UINT ccExtra)
UINT DeduplicateCharSepText(ASTR Text, CHAR Separator, bool caseSens, bool emitSorted)
TSTR LinesToMultiSz(TSTR pText, UINT *ccSz)
char * stristr(const char *str, const char *pattern)
bool ShellFuncInitialized()
UINT EnumerateMultiSzW(WSTR MultiSz, PFnEnumMultiStringW Action, PVOID Context)
bool MatchPattern(CSTR String, CSTR Pattern, bool CaseSens)
class WordList * PWordList
CSTR GetIIDString(REFIID riid, TSTR pzBuf, UINT ccBuf)
ASTR mem_AllocAStr(WORD nChar)
CSTR GetGUIDString(REFIID riid, TSTR pzBuf, UINT ccBuf)
BOOL(WINAPI *SysImgList::Shell_GetImageLists)(HIMAGELIST *pimlLarge
PVOID WINAPI LoadCustomResourceEx(HMODULE hModule, CSTR Id, CSTR Type, LANGID Language OPTIN=0, UINT *pSize OPTOUT=NULL)
void * mem_Free(void *pBlk)
TSTR MultiSzToLines(TSTR pText)
CSTR GetCLSIDAppname(REFIID riid, TSTR pzBuf, UINT ccBuf)
_NTFN_EXTERN NTSTATUS _RtlHashUnicodeString(IN CONST UNICODE_STRING *String, IN BOOLEAN CaseInSensitive, IN ULONG HashAlgorithm, OUT PULONG HashValue)
WSTR mem_AllocWStr(WORD nChar)
char *__fastcall strnecpy(register char *Dst, register const char *Src, size_t n)
bool SetLastErrorFromNtStatus(NTSTATUS Status)
CSTR EngFormat(long double Value, BYTE nDecimals, CSTR Unit)
StringCache(UINT InitSize=4096, UINT ChunkSize=4096)
CSTR __cdecl StrFmt(TSTR Buf, UINT ccBuf, CSTR Fmt,...)
UString & operator=(WCSTR Src)
bool __GetRoot(OUT TSTR Root, UINT ccRoot, IN CSTR PathName)
bool SetUnicodeString(PUNICODE_STRING puStr, WCSTR wzSrc)
#define ROUND_UP(x, chunk)
CSTR IsoDataSizeStr(UINT64 _Size)
__inline bool __ChkOkSetErr(BOOL Ok, DWORD Err)
bool AddString(char *Str, bool caseSens=true)
bool __forceinline bool_cast(BOOL B52)
UINT MultiSzCountW(WCSTR MultiSz)
INT_PTR CharIndexA(const char *Buffer, const char *Inside)
UINT AppendString(TSTR String, UINT ccBuf, TCHAR Sep, CSTR Epilog)
wchar_t *__fastcall wcsnecpy(register wchar_t *Dst, register const wchar_t *Src, size_t n)
WSTR mem_DupWStr(WCSTR Src)
CSTR DupResourceStrEx(HMODULE hModule, UINT Id, LANGID Lang, PWORD pCount)
Debug and error handling support.
WordList(UINT InitListDim=128, UINT InitStgSize=4096, UINT ListGrowBy=128, UINT StgGrowBy=4096)
INT_PTR CharIndex(const chrType *Buffer, const chrType *Inside)
TSTR FreeMultiSz(TSTR pzMulti)
INT_PTR CharIndexW(const wchar_t *Buffer, const wchar_t *Inside)
wchar_t *__fastcall wcsecpy(register wchar_t *Dst, register const wchar_t *Src)
char * Search(char *Key, int(__stdcall *Compare)(char *Key, char *Str, void *Ctx), void *Context)
CSTR GetCLSIDString(REFIID riid, TSTR pzBuf, UINT ccBuf)
CSTR DataSizeStr(UINT64 Size)
#define NT_SUCCESS(Status)
size_t wcsbytes(const wchar_t *Src)
WCSTR deleteWStr(WCSTR Dup)
CSTR FileTypeStr(CSTR FName)
PSTRING _InitString(PSTRING pStr, LPCSTR pzSrc)
WCSTR GetResourceStr(HMODULE hModule, UINT Id, PWORD pCount)
#define END_STRSAFE_OVERRIDE
CSTR HexString(PBYTE data, UINT len, TSTR buf, UINT size, bool dots)
bool GetRootOf(IN CSTR PathName, OUT TSTR Root, UINT ccRoot)
CSTR SysTimeStr(SYSTEMTIME *Time, CSTR Fmt)
UINT PrependString(TSTR String, UINT ccBuf, TCHAR Sep, CSTR Prolog)
bool __forceinline IsString(CSTR Str)
char *__fastcall strncpyz(register char *Dst, register const char *Src, size_t Count)
char *__fastcall strecpy(register char *Dst, register const char *Src)
ASTR mem_DupAStr(ACSTR Src)
bool(__stdcall * PFnEnumMultiStringA)(ASTR Str, PVOID Context)
END_STRSAFE_OVERRIDE CSTR FileAttribStr(DWORD Attr)
wchar_t * wcsistr(const wchar_t *str, const wchar_t *pattern)