aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/charset.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-11-09 16:43:57 -0500
committerJack Lloyd <[email protected]>2017-11-09 16:43:57 -0500
commitb08f26d3658db3213d98932cbc6dd3e6efdc8b85 (patch)
treec1cfb432aaa1625d6a1cfff7bf7487b75dcd0286 /src/lib/utils/charset.cpp
parent54baf3a3d3ee070e3740859298f92d69b042c9c6 (diff)
Remove use of transcode
Diffstat (limited to 'src/lib/utils/charset.cpp')
-rw-r--r--src/lib/utils/charset.cpp58
1 files changed, 30 insertions, 28 deletions
diff --git a/src/lib/utils/charset.cpp b/src/lib/utils/charset.cpp
index dadee8f78..ca32c652d 100644
--- a/src/lib/utils/charset.cpp
+++ b/src/lib/utils/charset.cpp
@@ -92,34 +92,6 @@ std::string ucs4_to_utf8(const uint8_t ucs4[], size_t len)
return s;
}
-namespace Charset {
-
-namespace {
-
-/*
-* Convert from UCS-2 to ISO 8859-1
-*/
-std::string ucs2_to_latin1(const std::string& ucs2)
- {
- if(ucs2.size() % 2 == 1)
- throw Decoding_Error("UCS-2 string has an odd number of bytes");
-
- std::string latin1;
-
- for(size_t i = 0; i != ucs2.size(); i += 2)
- {
- const uint8_t c1 = ucs2[i];
- const uint8_t c2 = ucs2[i+1];
-
- if(c1 != 0)
- throw Decoding_Error("UCS-2 has non-Latin1 characters");
-
- latin1 += static_cast<char>(c2);
- }
-
- return latin1;
- }
-
/*
* Convert from UTF-8 to ISO 8859-1
*/
@@ -133,7 +105,9 @@ std::string utf8_to_latin1(const std::string& utf8)
const uint8_t c1 = static_cast<uint8_t>(utf8[position++]);
if(c1 <= 0x7F)
+ {
iso8859 += static_cast<char>(c1);
+ }
else if(c1 >= 0xC0 && c1 <= 0xC7)
{
if(position == utf8.size())
@@ -154,6 +128,34 @@ std::string utf8_to_latin1(const std::string& utf8)
return iso8859;
}
+namespace Charset {
+
+namespace {
+
+/*
+* Convert from UCS-2 to ISO 8859-1
+*/
+std::string ucs2_to_latin1(const std::string& ucs2)
+ {
+ if(ucs2.size() % 2 == 1)
+ throw Decoding_Error("UCS-2 string has an odd number of bytes");
+
+ std::string latin1;
+
+ for(size_t i = 0; i != ucs2.size(); i += 2)
+ {
+ const uint8_t c1 = ucs2[i];
+ const uint8_t c2 = ucs2[i+1];
+
+ if(c1 != 0)
+ throw Decoding_Error("UCS-2 has non-Latin1 characters");
+
+ latin1 += static_cast<char>(c2);
+ }
+
+ return latin1;
+ }
+
/*
* Convert from ISO 8859-1 to UTF-8
*/