28 WCHAR *auxSrc =
new WCHAR[s*2];
30 for (i=0, j=0; i<s && src[i]; i++) {
34 wchar_t w=src[i]-0x10000;
35 auxSrc[j++] = (w >> 10) + 0xD800;
36 auxSrc[j++] = (w & 0x3FF)+0xDC00;
40 size = WideCharToMultiByte(CP_ACP, 0, auxSrc, len, 0, 0, 0, 0);
41 dst =
new char[size + (len != (size_t)-1)];
42 size = WideCharToMultiByte(CP_ACP, 0, auxSrc, len, dst, size, 0, 0);
45 size = WideCharToMultiByte(CP_ACP, 0, src,
static_cast<int>(len), 0, 0, 0, 0);
46 dst =
new char[size + (len != (size_t)-1)];
47 size = WideCharToMultiByte(CP_ACP, 0, src,
static_cast<int>(len), dst,
static_cast<int>(size), 0, 0);
49 if (len != (
size_t)-1)
59 size_t size = MultiByteToWideChar(CP_ACP, 0, src,
static_cast<int>(len), 0, 0);
62 WCHAR* auxDst =
new WCHAR[size + (len != (size_t)-1)];
63 size = MultiByteToWideChar(CP_ACP, 0, src, len, auxDst, size);
64 if (len != (
size_t)-1)
68 dst =
new wchar_t[size + (len != (size_t)-1)];
70 for (i=0, j=0; i<size && auxDst[i]; i++) {
71 if (auxDst[i]<0xD800 || auxDst[i]>0xDFFF)
74 dst[j++] = 0x10000 + (auxDst[i] - 0xD800) <<10 + (auxDst[i+1] - 0xDC00);
82 dst =
new wchar_t[size + (len != (size_t)-1)];
83 size = MultiByteToWideChar(CP_ACP, 0, src,
static_cast<int>(len), dst,
static_cast<int>(size));
84 if (len != (
size_t)-1)
92 size_t size = MultiByteToWideChar(CP_ACP, 0, src, -1, 0, 0);
93 wchar_t* pWide = (
wchar_t*)
alloca(
sizeof(
wchar_t)*(size+1));
94 size = MultiByteToWideChar(CP_ACP, 0, src, -1, pWide,
static_cast<int>(size));
96 return ::SysAllocString(pWide);
103char* TUString::ChangeToCopy()
106 const char * src = 0;
129 dst =
ConvertWtoA(GetOWLString().c_str(), GetOWLString().length());
131 src = GetOWLString().c_str();
132 len = GetOWLString().length();
139 dst =
new char[len+1];
140 memcpy(dst, src, len+1);
151wchar_t* TUString::ChangeToWCopy()
154 const wchar_t* src = 0;
178 src = GetOWLString().c_str();
179 len = GetOWLString().length();
181 dst =
ConvertAtoW(GetOWLString().c_str(), GetOWLString().length());
185 dst =
new wchar_t[len+1];
186 memcpy(dst, src, (len+1) *
sizeof(
wchar_t));
223 CHECK(!
"Unexpected Kind of TUString");
238inline TUString::TUString(
const char & str)
240 Lang(0), Kind(isConst), RefCnt(1), Const(&str)
245inline TUString::TUString(
char& str)
247 Lang(0),Kind(isCopy), RefCnt(1)
249 Copy =
new char[strlen(&str)+1];
255inline TUString::TUString(
const wchar_t& str)
257 Lang(0), Kind(isWConst), RefCnt(1), WConst(&str)
262inline TUString::TUString(
wchar_t& str)
264 Lang(0), Kind(isWCopy), RefCnt(1)
266 WCopy =
new wchar_t[
::wcslen(&str)+1];
271inline TUString::TUString(BSTR str,
bool loan,
TLangId lang)
274 Kind(loan ? isExtBstr : isBstr),
275 RefCnt(
int16(loan ? 2 : 1)),
284 Kind(loan ? isExtBstr : isBstr),
285 RefCnt(
int16(loan ? 2 : 1)),
286 Bstr(str.operator BSTR())
294inline TUString::TUString(
const tstring& str)
296 Lang(0), Kind(isString), RefCnt(1)
309 return str ?
new TUString(*str) : &++Null;
315 return str ?
new TUString(*str) : &++Null;
321 return str ?
new TUString(*str) : &++Null;
327 return str ?
new TUString(*str) : &++Null;
334 return new TUString(str, loan, lang);
343 return Create(str.operator BSTR(), loan, lang);
349 return str.length() ?
new TUString(str) : &++Null;
359 if (RefCnt == 1 && Kind != isNull && Kind != isExtBstr)
371 if (s.length() && RefCnt == 1 && Kind != isNull && Kind != isExtBstr)
388 if (s && *s && RefCnt == 1 && Kind != isNull && Kind != isExtBstr) {
403 if (s && *s && RefCnt == 1 && Kind != isNull && Kind != isExtBstr) {
406 Copy =
new char[strlen(s)+1];
419 if (s && *s && RefCnt == 1 && Kind != isNull && Kind != isExtBstr) {
434 if (s && *s && RefCnt == 1 && Kind != isNull && Kind != isExtBstr) {
450 if (RefCnt==1 && Kind != isNull && Kind != isExtBstr) {
462 return Create(str,
false, lang);
469TUString::operator
const char *()
const
472 case isNull:
return 0;
473 case isConst:
return Const;
474 case isCopy:
return Copy;
476 case isString:
return CONST_CAST(TUString*,
this)->ChangeToCopy();
478 case isString:
return GetOWLString().c_str();
481 case isExtBstr:
return CONST_CAST(TUString*,
this)->ChangeToCopy();
483 case isWCopy:
return CONST_CAST(TUString*,
this)->ChangeToCopy();
490TUString::operator
char*()
492 return ChangeToCopy();
496TUString::operator
const wchar_t*()
const
499 case isNull:
return 0;
500 case isWConst:
return WConst;
501 case isWCopy:
return WCopy;
503 case isExtBstr:
return Bstr;
507 return CONST_CAST(TUString*,
this)->ChangeToWCopy();
508 case isString:
return GetOWLString().c_str();
510 case isString:
return CONST_CAST(TUString*,
this)->ChangeToWCopy();
517TUString::operator
wchar_t*()
519 return ChangeToWCopy();
530 case isNull:
return 0;
531 case isWConst:
return static_cast<int>(
::wcslen(WConst));
532 case isWCopy:
return static_cast<int>(
::wcslen(WCopy));
535 case isConst:
return static_cast<int>(strlen(Const));
536 case isCopy:
return static_cast<int>(strlen(Copy));
537 case isString:
return static_cast<int>(GetOWLString().length());
550 if (Kind != isExtBstr || Bstr != s)
565 if (Kind == isExtBstr && Bstr == s) {
580 case isCopy:
delete[] Copy;
break;
581 case isWCopy:
delete[] WCopy;
break;
583 case isString: GetOWLString().~tstring();
break;
static UINT SysStringLen(BSTR)
static HRESULT SysFreeString(BSTR)
System string (BSTR) encapsulation.
Privately used by TString to manage string pointers This is a reference counted union of various stri...
static BSTR ConvertAtoBSTR(const char *src)
static char * ConvertWtoA(const wchar_t *src, size_t len=(size_t) -1)
static TUString * Create(const char *str)
int Length() const
Return appropriate string length.
TUString * Assign(const TUString &s)
void ReleaseBstr(BSTR s)
Used to unhook if Created with loan==true.
static wchar_t * ConvertAtoW(const char *src, size_t len=(size_t) -1)
void RevokeBstr(BSTR s)
Used to restore if Created with loan==true.
size_t __stdcall wcslen(const wchar_t *str)
wchar_t *__stdcall wcscpy(wchar_t *dst, const wchar_t *src)
Reliable platform independent header for common memory and string functions.
Object Windows Library (OWLNext Core).
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
BSTR SysAllocString(const char *str)
General definitions used by all ObjectWindows programs.
#define CONST_CAST(targetType, object)
Definition of class TString, a flexible universal string envelope class.
Classes for window system structure and type encapsulation.