fixes problem whith lexical_cast being locale dependent

This commit is contained in:
Arvid Norberg
2009-01-27 06:17:55 +00:00
parent 6c6af0c0a0
commit 8030454c96
21 changed files with 74 additions and 47 deletions

View File

@@ -39,13 +39,35 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cctype>
#include <algorithm>
#include <iostream>
#include <limits>
#include <boost/optional.hpp>
#include <boost/array.hpp>
#include "libtorrent/assert.hpp"
#include "libtorrent/escape_string.hpp"
namespace libtorrent
{
// lexical_cast's result depends on the locale. We need
// a well defined result
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> to_string(size_type n)
{
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> ret;
char *p = &ret.back();;
*p = '\0';
unsigned_size_type un = n;
if (n < 0) un = -un;
do {
*--p = '0' + un % 10;
un /= 10;
} while (un);
if (n < 0) *--p = '-';
std::memmove(&ret.front(), p, sizeof(ret.elems));
return ret;
}
std::string unescape_string(std::string const& s)
{
std::string ret;