blob: a29c88a65cc26f978899a159c435d0d3d88e6f4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#pragma once
#include "coding/coder.hpp"
#include "base/base.hpp"
#include "base/exception.hpp"
#include "std/string.hpp"
template <typename FixedSizeCoderT, typename SrcCharT>
void FixedDstSizeCodeToString(FixedSizeCoderT coder, SrcCharT * pSrc, size_t srcSize, string & dst)
{
dst.resize(1024);
while (true)
{
size_t dstUsed = coder(pSrc, srcSize, &dst[0], dst.size());
if (dstUsed != -1)
{
dst.resize(dstUsed);
return;
}
else
{
// Double dst string size.
try { dst.resize(dst.size() * 2); }
catch (std::exception & e)
{
dst.clear();
MYTHROW(DstOutOfMemoryStringCodingException, (e.what()));
}
}
}
}
|