예제 #1
0
//===========================================================================
unsigned StrPrintf (wchar_t * dest, unsigned count, const wchar_t format[], ...) {
    va_list argList;
    va_start(argList, format);
    int result = hsVsnwprintf(dest, count, format, argList);
    va_end(argList);
    return IStrPrintfValidate(dest, count, result);
}
예제 #2
0
bool formatv(std::wstring & out, const wchar_t * fmt, va_list args)
{
#define kBufSz 2048
    
    wchar_t buf[kBufSz];
    wchar_t * pbuf = buf;
    int len = 0;
    int attempts = 0;
    bool success = false;
    const int kMaxAttempts = 40;
    
    do
    {
        int maxlen = kBufSz*attempts+kBufSz-1;
        len = hsVsnwprintf(pbuf,maxlen,fmt,args);
        attempts++;
        success = (len>=0 && len<maxlen);
        if (!success)
        {
            if (pbuf!=buf)
                delete [] pbuf;
            pbuf = new wchar_t[kBufSz+kBufSz*attempts];
        }
    }
    while (!success && attempts<kMaxAttempts);
    
    if (success)
    {
        pbuf[len] = L'\0';
        out = pbuf;
    }
    
    if (success)
    {
        pbuf[len] = L'\0';
        out = pbuf;
    }
    else
    {
        out = L"";
        if ( attempts==kMaxAttempts )
        {
            hsDebugMessage( "xtl::formatv - Max reallocs occurred while formatting wstring. Result is likely truncated!", 0 );
        }
    }
    
    if (pbuf!=buf)
        delete [] pbuf;
    
    return success;
}
예제 #3
0
//===========================================================================
unsigned StrPrintfV (wchar_t * dest, unsigned count, const wchar_t format[], va_list args) {
    int result = hsVsnwprintf(dest, count, format, args);
    return IStrPrintfValidate(dest, count, result);
}