Reader/WriterLcf: Use Encoder
MODIFY
src/reader_lcf.cpp
src/reader_lcf.cpp
std::string LcfReader::error_str;
-LcfReader::LcfReader(std::istream& filestream, std::string encoding) :
- encoding(encoding),
- stream(filestream)
+LcfReader::LcfReader(std::istream& filestream, std::string encoding)
+ : stream(filestream)
+ , encoder(std::move(encoding))
{
}
@@ -271,7 +271,11 @@ const std::string& LcfReader::GetError() {
}
std::string LcfReader::Encode(const std::string& str_to_encode) {
- return ReaderUtil::Recode(str_to_encode, encoding, "UTF-8");
+#ifdef LCF_SUPPORT_ICU
+ return encoder.Encode(str_to_encode);
+#else
+ return ReaderUtil::Recode(str_to_encode, encoder.GetEncoding(), "UTF-8");
+#endif
}
int LcfReader::IntSize(unsigned int x) {

MODIFY
src/reader_lcf.h
src/reader_lcf.h
#include <stdint.h>
#include "lcf_options.h"
#include "reader_util.h"
+#include "encoder.h"
/*
* Calls SkipDebug() instead of Skip() for debug builds.
@@ -213,12 +214,12 @@ public:
static int IntSize(unsigned int x);
private:
- /** Name of the encoding. */
- std::string encoding;
/** File-stream managed by this Reader. */
std::istream& stream;
/** Contains the last set error. */
static std::string error_str;
+ /** The internal Encoder */
+ Encoder encoder;
/**
* Converts a 16bit signed integer to/from little-endian.

MODIFY
src/writer_lcf.cpp
src/writer_lcf.cpp
#include "writer_lcf.h"
-LcfWriter::LcfWriter(std::ostream& filestream, std::string encoding) :
- encoding(encoding),
- stream(filestream)
+LcfWriter::LcfWriter(std::ostream& filestream, std::string encoding)
+ : stream(filestream)
+ , encoder(std::move(encoding))
{
}
@@ -130,7 +130,11 @@ bool LcfWriter::IsOk() const {
}
std::string LcfWriter::Decode(const std::string& str_to_encode) {
- return ReaderUtil::Recode(str_to_encode, "UTF-8", encoding);
+#ifdef LCF_SUPPORT_ICU
+ return encoder.Decode(str_to_encode);
+#else
+ return ReaderUtil::Recode(str_to_encode, "UTF-8", encoder.GetEncoding());
+#endif
}
#ifdef WORDS_BIGENDIAN

MODIFY
src/writer_lcf.h
src/writer_lcf.h
#include <stdint.h>
#include "lcf_options.h"
#include "reader_util.h"
+#include "encoder.h"
/**
* LcfWriter class.
@@ -104,10 +105,10 @@ public:
std::string Decode(const std::string& str_to_encode);
private:
- /** Name of the encoding. */
- std::string encoding;
/** File-stream managed by this Writer. */
std::ostream& stream;
+ /** Encoder object */
+ Encoder encoder;
/**
* Converts a 16bit signed integer to/from little-endian.

Reader/WriterLcf: Use Encoder