26 #define O_SEQUENTIAL 0
40 if (fh < 0)
return false;
61 if (fh < 0)
return false;
81 if (fh < 0)
return false;
102 if (fh < 0)
return false;
136 int len = WideCharToMultiByte(CP_UTF8, 0, utf16, -1,
nullptr, 0,
nullptr,
nullptr);
138 WideCharToMultiByte(CP_UTF8, 0, utf16, -1,
getMData(),
getSize(),
nullptr,
nullptr);
142 if (!
getSize())
return StdStrBuf::wchar_t_holder(
nullptr);
144 int len = MultiByteToWideChar(CP_UTF8, 0,
getData(),
getSize(),
nullptr, 0);
145 wchar_t * p =
new wchar_t[len];
147 return StdStrBuf::wchar_t_holder(p);
151 int len = MultiByteToWideChar(CP_UTF8, 0,
getData(),
getSize(),
nullptr, 0);
153 MultiByteToWideChar(CP_UTF8, 0,
getData(),
getSize(), getMBufPtr<wchar_t>(r), len);
156 StdStrBuf::wchar_t_holder
GetWideChar(
const char * utf8,
bool double_null_terminate)
158 int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1,
nullptr, 0);
159 if (double_null_terminate) ++len;
160 wchar_t * p =
new wchar_t[len];
161 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, p, len);
162 if (double_null_terminate) p[len - 1] = wchar_t(0);
163 return StdStrBuf::wchar_t_holder(p);
167 int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1,
nullptr, 0);
169 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, getMBufPtr<wchar_t>(r), len);
177 va_list args; va_start(args, szFmt);
193 va_list args; va_start(args, szFmt);
200 #ifdef HAVE_VASPRINTF
202 char *pStr;
int iBytes = vasprintf(&pStr, szFmt, args);
203 if (iBytes < 0 || !pStr)
return;
212 #elif defined(HAVE_VSCPRINTF)
216 int iLength = vscprintf(szFmt, args);
219 char *pPos = getMElem<char>(*
this,
iSize - iLength - 1);
220 vsprintf(
getMPtr(iStart), szFmt, args);
231 va_copy(args_copy, args);
235 iBytes = vsnprintf(
getMPtr(iStart),
getLength() - iStart, szFmt, args_copy);
240 while (iBytes < 0 || (
unsigned int)(iBytes) >=
getLength() - iStart);
242 iBytes = strlen(
getMPtr(iStart));
264 char *pData =
const_cast<char *
>(
getData());
265 if (!pData) pData =
const_cast<char *
>(
"");
272 va_list args; va_start(args, szFmt);
286 if (!
getPtr(0) || !szOld)
return 0;
287 if (!szNew) szNew =
"";
289 size_t iOldLen = strlen(szOld), iNewLen = strlen(szNew);
290 if (iOldLen != iNewLen)
294 const char *szPos =
getPtr(iStartSearch);
295 while ((szPos =
SSearch(szPos, szOld)))
297 iResultLen += iNewLen - iOldLen;
303 sResult.
New(iResultLen+1);
304 const char *szRPos =
getPtr(0), *szRNextPos;
305 char *szWrite = sResult.
getMPtr(0);
308 memcpy(szWrite, szRPos, iStartSearch *
sizeof(
char));
309 szRPos += iStartSearch;
310 szWrite += iStartSearch;
312 while ((szRNextPos =
SSearch(szRPos, szOld)))
314 memcpy(szWrite, szRPos, (szRNextPos - szRPos - iOldLen) *
sizeof(
char));
315 szWrite += (szRNextPos - szRPos - iOldLen);
316 memcpy(szWrite, szNew, iNewLen *
sizeof(
char));
320 strcpy(szWrite, szRPos);
321 Take(std::move(sResult));
326 char *szRPos =
getMPtr(iStartSearch);
327 while ((szRPos =
const_cast<char *
>(
SSearch(szRPos, szOld))))
329 memcpy(szRPos - iOldLen, szNew, iOldLen *
sizeof(
char));
341 if (!cNew) cNew =
'_';
343 while ((szPos = strchr(szPos, cOld)))
354 assert(iPos <= iLen);
if (iPos > iLen)
return;
355 size_t iEndLen = strlen(szNewEnd);
356 if (iLen - iPos != iEndLen)
SetLength(iPos + iEndLen);
357 memcpy(
getMPtr(iPos), szNewEnd, iEndLen *
sizeof(
char));
364 if (!strchr(i ? szMidChars : szInitialChars,
getData()[i]))
371 assert(psOutSection);
372 psOutSection->
Clear();
373 const char *szStr =
getData(), *szSepPos;
374 if (!szStr)
return false;
375 while ((szSepPos = strchr(szStr, cSeparator)) && idx) { szStr = szSepPos+1; --idx; }
376 if (idx)
return false;
379 if (szSepPos != szStr) psOutSection->
Copy(szStr, szSepPos - szStr);
388 for (
char *szPos =
getMPtr(0); *szPos; ++szPos)
389 *szPos = tolower(*szPos);
394 if (unicodechar < 0x80)
396 else if (unicodechar < 0x800)
402 else if (unicodechar < 0x10000)
409 else if (unicodechar < 0x110000)
430 enum { GROWSIZE = 20 };
431 for (
size_t i = 0; i <
getSize(); ++i)
433 unsigned char c = *
getPtr(i);
443 if (c == 0x81 || c == 0x8D || c == 0x8F || c == 0x90 || c == 0x9D || c >= 0xA0)
447 *buf.
getMPtr(j++) = (0xC0 | (c >> 6));
448 *buf.
getMPtr(j++) = (0x80 | (c & 0x3F));
453 static const char * extra_chars [] =
457 "\xe2\x82\xac",
nullptr,
"\xe2\x80\x9a",
"\xc6\x92",
"\xe2\x80\x9e",
"\xe2\x80\xa6",
"\xe2\x80\xa0",
"\xe2\x80\xa1",
"\xcb\x86",
"\xe2\x80\xb0",
"\xc5\xa0",
"\xe2\x80\xb9",
"\xc5\x92",
nullptr,
"\xc5\xbd",
nullptr,
458 nullptr,
"\xe2\x80\x98",
"\xe2\x80\x99",
"\xe2\x80\x9c",
"\xe2\x80\x9d",
"\xe2\x80\xa2",
"\xe2\x80\x93",
"\xe2\x80\x94",
"\xcb\x9c",
"\xe2\x84\xa2",
"\xc5\xa1",
"\xe2\x80\xba",
"\xc5\x93",
nullptr,
"\xc5\xbe",
"\xc5\xb8"
460 buf.
Append(extra_chars[c - 0x80]);
461 j += strlen(extra_chars[c - 0x80]);
464 Take(std::move(buf));
473 int32_t iSpaceLeftCount = 0, iLength =
getLength();
474 if (!iLength)
return false;
476 while (iSpaceLeftCount < iLength)
477 if (isspace((
unsigned char)(
unsigned char) szStr[iSpaceLeftCount]))
482 if (iSpaceLeftCount == iLength)
488 int32_t iSpaceRightCount = 0;
489 while (isspace((
unsigned char)szStr[iLength - 1 - iSpaceRightCount])) ++iSpaceRightCount;
491 if (!iSpaceLeftCount && !iSpaceRightCount)
return false;
493 if (!iSpaceLeftCount)
499 memmove(
getMPtr(0), szStr+iSpaceLeftCount, iLength - iSpaceLeftCount - iSpaceRightCount);
500 SetLength(iLength - iSpaceLeftCount - iSpaceRightCount);
505 std::string WStrToString(
wchar_t *ws)
507 int len = WideCharToMultiByte(CP_UTF8, 0, ws, -1,
nullptr, 0,
nullptr,
nullptr);
509 if (len <= 0)
return std::string{};
511 std::string
s(
static_cast<size_t>(len),
'\0');
512 s.resize(WideCharToMultiByte(CP_UTF8, 0, ws, -1, &
s[0],
s.size(),
nullptr,
nullptr) - 1);
StdStrBuf::wchar_t_holder GetWideChar(const char *utf8, bool double_null_terminate=false)
StdBuf GetWideCharBuf(const char *utf8)
const char * SSearch(const char *szString, const char *szIndex)
bool IsValidUtf8(const char *text, int length)
StdIntPackAdapt< T > mkIntPackAdapt(T &rVal)
StdStrBuf FormatString(const char *szFmt,...)
StdStrBuf FormatStringV(const char *szFmt, va_list args)
size_t FileSize(const char *fname)
void SetSize(size_t inSize)
void CompileFunc(class StdCompiler *pComp, int iType=0)
bool SaveToFile(const char *szFile) const
const void * getData() const
bool LoadFromFile(const char *szFile)
virtual void Raw(void *pData, size_t iSize, RawCompileType eType=RCT_Escaped)=0
virtual bool Separator(Sep eSep=SEP_SEP)
void Value(const T &rStruct)
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
virtual bool isDeserializer()
void AppendFormatV(const char *szFmt, va_list args)
void AppendCharacter(uint32_t unicodechar)
void SetLength(size_t iLength)
void CompileFunc(class StdCompiler *pComp, int iRawType=0)
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
void FormatV(const char *szFmt, va_list args)
int Replace(const char *szOld, const char *szNew, size_t iStartSearch=0)
void ReplaceEnd(size_t iPos, const char *szNewEnd)
const char * getData() const
void AppendChar(char cChar)
bool ValidateChars(const char *szInitialChars, const char *szMidChars)
bool LoadFromFile(const char *szFile)
void Append(const char *pnData, size_t iChars)
int ReplaceChar(char cOld, char cNew)
bool SaveToFile(const char *szFile) const
const char * getPtr(size_t i) const
bool GetSection(size_t idx, StdStrBuf *psOutSection, char cSeparator=';') const
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O