mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-10-06 12:01:39 +00:00
29 lines
772 B
C++
29 lines
772 B
C++
|
#include <cstdarg>
|
||
|
|
||
|
#include "StringFormatter.h"
|
||
|
|
||
|
namespace pdf2htmlEX {
|
||
|
|
||
|
StringFormatter::GuardedPointer StringFormatter::operator () (const char * format, ...)
|
||
|
{
|
||
|
assert((buf_cnt == 0) && "StringFormatter: buffer is reused!");
|
||
|
|
||
|
va_list vlist;
|
||
|
va_start(vlist, format);
|
||
|
int l = vsnprintf(&buf.front(), buf.capacity(), format, vlist);
|
||
|
va_end(vlist);
|
||
|
if(l >= (int)buf.capacity())
|
||
|
{
|
||
|
buf.reserve(std::max<long>((long)(l+1), (long)buf.capacity() * 2));
|
||
|
va_start(vlist, format);
|
||
|
l = vsnprintf(&buf.front(), buf.capacity(), format, vlist);
|
||
|
va_end(vlist);
|
||
|
}
|
||
|
assert(l >= 0); // we should fail when vsnprintf fail
|
||
|
assert(l < (int)buf.capacity());
|
||
|
return GuardedPointer(this);
|
||
|
}
|
||
|
|
||
|
} //namespace pdf2htmlEX
|
||
|
|