diff options
Diffstat (limited to 'dep/CascLib/src/common/Common.cpp')
-rw-r--r-- | dep/CascLib/src/common/Common.cpp | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/dep/CascLib/src/common/Common.cpp b/dep/CascLib/src/common/Common.cpp index 74f86d44853..2dbdd470478 100644 --- a/dep/CascLib/src/common/Common.cpp +++ b/dep/CascLib/src/common/Common.cpp @@ -16,15 +16,15 @@ // Conversion to uppercase/lowercase // Converts ASCII characters to lowercase -// Converts slash (0x2F) to backslash (0x5C) -unsigned char AsciiToLowerTable[256] = +// Converts backslash (0x5C) to normal slash (0x2F) +unsigned char AsciiToLowerTable_Slash[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x5C, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x5B, 0x2F, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, @@ -39,7 +39,7 @@ unsigned char AsciiToLowerTable[256] = // Converts ASCII characters to uppercase // Converts slash (0x2F) to backslash (0x5C) -unsigned char AsciiToUpperTable[256] = +unsigned char AsciiToUpperTable_BkSlash[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, @@ -218,31 +218,37 @@ TCHAR * CombinePath(const TCHAR * szDirectory, const TCHAR * szSubDir) return szFullPath; } -void NormalizeFileName_UpperBkSlash(const char * szSrcFileName, char * szTrgFileName) +void NormalizeFileName_UpperBkSlash(char * szTrgFileName, const char * szSrcFileName, size_t cchMaxChars) { + char * szTrgFileEnd = szTrgFileName + cchMaxChars; size_t i; // Normalize the file name: ToLower + BackSlashToSlash - for(i = 0; szSrcFileName[i] != 0; i++) - szTrgFileName[i] = AsciiToUpperTable[szSrcFileName[i]]; + for(i = 0; szSrcFileName[i] != 0 && szTrgFileName < szTrgFileEnd; i++) + szTrgFileName[i] = AsciiToUpperTable_BkSlash[szSrcFileName[i]]; + + assert(szSrcFileName[i] == 0); szTrgFileName[i] = 0; } -void NormalizeFileName_LowerSlash(char * szFileName) +void NormalizeFileName_LowerSlash(char * szTrgFileName, const char * szSrcFileName, size_t cchMaxChars) { + char * szTrgFileEnd = szTrgFileName + cchMaxChars; + size_t i; + // Normalize the file name: ToLower + BackSlashToSlash - for(size_t i = 0; szFileName[i] != 0; i++) - { - szFileName[i] = AsciiToLowerTable[szFileName[i]]; - szFileName[i] = (szFileName[i] != '\\') ? szFileName[i] : '/'; - } + for(i = 0; szSrcFileName[i] != 0 && szTrgFileName < szTrgFileEnd; i++) + szTrgFileName[i] = AsciiToLowerTable_Slash[szSrcFileName[i]]; + + assert(szSrcFileName[i] == 0); + szTrgFileName[i] = 0; } int ConvertDigitToInt32(const TCHAR * szString, PDWORD PtrValue) { BYTE Digit; - Digit = (BYTE)(AsciiToUpperTable[szString[0]] - _T('0')); + Digit = (BYTE)(AsciiToUpperTable_BkSlash[szString[0]] - _T('0')); if(Digit > 9) Digit -= 'A' - '9' - 1; @@ -266,11 +272,11 @@ int ConvertStringToInt32(const TCHAR * szString, size_t nMaxDigits, PDWORD PtrVa BYTE DigitOne; BYTE DigitTwo; - DigitOne = (BYTE)(AsciiToUpperTable[szString[0]] - _T('0')); + DigitOne = (BYTE)(AsciiToUpperTable_BkSlash[szString[0]] - _T('0')); if(DigitOne > 9) DigitOne -= 'A' - '9' - 1; - DigitTwo = (BYTE)(AsciiToUpperTable[szString[1]] - _T('0')); + DigitTwo = (BYTE)(AsciiToUpperTable_BkSlash[szString[1]] - _T('0')); if(DigitTwo > 9) DigitTwo -= 'A' - '9' - 1; @@ -383,7 +389,7 @@ bool CheckWildCard(const char * szString, const char * szWildCard) // Calculate match count while(nMatchCount < nSubStringLength) { - if(AsciiToUpperTable[(BYTE)szString[nMatchCount]] != AsciiToUpperTable[(BYTE)szWildCard[nMatchCount]]) + if(AsciiToUpperTable_BkSlash[(BYTE)szString[nMatchCount]] != AsciiToUpperTable_BkSlash[(BYTE)szWildCard[nMatchCount]]) break; if(szString[nMatchCount] == 0) break; @@ -406,7 +412,7 @@ bool CheckWildCard(const char * szString, const char * szWildCard) else { // If we came to the end of the string, compare it to the wildcard - if(AsciiToUpperTable[(BYTE)*szString] != AsciiToUpperTable[(BYTE)*szWildCard]) + if(AsciiToUpperTable_BkSlash[(BYTE)*szString] != AsciiToUpperTable_BkSlash[(BYTE)*szWildCard]) return false; // If we arrived to the end of the string, it's a match |