mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-10 06:07:07 -06:00
4.27 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
31e7b924e8
commit
d66cf2fcf3
@@ -26,6 +26,8 @@ public:
|
||||
size_t GetCapacity() const { return _capacity; }
|
||||
void SetCapacity(size_t newCapacity)
|
||||
{
|
||||
if (newCapacity == _capacity)
|
||||
return;
|
||||
T *newBuffer;
|
||||
if (newCapacity > 0)
|
||||
{
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
// Common/StringConvert.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "StringConvert.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
|
||||
{
|
||||
UString resultString;
|
||||
if(!srcString.IsEmpty())
|
||||
{
|
||||
int numChars = MultiByteToWideChar(codePage, 0, srcString,
|
||||
srcString.Length(), resultString.GetBuffer(srcString.Length()),
|
||||
srcString.Length() + 1);
|
||||
#ifndef _WIN32_WCE
|
||||
if(numChars == 0)
|
||||
throw 282228;
|
||||
#endif
|
||||
resultString.ReleaseBuffer(numChars);
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
|
||||
{
|
||||
AString resultString;
|
||||
if(!srcString.IsEmpty())
|
||||
{
|
||||
int numRequiredBytes = srcString.Length() * 2;
|
||||
int numChars = WideCharToMultiByte(codePage, 0, srcString,
|
||||
srcString.Length(), resultString.GetBuffer(numRequiredBytes),
|
||||
numRequiredBytes + 1, NULL, NULL);
|
||||
#ifndef _WIN32_WCE
|
||||
if(numChars == 0)
|
||||
throw 282229;
|
||||
#endif
|
||||
resultString.ReleaseBuffer(numChars);
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
AString SystemStringToOemString(const CSysString &srcString)
|
||||
{
|
||||
AString result;
|
||||
CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));
|
||||
result.ReleaseBuffer();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
|
||||
{
|
||||
UString resultString;
|
||||
for (int i = 0; i < srcString.Length(); i++)
|
||||
resultString += wchar_t(srcString[i]);
|
||||
/*
|
||||
if(!srcString.IsEmpty())
|
||||
{
|
||||
int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);
|
||||
if (numChars < 0) throw "Your environment does not support UNICODE";
|
||||
resultString.ReleaseBuffer(numChars);
|
||||
}
|
||||
*/
|
||||
return resultString;
|
||||
}
|
||||
|
||||
AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
|
||||
{
|
||||
AString resultString;
|
||||
for (int i = 0; i < srcString.Length(); i++)
|
||||
resultString += char(srcString[i]);
|
||||
/*
|
||||
if(!srcString.IsEmpty())
|
||||
{
|
||||
int numRequiredBytes = srcString.Length() * 6 + 1;
|
||||
int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);
|
||||
if (numChars < 0) throw "Your environment does not support UNICODE";
|
||||
resultString.ReleaseBuffer(numChars);
|
||||
}
|
||||
*/
|
||||
return resultString;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
// Common/StringConvert.h
|
||||
|
||||
#ifndef __COMMON_STRINGCONVERT_H
|
||||
#define __COMMON_STRINGCONVERT_H
|
||||
|
||||
#include "MyWindows.h"
|
||||
#include "Common/String.h"
|
||||
#include "Types.h"
|
||||
|
||||
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);
|
||||
AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);
|
||||
|
||||
inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)
|
||||
{ return unicodeString; }
|
||||
inline const UString& GetUnicodeString(const UString &unicodeString)
|
||||
{ return unicodeString; }
|
||||
inline UString GetUnicodeString(const AString &ansiString)
|
||||
{ return MultiByteToUnicodeString(ansiString); }
|
||||
inline UString GetUnicodeString(const AString &multiByteString, UINT codePage)
|
||||
{ return MultiByteToUnicodeString(multiByteString, codePage); }
|
||||
inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT codePage)
|
||||
{ return unicodeString; }
|
||||
inline const UString& GetUnicodeString(const UString &unicodeString, UINT codePage)
|
||||
{ return unicodeString; }
|
||||
|
||||
inline const char* GetAnsiString(const char* ansiString)
|
||||
{ return ansiString; }
|
||||
inline const AString& GetAnsiString(const AString &ansiString)
|
||||
{ return ansiString; }
|
||||
inline AString GetAnsiString(const UString &unicodeString)
|
||||
{ return UnicodeStringToMultiByte(unicodeString); }
|
||||
|
||||
inline const char* GetOemString(const char* oemString)
|
||||
{ return oemString; }
|
||||
inline const AString& GetOemString(const AString &oemString)
|
||||
{ return oemString; }
|
||||
inline AString GetOemString(const UString &unicodeString)
|
||||
{ return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }
|
||||
|
||||
|
||||
#ifdef _UNICODE
|
||||
inline const wchar_t* GetSystemString(const wchar_t* unicodeString)
|
||||
{ return unicodeString;}
|
||||
inline const UString& GetSystemString(const UString &unicodeString)
|
||||
{ return unicodeString;}
|
||||
inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT codePage)
|
||||
{ return unicodeString;}
|
||||
inline const UString& GetSystemString(const UString &unicodeString, UINT codePage)
|
||||
{ return unicodeString;}
|
||||
inline UString GetSystemString(const AString &multiByteString, UINT codePage)
|
||||
{ return MultiByteToUnicodeString(multiByteString, codePage);}
|
||||
inline UString GetSystemString(const AString &multiByteString)
|
||||
{ return MultiByteToUnicodeString(multiByteString);}
|
||||
#else
|
||||
inline const char* GetSystemString(const char *ansiString)
|
||||
{ return ansiString; }
|
||||
inline const AString& GetSystemString(const AString &multiByteString, UINT codePage)
|
||||
{ return multiByteString; }
|
||||
inline const char * GetSystemString(const char *multiByteString, UINT codePage)
|
||||
{ return multiByteString; }
|
||||
inline AString GetSystemString(const UString &unicodeString)
|
||||
{ return UnicodeStringToMultiByte(unicodeString); }
|
||||
inline AString GetSystemString(const UString &unicodeString, UINT codePage)
|
||||
{ return UnicodeStringToMultiByte(unicodeString, codePage); }
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
AString SystemStringToOemString(const CSysString &srcString);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,91 +0,0 @@
|
||||
// UTFConvert.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "UTFConvert.h"
|
||||
#include "Types.h"
|
||||
|
||||
static Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
||||
|
||||
// These functions are for UTF8 <-> UTF16 conversion.
|
||||
|
||||
bool ConvertUTF8ToUnicode(const AString &src, UString &dest)
|
||||
{
|
||||
dest.Empty();
|
||||
for(int i = 0; i < src.Length();)
|
||||
{
|
||||
Byte c = (Byte)src[i++];
|
||||
if (c < 0x80)
|
||||
{
|
||||
dest += (wchar_t)c;
|
||||
continue;
|
||||
}
|
||||
if(c < 0xC0)
|
||||
return false;
|
||||
int numAdds;
|
||||
for (numAdds = 1; numAdds < 5; numAdds++)
|
||||
if (c < kUtf8Limits[numAdds])
|
||||
break;
|
||||
UInt32 value = (c - kUtf8Limits[numAdds - 1]);
|
||||
do
|
||||
{
|
||||
if (i >= src.Length())
|
||||
return false;
|
||||
Byte c2 = (Byte)src[i++];
|
||||
if (c2 < 0x80 || c2 >= 0xC0)
|
||||
return false;
|
||||
value <<= 6;
|
||||
value |= (c2 - 0x80);
|
||||
numAdds--;
|
||||
}
|
||||
while(numAdds > 0);
|
||||
if (value < 0x10000)
|
||||
dest += (wchar_t)(value);
|
||||
else
|
||||
{
|
||||
value -= 0x10000;
|
||||
if (value >= 0x100000)
|
||||
return false;
|
||||
dest += (wchar_t)(0xD800 + (value >> 10));
|
||||
dest += (wchar_t)(0xDC00 + (value & 0x3FF));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUnicodeToUTF8(const UString &src, AString &dest)
|
||||
{
|
||||
dest.Empty();
|
||||
for(int i = 0; i < src.Length();)
|
||||
{
|
||||
UInt32 value = (UInt32)src[i++];
|
||||
if (value < 0x80)
|
||||
{
|
||||
dest += (char)value;
|
||||
continue;
|
||||
}
|
||||
if (value >= 0xD800 && value < 0xE000)
|
||||
{
|
||||
if (value >= 0xDC00)
|
||||
return false;
|
||||
if (i >= src.Length())
|
||||
return false;
|
||||
UInt32 c2 = (UInt32)src[i++];
|
||||
if (c2 < 0xDC00 || c2 >= 0xE000)
|
||||
return false;
|
||||
value = ((value - 0xD800) << 10) | (c2 - 0xDC00);
|
||||
}
|
||||
int numAdds;
|
||||
for (numAdds = 1; numAdds < 5; numAdds++)
|
||||
if (value < (((UInt32)1) << (numAdds * 5 + 6)))
|
||||
break;
|
||||
dest += (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));
|
||||
do
|
||||
{
|
||||
numAdds--;
|
||||
dest += (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));
|
||||
}
|
||||
while(numAdds > 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// Common/UTFConvert.h
|
||||
|
||||
#ifndef __COMMON_UTFCONVERT_H
|
||||
#define __COMMON_UTFCONVERT_H
|
||||
|
||||
#include "Common/String.h"
|
||||
|
||||
bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);
|
||||
bool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);
|
||||
|
||||
#endif
|
||||
@@ -166,7 +166,9 @@ STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \
|
||||
MY_ADDREF_RELEASE
|
||||
|
||||
|
||||
#define MY_UNKNOWN_IMP MY_UNKNOWN_IMP_SPEC(;)
|
||||
#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \
|
||||
MY_QUERYINTERFACE_END \
|
||||
MY_ADDREF_RELEASE
|
||||
|
||||
#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \
|
||||
MY_QUERYINTERFACE_ENTRY(i) \
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
#ifndef GUID_DEFINED
|
||||
#define GUID_DEFINED
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned long Data1;
|
||||
unsigned short Data2;
|
||||
unsigned short Data3;
|
||||
UInt32 Data1;
|
||||
UInt16 Data2;
|
||||
UInt16 Data3;
|
||||
unsigned char Data4[8];
|
||||
} GUID;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <stddef.h> // for wchar_t
|
||||
#include <string.h>
|
||||
|
||||
#include "Types.h"
|
||||
#include "MyGuidDef.h"
|
||||
|
||||
typedef char CHAR;
|
||||
|
||||
@@ -34,9 +34,9 @@ inline wchar_t* MyStringGetNextCharPointer(wchar_t *p)
|
||||
{ return (p + 1); }
|
||||
inline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)
|
||||
{ return (p + 1); }
|
||||
inline wchar_t* MyStringGetPrevCharPointer(const wchar_t *base, wchar_t *p)
|
||||
inline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)
|
||||
{ return (p - 1); }
|
||||
inline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *base, const wchar_t *p)
|
||||
inline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)
|
||||
{ return (p - 1); }
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -18,9 +18,9 @@ inline UString GetUnicodeString(const AString &ansiString)
|
||||
{ return MultiByteToUnicodeString(ansiString); }
|
||||
inline UString GetUnicodeString(const AString &multiByteString, UINT codePage)
|
||||
{ return MultiByteToUnicodeString(multiByteString, codePage); }
|
||||
inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT codePage)
|
||||
inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)
|
||||
{ return unicodeString; }
|
||||
inline const UString& GetUnicodeString(const UString &unicodeString, UINT codePage)
|
||||
inline const UString& GetUnicodeString(const UString &unicodeString, UINT)
|
||||
{ return unicodeString; }
|
||||
|
||||
inline const char* GetAnsiString(const char* ansiString)
|
||||
@@ -54,9 +54,9 @@ inline AString GetOemString(const UString &unicodeString)
|
||||
#else
|
||||
inline const char* GetSystemString(const char *ansiString)
|
||||
{ return ansiString; }
|
||||
inline const AString& GetSystemString(const AString &multiByteString, UINT codePage)
|
||||
inline const AString& GetSystemString(const AString &multiByteString, UINT)
|
||||
{ return multiByteString; }
|
||||
inline const char * GetSystemString(const char *multiByteString, UINT codePage)
|
||||
inline const char * GetSystemString(const char *multiByteString, UINT)
|
||||
{ return multiByteString; }
|
||||
inline AString GetSystemString(const UString &unicodeString)
|
||||
{ return UnicodeStringToMultiByte(unicodeString); }
|
||||
|
||||
@@ -22,6 +22,25 @@ UInt64 ConvertStringToUInt64(const char *s, const char **end)
|
||||
}
|
||||
}
|
||||
|
||||
UInt64 ConvertOctStringToUInt64(const char *s, const char **end)
|
||||
{
|
||||
UInt64 result = 0;
|
||||
while(true)
|
||||
{
|
||||
char c = *s;
|
||||
if (c < '0' || c > '7')
|
||||
{
|
||||
if (end != NULL)
|
||||
*end = s;
|
||||
return result;
|
||||
}
|
||||
result <<= 3;
|
||||
result += (c - '0');
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)
|
||||
{
|
||||
UInt64 result = 0;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Types.h"
|
||||
|
||||
UInt64 ConvertStringToUInt64(const char *s, const char **end);
|
||||
UInt64 ConvertOctStringToUInt64(const char *s, const char **end);
|
||||
UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);
|
||||
|
||||
Int64 ConvertStringToInt64(const char *s, const char **end);
|
||||
|
||||
@@ -70,14 +70,46 @@ public:
|
||||
T& Front() { return operator[](0); }
|
||||
const T& Back() const { return operator[](_size - 1); }
|
||||
T& Back() { return operator[](_size - 1); }
|
||||
static int
|
||||
#ifdef _MSC_VER
|
||||
__cdecl
|
||||
#endif
|
||||
CompareRecordItems(const void *a1, const void *a2)
|
||||
{ return MyCompare(*((const T *)a1), *((const T *)a2)); }
|
||||
void Sort()
|
||||
{ qsort(&Front(), Size(), _itemSize, CompareRecordItems); }
|
||||
|
||||
void Swap(int i, int j)
|
||||
{
|
||||
T temp = operator[](i);
|
||||
operator[](i) = operator[](j);
|
||||
operator[](j) = temp;
|
||||
}
|
||||
|
||||
void Sort(int left, int right)
|
||||
{
|
||||
if (right - left < 2)
|
||||
return;
|
||||
Swap(left, (left + right) / 2);
|
||||
int last = left;
|
||||
for (int i = left; i < right; i++)
|
||||
if (operator[](i) < operator[](left))
|
||||
Swap(++last, i);
|
||||
Swap(left, last);
|
||||
Sort(left, last);
|
||||
Sort(last + 1, right);
|
||||
}
|
||||
void Sort() { Sort(0, Size()); }
|
||||
void Sort(int left, int right, int (*compare)(const T*, const T*, void *), void *param)
|
||||
{
|
||||
if (right - left < 2)
|
||||
return;
|
||||
Swap(left, (left + right) / 2);
|
||||
int last = left;
|
||||
for (int i = left; i < right; i++)
|
||||
if (compare(&operator[](i), &operator[](left), param) < 0)
|
||||
Swap(++last, i);
|
||||
Swap(left, last);
|
||||
Sort(left, last, compare, param);
|
||||
Sort(last + 1, right, compare, param);
|
||||
}
|
||||
|
||||
void Sort(int (*compare)(const T*, const T*, void *), void *param)
|
||||
{
|
||||
Sort(0, Size(), compare, param);
|
||||
}
|
||||
};
|
||||
|
||||
typedef CRecordVector<int> CIntVector;
|
||||
@@ -167,17 +199,13 @@ public:
|
||||
Insert(right, item);
|
||||
return right;
|
||||
}
|
||||
static int
|
||||
#ifdef _MSC_VER
|
||||
__cdecl
|
||||
#endif
|
||||
CompareObjectItems(const void *a1, const void *a2)
|
||||
|
||||
void Sort(int (*compare)(void *const *, void *const *, void *), void *param)
|
||||
{ CPointerVector::Sort(compare, param); }
|
||||
|
||||
static int CompareObjectItems(void *const *a1, void *const *a2, void *param)
|
||||
{ return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }
|
||||
void Sort()
|
||||
{
|
||||
CPointerVector &pointerVector = *this;
|
||||
qsort(&pointerVector[0], Size(), sizeof(void *), CompareObjectItems);
|
||||
}
|
||||
void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user