mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-13 11:54:04 +02:00
Move the ConversionError class
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
|
||||||
std::string ByteString::ConversionError::formatError(ByteString::value_type const *at, ByteString::value_type const *upto)
|
ByteString ConversionError::formatError(ByteString::value_type const *at, ByteString::value_type const *upto)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Could not convert sequence to UTF-8:";
|
ss << "Could not convert sequence to UTF-8:";
|
||||||
@@ -77,7 +77,7 @@ ByteString String::ToUtf8() const
|
|||||||
}
|
}
|
||||||
else if(result == std::codecvt_base::error)
|
else if(result == std::codecvt_base::error)
|
||||||
{
|
{
|
||||||
throw ByteString::ConversionError(true);
|
throw ConversionError(true);
|
||||||
}
|
}
|
||||||
else if(result == std::codecvt_base::partial)
|
else if(result == std::codecvt_base::partial)
|
||||||
{
|
{
|
||||||
|
@@ -99,14 +99,6 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class ConversionError : public std::runtime_error
|
|
||||||
{
|
|
||||||
static std::string formatError(value_type const *at, value_type const *upto);
|
|
||||||
public:
|
|
||||||
inline ConversionError(value_type const *at, value_type const *upto): std::runtime_error(formatError(at, upto)) {}
|
|
||||||
inline ConversionError(bool to): std::runtime_error(to ? "Could not convert to UTF-8" : "Could not convert from UTF-8") {}
|
|
||||||
};
|
|
||||||
|
|
||||||
String FromUtf8(bool ignoreError = true) const;
|
String FromUtf8(bool ignoreError = true) const;
|
||||||
inline String FromAscii() const;
|
inline String FromAscii() const;
|
||||||
|
|
||||||
@@ -243,4 +235,13 @@ inline ByteString String::ToAscii() const
|
|||||||
destination[i] = ByteString::value_type(operator[](i));
|
destination[i] = ByteString::value_type(operator[](i));
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ConversionError : public std::runtime_error
|
||||||
|
{
|
||||||
|
static ByteString formatError(ByteString::value_type const *at, ByteString::value_type const *upto);
|
||||||
|
public:
|
||||||
|
inline ConversionError(ByteString::value_type const *at, ByteString::value_type const *upto): std::runtime_error(formatError(at, upto)) {}
|
||||||
|
inline ConversionError(bool to): std::runtime_error(to ? "Could not convert to UTF-8" : "Could not convert from UTF-8") {}
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user