23#pragma warning (disable : 4996)
27#include <CoreFoundation/CoreFoundation.h>
53Converter& converter ()
55 static Converter instance;
68template <
class TDstChar,
class TSrcChar>
69void StringCopy (TDstChar* dst, int32 dstSize,
const TSrcChar* src, int32 srcSize = -1)
71 int32 count = dstSize;
72 if (srcSize >= 0 && srcSize < dstSize)
74 for (int32 i = 0; i < count; i++)
76 dst[i] = (TDstChar)src[i];
86template <
class TSrcChar>
95 if (srcSize > 0 && length >= srcSize)
106 return StringLength<char16> (thisBuffer,
thisSize);
112 StringCopy<char16, char16> (thisBuffer,
thisSize, src, srcSize);
120 StringCopy<char16, char16> (thisBuffer + length,
thisSize - length, src, srcSize);
127 StringCopy<char16, char16> (dst, dstSize, thisBuffer,
thisSize);
134 StringCopy<char16, char> (thisBuffer,
thisSize, src, srcSize);
141 StringCopy<char, char16> (dst, dstSize, thisBuffer,
thisSize);
149 return swscanf ((
const wchar_t*)thisBuffer, L
"%lf", &value) != -1;
151#elif TARGET_API_MAC_CARBON
152 CFStringRef cfStr = CFStringCreateWithBytes (0, (
const UInt8 *)thisBuffer,
getLength () * 2, kCFStringEncodingUTF16,
false);
155 value = CFStringGetDoubleValue (cfStr);
162 auto str = converter ().to_bytes (thisBuffer);
163 return sscanf (str.data (),
"%lf", &value) == 1;
176 return swprintf ((
wchar_t*)thisBuffer, L
"%.*lf", precision, value) != -1;
179 CFStringRef cfStr = CFStringCreateWithFormat (0, 0, CFSTR(
"%.*lf"), precision, value);
183 CFRange range = {0, CFStringGetLength (cfStr)};
184 CFStringGetBytes (cfStr, range, kCFStringEncodingUTF16, 0,
false, (UInt8*)thisBuffer,
thisSize, 0);
190 auto utf8Buffer =
reinterpret_cast<char*
> (thisBuffer);
194 auto utf16Buffer =
reinterpret_cast<char16*
> (thisBuffer);
195 utf16Buffer[len] = 0;
198 utf16Buffer[len] = utf8Buffer[len];
214 return swscanf ((
const wchar_t*)thisBuffer, L
"%I64d", &value) != -1;
217 CFStringRef cfStr = CFStringCreateWithBytes (0, (
const UInt8 *)thisBuffer,
getLength () * 2, kCFStringEncodingUTF16,
false);
220 value = CFStringGetIntValue (cfStr);
227 auto str = converter ().to_bytes (thisBuffer);
228 return sscanf (str.data (),
"%lld", &value) == 1;
241 return swprintf ((
wchar_t*)thisBuffer, L
"%I64d", value) != -1;
244 CFStringRef cfStr = CFStringCreateWithFormat (0, 0, CFSTR(
"%lld"), value);
248 CFRange range = {0, CFStringGetLength (cfStr)};
249 CFStringGetBytes (cfStr, range, kCFStringEncodingUTF16, 0,
false, (UInt8*)thisBuffer,
thisSize, 0);
255 auto utf8Buffer =
reinterpret_cast<char*
> (thisBuffer);
259 auto utf16Buffer =
reinterpret_cast<char16*
> (thisBuffer);
260 utf16Buffer[len] = 0;
263 utf16Buffer[len] = utf8Buffer[len];
UTF-16 string class without buffer management.
bool printInt(int64 value)
Print integer to string.
bool scanInt(int64 &value) const
Scan integer from string.
UString & append(const char16 *src, int32 srcSize=-1)
Append UTF-16 buffer (srcSize is in code unit (count of char16)).
const UString & toAscii(char *dst, int32 dstSize) const
Copy to ASCII string.
int32 getLength() const
Returns length of string (in code unit).
bool scanFloat(double &value) const
Scan float from string.
const UString & copyTo(char16 *dst, int32 dstSize) const
Copy to UTF-16 buffer (dstSize is in code unit (count of char16)).
UString & fromAscii(const char *src, int32 srcSize=-1)
Copy from ASCII string (srcSize is in code unit (count of char16)).
UString & assign(const char16 *src, int32 srcSize=-1)
Copy from UTF-16 buffer (srcSize is in code unit (count of char16)).
int32 thisSize
size in code unit (not in byte!)
bool printFloat(double value, int32 precision=4)
Print float to string.
int32 StringLength(const TSrcChar *src, int32 srcSize=-1)
Find length of null-terminated string, i.e.
void StringCopy(TDstChar *dst, int32 dstSize, const TSrcChar *src, int32 srcSize=-1)
Copy strings of different character width.