//--------------------------------------------------------------------------- // tTJSNarrowStringHolder //--------------------------------------------------------------------------- tTJSNarrowStringHolder::tTJSNarrowStringHolder(const wchar_t * wide) { int n; if(!wide) n = -1; else n = TJS_wcstombs(NULL, wide, 0); if( n == -1 ) { Buf = TJS_N(""); Allocated = false; return; } Buf = new tjs_nchar[n+1]; Allocated = true; Buf[TJS_wcstombs(Buf, wide, n)] = 0; }
//--------------------------------------------------------------------------- void tTJSString::ToNarrowStr(tjs_nchar *dest, tjs_int destmaxlen) const { // dest must be an array of char, its size must be at least destmaxlen+1 dest[TJS_wcstombs(dest, c_str(), destmaxlen)] = 0; }
//--------------------------------------------------------------------------- tjs_int tTJSString::GetNarrowStrLen() const { // note that this function will return -1 when there are invalid chars in string. if(!Ptr) return 0; return TJS_wcstombs(NULL, c_str(), 0); }