Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move the ConversionError class
  • Loading branch information
mniip committed May 1, 2018
1 parent a121c62 commit ced7b0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/common/String.cpp
Expand Up @@ -5,7 +5,7 @@

#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;
ss << "Could not convert sequence to UTF-8:";
Expand Down Expand Up @@ -77,7 +77,7 @@ ByteString String::ToUtf8() const
}
else if(result == std::codecvt_base::error)
{
throw ByteString::ConversionError(true);
throw ConversionError(true);
}
else if(result == std::codecvt_base::partial)
{
Expand Down
17 changes: 9 additions & 8 deletions src/common/String.h
Expand Up @@ -99,14 +99,6 @@ class ByteString : public std::basic_string<char>

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;
inline String FromAscii() const;

Expand Down Expand Up @@ -243,4 +235,13 @@ inline ByteString String::ToAscii() const
destination[i] = ByteString::value_type(operator[](i));
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

0 comments on commit ced7b0c

Please sign in to comment.