blob: 0cf4b3b174758d25374efad8f3cd5163914fb8b9 (
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 "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()));
}
}
}
}
|