This commit is contained in:
Igor Pavlov
2015-01-03 00:00:00 +00:00
committed by Kornel Lesiński
parent 7e021179cd
commit 0713a3ab80
153 changed files with 2744 additions and 1485 deletions
+2
View File
@@ -10,8 +10,10 @@
#include "MyWindows.h"
#ifdef _WIN32
#ifdef _MSC_VER
typedef size_t ssize_t;
#endif
#endif
namespace NC {
namespace NFile {
+3 -10
View File
@@ -2,17 +2,10 @@
#include "StdAfx.h"
#ifdef _WIN32
#include <windows.h>
#include <wchar.h>
#else
#include <ctype.h>
#endif
#include "DynLimBuf.h"
#include "MyString.h"
CDynLimBuf::CDynLimBuf(size_t limit)
CDynLimBuf::CDynLimBuf(size_t limit) throw()
{
_chars = 0;
_pos = 0;
@@ -30,7 +23,7 @@ CDynLimBuf::CDynLimBuf(size_t limit)
}
}
CDynLimBuf & CDynLimBuf::operator+=(char c)
CDynLimBuf & CDynLimBuf::operator+=(char c) throw()
{
if (_error)
return *this;
@@ -62,7 +55,7 @@ CDynLimBuf & CDynLimBuf::operator+=(char c)
return *this;
}
CDynLimBuf &CDynLimBuf::operator+=(const char *s)
CDynLimBuf &CDynLimBuf::operator+=(const char *s) throw()
{
if (_error)
return *this;
+10 -10
View File
@@ -11,12 +11,12 @@
while (i != 0) { i--; *s++ = temp[i]; } \
*s = 0;
void ConvertUInt32ToString(UInt32 val, char *s)
void ConvertUInt32ToString(UInt32 val, char *s) throw()
{
CONVERT_INT_TO_STR(char, 16);
}
void ConvertUInt64ToString(UInt64 val, char *s)
void ConvertUInt64ToString(UInt64 val, char *s) throw()
{
if (val <= (UInt32)0xFFFFFFFF)
{
@@ -26,7 +26,7 @@ void ConvertUInt64ToString(UInt64 val, char *s)
CONVERT_INT_TO_STR(char, 24);
}
void ConvertUInt64ToOct(UInt64 val, char *s)
void ConvertUInt64ToOct(UInt64 val, char *s) throw()
{
UInt64 v = val;
unsigned i;
@@ -46,7 +46,7 @@ void ConvertUInt64ToOct(UInt64 val, char *s)
while (i);
}
void ConvertUInt32ToHex(UInt32 val, char *s)
void ConvertUInt32ToHex(UInt32 val, char *s) throw()
{
UInt32 v = val;
unsigned i;
@@ -66,7 +66,7 @@ void ConvertUInt32ToHex(UInt32 val, char *s)
while (i);
}
void ConvertUInt64ToHex(UInt64 val, char *s)
void ConvertUInt64ToHex(UInt64 val, char *s) throw()
{
UInt64 v = val;
unsigned i;
@@ -86,7 +86,7 @@ void ConvertUInt64ToHex(UInt64 val, char *s)
while (i);
}
void ConvertUInt32ToHex8Digits(UInt32 val, char *s)
void ConvertUInt32ToHex8Digits(UInt32 val, char *s) throw()
{
s[8] = 0;
for (int i = 7; i >= 0; i--)
@@ -110,12 +110,12 @@ void ConvertUInt32ToHex8Digits(UInt32 val, wchar_t *s)
}
*/
void ConvertUInt32ToString(UInt32 val, wchar_t *s)
void ConvertUInt32ToString(UInt32 val, wchar_t *s) throw()
{
CONVERT_INT_TO_STR(wchar_t, 16);
}
void ConvertUInt64ToString(UInt64 val, wchar_t *s)
void ConvertUInt64ToString(UInt64 val, wchar_t *s) throw()
{
if (val <= (UInt32)0xFFFFFFFF)
{
@@ -125,7 +125,7 @@ void ConvertUInt64ToString(UInt64 val, wchar_t *s)
CONVERT_INT_TO_STR(wchar_t, 24);
}
void ConvertInt64ToString(Int64 val, char *s)
void ConvertInt64ToString(Int64 val, char *s) throw()
{
if (val < 0)
{
@@ -135,7 +135,7 @@ void ConvertInt64ToString(Int64 val, char *s)
ConvertUInt64ToString(val, s);
}
void ConvertInt64ToString(Int64 val, wchar_t *s)
void ConvertInt64ToString(Int64 val, wchar_t *s) throw()
{
if (val < 0)
{
+2 -2
View File
@@ -8,7 +8,7 @@
#include "../Windows/FileIO.h"
void CLang::Clear()
void CLang::Clear() throw()
{
delete []_text;
_text = 0;
@@ -149,7 +149,7 @@ bool CLang::Open(CFSTR fileName, const wchar_t *id)
return false;
}
const wchar_t *CLang::Get(UInt32 id) const
const wchar_t *CLang::Get(UInt32 id) const throw()
{
int index = _ids.FindInSorted(id);
if (index < 0)
+29 -6
View File
@@ -3,20 +3,43 @@
#ifndef __COMMON_MY_INITGUID_H
#define __COMMON_MY_INITGUID_H
/*
This file must be included only to one C++ file in project before
declarations of COM interfaces with DEFINE_GUID macro.
Each GUID must be initialized exactly once in project.
There are two different versions of the DEFINE_GUID macro in guiddef.h (MyGuidDef.h):
- if INITGUID is not defined: DEFINE_GUID declares an external reference to the symbol name.
- if INITGUID is defined: DEFINE_GUID initializes the symbol name to the value of the GUID.
Also we need IID_IUnknown that is initialized in some file for linking:
MSVC: by default the linker uses some lib file that contains IID_IUnknown
MinGW: add -luuid switch for linker
WinCE: we define IID_IUnknown in this file
Other: we define IID_IUnknown in this file
*/
#ifdef _WIN32
#ifdef UNDER_CE
#include <basetyps.h>
#endif
#include <initguid.h>
#ifdef UNDER_CE
DEFINE_GUID(IID_IUnknown,
0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#endif
#else
#define INITGUID
#include "MyGuidDef.h"
DEFINE_GUID(IID_IUnknown,
0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#endif
#else
#define INITGUID
#include "MyGuidDef.h"
DEFINE_GUID(IID_IUnknown,
0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#endif
#endif
+1 -1
View File
@@ -18,7 +18,7 @@ static UInt32 GetSubBits(UInt32 value, unsigned startPos, unsigned numBits) thro
static inline unsigned GetSubBit(UInt32 v, unsigned n) { return (unsigned)(v >> n) & 1; }
bool CMap32::Find(UInt32 key, UInt32 &valueRes) const
bool CMap32::Find(UInt32 key, UInt32 &valueRes) const throw()
{
valueRes = (UInt32)(Int32)-1;
if (Nodes.Size() == 0)
+37 -38
View File
@@ -29,7 +29,7 @@ inline const char* MyStringGetNextCharPointer(const char *p) throw()
}
*/
int FindCharPosInString(const char *s, char c)
int FindCharPosInString(const char *s, char c) throw()
{
for (const char *p = s;; p++)
{
@@ -41,7 +41,7 @@ int FindCharPosInString(const char *s, char c)
}
}
int FindCharPosInString(const wchar_t *s, wchar_t c)
int FindCharPosInString(const wchar_t *s, wchar_t c) throw()
{
for (const wchar_t *p = s;; p++)
{
@@ -65,7 +65,7 @@ void MyStringUpper_Ascii(wchar_t *s)
}
*/
void MyStringLower_Ascii(wchar_t *s)
void MyStringLower_Ascii(wchar_t *s) throw()
{
for (;;)
{
@@ -91,7 +91,7 @@ void MyStringLower_Ascii(wchar_t *s)
// char * MyStringUpper(char *s) { return CharUpperA(s); }
// char * MyStringLower(char *s) { return CharLowerA(s); }
wchar_t MyCharUpper_WIN(wchar_t c)
wchar_t MyCharUpper_WIN(wchar_t c) throw()
{
wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned)c);
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
@@ -159,7 +159,7 @@ wchar_t * MyStringLower(wchar_t *s)
#endif
bool IsString1PrefixedByString2(const char *s1, const char *s2)
bool IsString1PrefixedByString2(const char *s1, const char *s2) throw()
{
for (;;)
{
@@ -168,7 +168,7 @@ bool IsString1PrefixedByString2(const char *s1, const char *s2)
}
}
bool StringsAreEqualNoCase(const wchar_t *s1, const wchar_t *s2)
bool StringsAreEqualNoCase(const wchar_t *s1, const wchar_t *s2) throw()
{
for (;;)
{
@@ -181,7 +181,7 @@ bool StringsAreEqualNoCase(const wchar_t *s1, const wchar_t *s2)
// ---------- ASCII ----------
bool AString::IsPrefixedBy_Ascii_NoCase(const char *s) const
bool AString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw()
{
const char *s1 = _chars;
for (;;)
@@ -196,7 +196,7 @@ bool AString::IsPrefixedBy_Ascii_NoCase(const char *s) const
}
}
bool UString::IsPrefixedBy_Ascii_NoCase(const char *s) const
bool UString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw()
{
const wchar_t *s1 = _chars;
for (;;)
@@ -205,13 +205,12 @@ bool UString::IsPrefixedBy_Ascii_NoCase(const char *s) const
if (c2 == 0)
return true;
wchar_t c1 = *s1++;
if (MyCharLower_Ascii(c1) !=
MyCharLower_Ascii(c2))
if (MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2))
return false;
}
}
bool StringsAreEqual_Ascii(const wchar_t *u, const char *a)
bool StringsAreEqual_Ascii(const wchar_t *u, const char *a) throw()
{
for (;;)
{
@@ -225,7 +224,7 @@ bool StringsAreEqual_Ascii(const wchar_t *u, const char *a)
}
}
bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2)
bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2) throw()
{
for (;;)
{
@@ -238,7 +237,7 @@ bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2)
}
}
bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2)
bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw()
{
for (;;)
{
@@ -251,20 +250,20 @@ bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2)
}
}
bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2)
bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw()
{
for (;;)
{
wchar_t c1 = *s1++;
char c2 = *s2++;
if (c1 != c2 && (c1 > 0x7F || MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)))
if (c1 != (unsigned char)c2 && (c1 > 0x7F || MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2)))
return false;
if (c1 == 0)
return true;
}
}
bool IsString1PrefixedByString2(const wchar_t *s1, const wchar_t *s2)
bool IsString1PrefixedByString2(const wchar_t *s1, const wchar_t *s2) throw()
{
for (;;)
{
@@ -274,7 +273,7 @@ bool IsString1PrefixedByString2(const wchar_t *s1, const wchar_t *s2)
}
// NTFS order: uses upper case
int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)
int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2) throw()
{
for (;;)
{
@@ -291,7 +290,7 @@ int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)
}
}
int MyStringCompareNoCase_N(const wchar_t *s1, const wchar_t *s2, unsigned num)
int MyStringCompareNoCase_N(const wchar_t *s1, const wchar_t *s2, unsigned num) throw()
{
for (; num != 0; num--)
{
@@ -509,7 +508,7 @@ void AString::SetFrom(const char *s, unsigned len) // no check
_len = len;
}
int AString::Find(const AString &s, unsigned startIndex) const
int AString::Find(const AString &s, unsigned startIndex) const throw()
{
if (s.IsEmpty())
return startIndex;
@@ -525,7 +524,7 @@ int AString::Find(const AString &s, unsigned startIndex) const
return -1;
}
int AString::ReverseFind(char c) const
int AString::ReverseFind(char c) const throw()
{
if (_len == 0)
return -1;
@@ -540,7 +539,7 @@ int AString::ReverseFind(char c) const
}
}
void AString::TrimLeft()
void AString::TrimLeft() throw()
{
const char *p = _chars;
for (;; p++)
@@ -557,7 +556,7 @@ void AString::TrimLeft()
}
}
void AString::TrimRight()
void AString::TrimRight() throw()
{
const char *p = _chars;
int i;
@@ -615,7 +614,7 @@ void AString::Insert(unsigned index, const AString &s)
}
}
void AString::RemoveChar(char ch)
void AString::RemoveChar(char ch) throw()
{
int pos = Find(ch);
if (pos < 0)
@@ -635,7 +634,7 @@ void AString::RemoveChar(char ch)
}
// !!!!!!!!!!!!!!! test it if newChar = '\0'
void AString::Replace(char oldChar, char newChar)
void AString::Replace(char oldChar, char newChar) throw()
{
if (oldChar == newChar)
return; // 0;
@@ -656,7 +655,7 @@ void AString::Replace(char oldChar, char newChar)
void AString::Replace(const AString &oldString, const AString &newString)
{
if (oldString.IsEmpty())
return; // 0;
return; // 0;
if (oldString == newString)
return; // 0;
unsigned oldLen = oldString.Len();
@@ -676,13 +675,13 @@ void AString::Replace(const AString &oldString, const AString &newString)
// return number;
}
void AString::Delete(unsigned index)
void AString::Delete(unsigned index) throw()
{
MoveItems(index, index + 1);
_len--;
}
void AString::Delete(unsigned index, unsigned count)
void AString::Delete(unsigned index, unsigned count) throw()
{
if (index + count > _len)
count = _len - index;
@@ -693,7 +692,7 @@ void AString::Delete(unsigned index, unsigned count)
}
}
void AString::DeleteFrontal(unsigned num)
void AString::DeleteFrontal(unsigned num) throw()
{
if (num != 0)
{
@@ -973,7 +972,7 @@ void UString::AddAsciiStr(const char *s)
int UString::Find(const UString &s, unsigned startIndex) const
int UString::Find(const UString &s, unsigned startIndex) const throw()
{
if (s.IsEmpty())
return startIndex;
@@ -989,7 +988,7 @@ int UString::Find(const UString &s, unsigned startIndex) const
return -1;
}
int UString::ReverseFind(wchar_t c) const
int UString::ReverseFind(wchar_t c) const throw()
{
if (_len == 0)
return -1;
@@ -1004,7 +1003,7 @@ int UString::ReverseFind(wchar_t c) const
}
}
void UString::TrimLeft()
void UString::TrimLeft() throw()
{
const wchar_t *p = _chars;
for (;; p++)
@@ -1021,7 +1020,7 @@ void UString::TrimLeft()
}
}
void UString::TrimRight()
void UString::TrimRight() throw()
{
const wchar_t *p = _chars;
int i;
@@ -1079,7 +1078,7 @@ void UString::Insert(unsigned index, const UString &s)
}
}
void UString::RemoveChar(wchar_t ch)
void UString::RemoveChar(wchar_t ch) throw()
{
int pos = Find(ch);
if (pos < 0)
@@ -1099,7 +1098,7 @@ void UString::RemoveChar(wchar_t ch)
}
// !!!!!!!!!!!!!!! test it if newChar = '\0'
void UString::Replace(wchar_t oldChar, wchar_t newChar)
void UString::Replace(wchar_t oldChar, wchar_t newChar) throw()
{
if (oldChar == newChar)
return; // 0;
@@ -1120,7 +1119,7 @@ void UString::Replace(wchar_t oldChar, wchar_t newChar)
void UString::Replace(const UString &oldString, const UString &newString)
{
if (oldString.IsEmpty())
return; // 0;
return; // 0;
if (oldString == newString)
return; // 0;
unsigned oldLen = oldString.Len();
@@ -1140,13 +1139,13 @@ void UString::Replace(const UString &oldString, const UString &newString)
// return number;
}
void UString::Delete(unsigned index)
void UString::Delete(unsigned index) throw()
{
MoveItems(index, index + 1);
_len--;
}
void UString::Delete(unsigned index, unsigned count)
void UString::Delete(unsigned index, unsigned count) throw()
{
if (index + count > _len)
count = _len - index;
@@ -1157,7 +1156,7 @@ void UString::Delete(unsigned index, unsigned count)
}
}
void UString::DeleteFrontal(unsigned num)
void UString::DeleteFrontal(unsigned num) throw()
{
if (num != 0)
{
+3 -3
View File
@@ -29,7 +29,7 @@ inline char *MyStpCpy(char *dest, const char *src)
{
for (;;)
{
Byte c = *src;
char c = *src;
*dest = c;
if (c == 0)
return dest;
@@ -248,7 +248,7 @@ public:
// int CompareNoCase(const char *s) const { return MyStringCompareNoCase(_chars, s); }
// int CompareNoCase(const AString &s) const { return MyStringCompareNoCase(_chars, s._chars); }
bool IsPrefixedBy(const char *s) const { return IsString1PrefixedByString2(_chars, s); }
bool IsPrefixedBy_Ascii_NoCase(const char *s) const;
bool IsPrefixedBy_Ascii_NoCase(const char *s) const throw();
int Find(char c) const { return FindCharPosInString(_chars, c); }
int Find(char c, unsigned startIndex) const
@@ -413,7 +413,7 @@ public:
// int CompareNoCase(const wchar_t *s) const { return MyStringCompareNoCase(_chars, s); }
// int CompareNoCase(const UString &s) const { return MyStringCompareNoCase(_chars, s._chars); }
bool IsPrefixedBy(const wchar_t *s) const { return IsString1PrefixedByString2(_chars, s); };
bool IsPrefixedBy_Ascii_NoCase(const char *s) const;
bool IsPrefixedBy_Ascii_NoCase(const char *s) const throw();
int Find(wchar_t c) const { return FindCharPosInString(_chars, c); }
int Find(wchar_t c, unsigned startIndex) const
+68 -51
View File
@@ -4,87 +4,104 @@
#ifndef _WIN32
#include <stdlib.h>
#include "MyWindows.h"
#include "Types.h"
#include <malloc.h>
static inline void *AllocateForBSTR(size_t cb) { return ::malloc(cb); }
static inline void FreeForBSTR(void *pv) { ::free(pv);}
static UINT MyStringLen(const wchar_t *s)
{
UINT i;
for (i = 0; s[i] != '\0'; i++);
return i;
}
/* Win32 uses DWORD (32-bit) type to store size of string before (OLECHAR *) string.
We must select CBstrSizeType for another systems (not Win32):
BSTR SysAllocStringByteLen(LPCSTR psz, UINT len)
if (CBstrSizeType is UINT32),
then we support only strings smaller than 4 GB.
Win32 version always has that limitation.
if (CBstrSizeType is UINT),
(UINT can be 16/32/64-bit)
We can support strings larger than 4 GB (if UINT is 64-bit),
but sizeof(UINT) can be different in parts compiled by
different compilers/settings,
and we can't send such BSTR strings between such parts.
*/
typedef UINT32 CBstrSizeType;
// typedef UINT CBstrSizeType;
#define k_BstrSize_Max 0xFFFFFFFF
// #define k_BstrSize_Max UINT_MAX
// #define k_BstrSize_Max ((UINT)(INT)-1)
BSTR SysAllocStringByteLen(LPCSTR s, UINT len)
{
int realLen = len + sizeof(UINT) + sizeof(OLECHAR) + sizeof(OLECHAR);
void *p = AllocateForBSTR(realLen);
if (p == 0)
return 0;
*(UINT *)p = len;
BSTR bstr = (BSTR)((UINT *)p + 1);
if (psz)
{
memcpy(bstr, psz, len);
Byte *pb = ((Byte *)bstr) + len;
for (unsigned i = 0; i < sizeof(OLECHAR) * 2; i++)
pb[i] = 0;
}
/* Original SysAllocStringByteLen in Win32 maybe fills only unaligned null OLECHAR at the end.
We provide also aligned null OLECHAR at the end. */
if (len >= (k_BstrSize_Max - sizeof(OLECHAR) - sizeof(OLECHAR) - sizeof(CBstrSizeType)))
return NULL;
UINT size = (len + sizeof(OLECHAR) + sizeof(OLECHAR) - 1) & ~(sizeof(OLECHAR) - 1);
void *p = AllocateForBSTR(size + sizeof(CBstrSizeType));
if (!p)
return NULL;
*(CBstrSizeType *)p = (CBstrSizeType)len;
BSTR bstr = (BSTR)((CBstrSizeType *)p + 1);
if (s)
memcpy(bstr, s, len);
for (; len < size; len++)
((Byte *)bstr)[len] = 0;
return bstr;
}
BSTR SysAllocStringLen(const OLECHAR *sz, UINT len)
BSTR SysAllocStringLen(const OLECHAR *s, UINT len)
{
int realLen = sizeof(UINT) + len * sizeof(OLECHAR) + sizeof(OLECHAR);
void *p = AllocateForBSTR(realLen);
if (p == 0)
return 0;
*(UINT *)p = len * sizeof(OLECHAR);
BSTR bstr = (BSTR)((UINT *)p + 1);
if (sz)
{
memcpy(bstr, sz, len * sizeof(OLECHAR));
bstr[len] = 0;
}
if (len >= (k_BstrSize_Max - sizeof(OLECHAR) - sizeof(CBstrSizeType)) / sizeof(OLECHAR))
return NULL;
UINT size = len * sizeof(OLECHAR);
void *p = AllocateForBSTR(size + sizeof(CBstrSizeType) + sizeof(OLECHAR));
if (!p)
return NULL;
*(CBstrSizeType *)p = (CBstrSizeType)size;
BSTR bstr = (BSTR)((CBstrSizeType *)p + 1);
if (s)
memcpy(bstr, s, size);
bstr[len] = 0;
return bstr;
}
BSTR SysAllocString(const OLECHAR *sz)
BSTR SysAllocString(const OLECHAR *s)
{
if (sz == 0)
if (!s)
return 0;
UINT strLen = MyStringLen(sz);
UINT len = (strLen + 1) * sizeof(OLECHAR);
void *p = AllocateForBSTR(len + sizeof(UINT));
if (p == 0)
return 0;
*(UINT *)p = strLen * sizeof(OLECHAR);
BSTR bstr = (BSTR)((UINT *)p + 1);
memcpy(bstr, sz, len);
return bstr;
const OLECHAR *s2 = s;
while (*s2 != 0)
s2++;
return SysAllocStringLen(s, (UINT)(s2 - s));
}
void SysFreeString(BSTR bstr)
{
if (bstr != 0)
FreeForBSTR((UINT *)bstr - 1);
if (bstr)
FreeForBSTR((CBstrSizeType *)bstr - 1);
}
UINT SysStringByteLen(BSTR bstr)
{
if (bstr == 0)
if (!bstr)
return 0;
return *((UINT *)bstr - 1);
return *((CBstrSizeType *)bstr - 1);
}
UINT SysStringLen(BSTR bstr)
{
return SysStringByteLen(bstr) / sizeof(OLECHAR);
if (!bstr)
return 0;
return *((CBstrSizeType *)bstr - 1) / sizeof(OLECHAR);
}
HRESULT VariantClear(VARIANTARG *prop)
{
if (prop->vt == VT_BSTR)
@@ -102,7 +119,7 @@ HRESULT VariantCopy(VARIANTARG *dest, const VARIANTARG *src)
{
dest->bstrVal = SysAllocStringByteLen((LPCSTR)src->bstrVal,
SysStringByteLen(src->bstrVal));
if (dest->bstrVal == 0)
if (!dest->bstrVal)
return E_OUTOFMEMORY;
dest->vt = VT_BSTR;
}
+22 -24
View File
@@ -20,7 +20,7 @@ static bool IsSpaceChar(char c)
#define SKIP_SPACES(s) while (IsSpaceChar(*s)) s++;
int CXmlItem::FindProp(const AString &propName) const
int CXmlItem::FindProp(const AString &propName) const throw()
{
FOR_VECTOR (i, Props)
if (Props[i].Name == propName)
@@ -36,12 +36,12 @@ AString CXmlItem::GetPropVal(const AString &propName) const
return AString();
}
bool CXmlItem::IsTagged(const AString &tag) const
bool CXmlItem::IsTagged(const AString &tag) const throw()
{
return (IsTag && Name == tag);
}
int CXmlItem::FindSubTag(const AString &tag) const
int CXmlItem::FindSubTag(const AString &tag) const throw()
{
FOR_VECTOR (i, SubItems)
if (SubItems[i].IsTagged(tag))
@@ -60,7 +60,7 @@ AString CXmlItem::GetSubString() const
return AString();
}
const AString * CXmlItem::GetSubStringPtr() const
const AString * CXmlItem::GetSubStringPtr() const throw()
{
if (SubItems.Size() == 1)
{
@@ -192,19 +192,17 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels)
}
}
static bool SkipHeader(const AString &s, int &pos, const char *startString, const char *endString)
static const char * SkipHeader(const char *s, const char *startString, const char *endString)
{
while (IsSpaceChar(s[pos]))
pos++;
if (IsString1PrefixedByString2(s.Ptr(pos), startString))
SKIP_SPACES(s);
if (IsString1PrefixedByString2(s, startString))
{
const AString es = endString;
pos = s.Find(es, pos);
if (pos < 0)
return false;
pos += es.Len();
s = strstr(s, endString);
if (!s)
return NULL;
s += strlen(endString);
}
return true;
return s;
}
void CXmlItem::AppendTo(AString &s) const
@@ -242,21 +240,21 @@ void CXmlItem::AppendTo(AString &s) const
}
}
bool CXml::Parse(const AString &s)
bool CXml::Parse(const char *s)
{
int pos = 0;
if (!SkipHeader(s, pos, "<?xml", "?>"))
s = SkipHeader(s, "<?xml", "?>"); if (!s) return false;
s = SkipHeader(s, "<!DOCTYPE", ">"); if (!s) return false;
s = Root.ParseItem(s, 1000);
if (!s || !Root.IsTag)
return false;
if (!SkipHeader(s, pos, "<!DOCTYPE", ">"))
return false;
const char *ptr = Root.ParseItem(s.Ptr(pos), 1000);
if (!ptr || !Root.IsTag)
return false;
SKIP_SPACES(ptr);
return *ptr == 0;
SKIP_SPACES(s);
return *s == 0;
}
/*
void CXml::AppendTo(AString &s) const
{
Root.AppendTo(s);
}
*/
+2 -2
View File
@@ -36,8 +36,8 @@ struct CXml
{
CXmlItem Root;
bool Parse(const AString &s);
void AppendTo(AString &s) const;
bool Parse(const char *s);
// void AppendTo(AString &s) const;
};
#endif
+3 -3
View File
@@ -20,7 +20,7 @@ extern int g_CodePage;
CStdInStream g_StdIn(stdin);
bool CStdInStream::Open(LPCTSTR fileName)
bool CStdInStream::Open(LPCTSTR fileName) throw()
{
Close();
_stream = _tfopen(fileName, kFileOpenMode);
@@ -28,7 +28,7 @@ bool CStdInStream::Open(LPCTSTR fileName)
return _streamIsOpen;
}
bool CStdInStream::Close()
bool CStdInStream::Close() throw()
{
if (!_streamIsOpen)
return true;
@@ -80,7 +80,7 @@ void CStdInStream::ReadToString(AString &resultString)
resultString += (char)c;
}
bool CStdInStream::Eof()
bool CStdInStream::Eof() throw()
{
return (feof(_stream) != 0);
}
+16 -30
View File
@@ -18,7 +18,7 @@ extern int g_CodePage;
CStdOutStream g_StdOut(stdout);
CStdOutStream g_StdErr(stderr);
bool CStdOutStream::Open(const char *fileName)
bool CStdOutStream::Open(const char *fileName) throw()
{
Close();
_stream = fopen(fileName, kFileOpenMode);
@@ -26,7 +26,7 @@ bool CStdOutStream::Open(const char *fileName)
return _streamIsOpen;
}
bool CStdOutStream::Close()
bool CStdOutStream::Close() throw()
{
if (!_streamIsOpen)
return true;
@@ -37,28 +37,16 @@ bool CStdOutStream::Close()
return true;
}
bool CStdOutStream::Flush()
bool CStdOutStream::Flush() throw()
{
return (fflush(_stream) == 0);
}
CStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*func)(CStdOutStream &))
{
(*func)(*this);
return *this;
}
CStdOutStream & endl(CStdOutStream & outStream)
CStdOutStream & endl(CStdOutStream & outStream) throw()
{
return outStream << kNewLineChar;
}
CStdOutStream & CStdOutStream::operator<<(const char *s)
{
fputs(s, _stream);
return *this;
}
CStdOutStream & CStdOutStream::operator<<(const wchar_t *s)
{
int codePage = g_CodePage;
@@ -68,12 +56,11 @@ CStdOutStream & CStdOutStream::operator<<(const wchar_t *s)
if (codePage == CP_UTF8)
ConvertUnicodeToUTF8(s, dest);
else
dest = UnicodeStringToMultiByte(s, (UINT)codePage);
*this << (const char *)dest;
return *this;
UnicodeStringToMultiByte2(dest, s, (UINT)codePage);
return operator<<((const char *)dest);
}
void CStdOutStream::PrintUString(const UString &s, AString &temp)
void StdOut_Convert_UString_to_AString(const UString &s, AString &temp)
{
int codePage = g_CodePage;
if (codePage == -1)
@@ -82,37 +69,36 @@ void CStdOutStream::PrintUString(const UString &s, AString &temp)
ConvertUnicodeToUTF8(s, temp);
else
UnicodeStringToMultiByte2(temp, s, (UINT)codePage);
}
void CStdOutStream::PrintUString(const UString &s, AString &temp)
{
StdOut_Convert_UString_to_AString(s, temp);
*this << (const char *)temp;
}
CStdOutStream & CStdOutStream::operator<<(char c)
{
fputc(c, _stream);
return *this;
}
CStdOutStream & CStdOutStream::operator<<(Int32 number)
CStdOutStream & CStdOutStream::operator<<(Int32 number) throw()
{
char s[32];
ConvertInt64ToString(number, s);
return operator<<(s);
}
CStdOutStream & CStdOutStream::operator<<(Int64 number)
CStdOutStream & CStdOutStream::operator<<(Int64 number) throw()
{
char s[32];
ConvertInt64ToString(number, s);
return operator<<(s);
}
CStdOutStream & CStdOutStream::operator<<(UInt32 number)
CStdOutStream & CStdOutStream::operator<<(UInt32 number) throw()
{
char s[16];
ConvertUInt32ToString(number, s);
return operator<<(s);
}
CStdOutStream & CStdOutStream::operator<<(UInt64 number)
CStdOutStream & CStdOutStream::operator<<(UInt64 number) throw()
{
char s[32];
ConvertUInt64ToString(number, s);
+23 -3
View File
@@ -17,14 +17,32 @@ public:
CStdOutStream(FILE *stream): _stream(stream), _streamIsOpen(false) {};
~CStdOutStream() { Close(); }
// void AttachStdStream(FILE *stream) { _stream = stream; _streamIsOpen = false; }
// bool IsDefined() const { return _stream != NULL; }
operator FILE *() { return _stream; }
bool Open(const char *fileName) throw();
bool Close() throw();
bool Flush() throw();
CStdOutStream & operator<<(CStdOutStream & (* func)(CStdOutStream &));
CStdOutStream & operator<<(const char *s) throw();
CStdOutStream & operator<<(char c) throw();
CStdOutStream & operator<<(CStdOutStream & (* func)(CStdOutStream &))
{
(*func)(*this);
return *this;
}
CStdOutStream & operator<<(const char *s) throw()
{
fputs(s, _stream);
return *this;
}
CStdOutStream & operator<<(char c) throw()
{
fputc(c, _stream);
return *this;
}
CStdOutStream & operator<<(Int32 number) throw();
CStdOutStream & operator<<(Int64 number) throw();
CStdOutStream & operator<<(UInt32 number) throw();
@@ -39,4 +57,6 @@ CStdOutStream & endl(CStdOutStream & outStream) throw();
extern CStdOutStream g_StdOut;
extern CStdOutStream g_StdErr;
void StdOut_Convert_UString_to_AString(const UString &s, AString &temp);
#endif
+8 -7
View File
@@ -5,10 +5,11 @@
#include "StringToInt.h"
static const UInt32 k_UInt32_max = 0xFFFFFFFF;
static const UInt64 k_UInt64_max = 0xFFFFFFFFFFFFFFFF;
static const UInt64 k_UInt64_max = UINT64_CONST(0xFFFFFFFFFFFFFFFF);
// static const UInt64 k_UInt64_max = (UInt64)(Int64)-1;
#define CONVERT_STRING_TO_UINT_FUNC(uintType, charType) \
uintType ConvertStringTo ## uintType(const charType *s, const charType **end) { \
uintType ConvertStringTo ## uintType(const charType *s, const charType **end) throw() { \
if (end) *end = s; \
uintType res = 0; \
for (;; s++) { \
@@ -25,7 +26,7 @@ CONVERT_STRING_TO_UINT_FUNC(UInt32, wchar_t)
CONVERT_STRING_TO_UINT_FUNC(UInt64, char)
CONVERT_STRING_TO_UINT_FUNC(UInt64, wchar_t)
Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end)
Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw()
{
if (end)
*end = s;
@@ -50,7 +51,7 @@ Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end)
return (Int32)res;
}
UInt32 ConvertOctStringToUInt32(const char *s, const char **end)
UInt32 ConvertOctStringToUInt32(const char *s, const char **end) throw()
{
if (end)
*end = s;
@@ -71,7 +72,7 @@ UInt32 ConvertOctStringToUInt32(const char *s, const char **end)
}
}
UInt64 ConvertOctStringToUInt64(const char *s, const char **end)
UInt64 ConvertOctStringToUInt64(const char *s, const char **end) throw()
{
if (end)
*end = s;
@@ -92,7 +93,7 @@ UInt64 ConvertOctStringToUInt64(const char *s, const char **end)
}
}
UInt32 ConvertHexStringToUInt32(const char *s, const char **end)
UInt32 ConvertHexStringToUInt32(const char *s, const char **end) throw()
{
if (end)
*end = s;
@@ -117,7 +118,7 @@ UInt32 ConvertHexStringToUInt32(const char *s, const char **end)
}
}
UInt64 ConvertHexStringToUInt64(const char *s, const char **end)
UInt64 ConvertHexStringToUInt64(const char *s, const char **end) throw()
{
if (end)
*end = s;
+1 -1
View File
@@ -107,7 +107,7 @@ bool GetTextConfig(const AString &s, CObjectVector<CTextConfigPair> &pairs)
return true;
}
int FindTextConfigItem(const CObjectVector<CTextConfigPair> &pairs, const UString &id)
int FindTextConfigItem(const CObjectVector<CTextConfigPair> &pairs, const UString &id) throw()
{
FOR_VECTOR (i, pairs)
if (pairs[i].ID == id)
+1 -1
View File
@@ -7,7 +7,7 @@
static const Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
bool CheckUTF8(const char *src)
bool CheckUTF8(const char *src) throw()
{
for (;;)
{
+1 -1
View File
@@ -33,7 +33,7 @@ bool IsPath1PrefixedByPath2(const wchar_t *s1, const wchar_t *s2)
}
}
int CompareFileNames(const wchar_t *s1, const wchar_t *s2)
int CompareFileNames(const wchar_t *s1, const wchar_t *s2) STRING_UNICODE_THROW
{
if (g_CaseSensitive)
return wcscmp(s1, s2);