38#include <boost/locale.hpp>
39#include <boost/algorithm/string.hpp>
41#include <go-glib-extras.h>
43#include <glib/gstdio.h>
47 std::unique_ptr<GncTokenizer> tok(
nullptr);
50 case GncImpFileFormat::CSV:
53 case GncImpFileFormat::FIXED_WIDTH:
65GncTokenizer::load_file(
const std::string& path)
70 m_imp_file_str = path;
73 GError *error =
nullptr;
75 if (!g_file_get_contents(path.c_str(), &raw_contents, &raw_length, &error))
77 std::string msg {error->message};
79 throw std::ifstream::failure {msg};
82 m_raw_contents = raw_contents;
86 const char *guessed_enc = NULL;
87 guessed_enc = go_guess_encoding (m_raw_contents.c_str(),
88 m_raw_contents.length(),
89 m_enc_str.empty() ?
"UTF-8" : m_enc_str.c_str(),
92 this->encoding(guessed_enc);
99GncTokenizer::current_file()
101 return m_imp_file_str;
105GncTokenizer::encoding(
const std::string& encoding)
107 m_enc_str = encoding;
108 m_utf8_contents = boost::locale::conv::to_utf<char>(m_raw_contents, m_enc_str);
112 boost::replace_all (m_utf8_contents,
"\r\n",
"\n");
113 boost::replace_all (m_utf8_contents,
"\r",
"\n");
117GncTokenizer::encoding()
123const std::vector<StrVec>&
124GncTokenizer::get_tokens()
126 return m_tokenized_contents;
Class to convert a csv file into vector of string vectors.
Dummy converter class to convert a file into vector of string vectors.
Class convert a file with fixed with delimited contents into vector of string vectors.
Class convert a file into vector of string vectors.
GncImpFileFormat
Enumeration for file formats supported by this importer.