1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-08 10:50:33 +00:00
pdf2htmlEX/src/StringFormatter.cc

31 lines
812 B
C++
Raw Normal View History

2012-12-11 12:17:36 +00:00
#include <cstdarg>
2012-12-11 12:20:52 +00:00
#include <algorithm>
#include <cassert>
2012-12-11 12:17:36 +00:00
#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