GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes
GncTokenizer Class Referenceabstract
Inheritance diagram for GncTokenizer:
GncCsvTokenizer GncDummyTokenizer GncFwTokenizer

Public Member Functions

 GncTokenizer (const GncTokenizer &)=default
 
GncTokenizeroperator= (const GncTokenizer &)=default
 
 GncTokenizer (GncTokenizer &&)=default
 
GncTokenizeroperator= (GncTokenizer &&)=default
 
virtual void load_file (const std::string &path)
 
const std::string & current_file ()
 
void encoding (const std::string &encoding)
 
const std::string & encoding ()
 
virtual int tokenize ()=0
 
const std::vector< StrVec > & get_tokens ()
 

Protected Attributes

std::string m_utf8_contents
 
std::vector< StrVec > m_tokenized_contents
 

Detailed Description

Definition at line 57 of file gnc-tokenizer.hpp.

Member Function Documentation

◆ current_file()

const std::string & GncTokenizer::current_file ( )

Definition at line 99 of file gnc-tokenizer.cpp.

100{
101 return m_imp_file_str;
102}

◆ encoding() [1/2]

const std::string & GncTokenizer::encoding ( )

Definition at line 117 of file gnc-tokenizer.cpp.

118{
119 return m_enc_str;
120}

◆ encoding() [2/2]

void GncTokenizer::encoding ( const std::string &  encoding)

Definition at line 105 of file gnc-tokenizer.cpp.

106{
107 m_enc_str = encoding;
108 m_utf8_contents = boost::locale::conv::to_utf<char>(m_raw_contents, m_enc_str);
109
110 // While we are converting here, let's also normalize line-endings to "\n"
111 // That's what STL expects by default
112 boost::replace_all (m_utf8_contents, "\r\n", "\n");
113 boost::replace_all (m_utf8_contents, "\r", "\n");
114}

◆ get_tokens()

const std::vector< StrVec > & GncTokenizer::get_tokens ( )

Definition at line 124 of file gnc-tokenizer.cpp.

125{
126 return m_tokenized_contents;
127}

◆ load_file()

void GncTokenizer::load_file ( const std::string &  path)
virtual

Definition at line 65 of file gnc-tokenizer.cpp.

66{
67 if (path.empty())
68 return;
69
70 m_imp_file_str = path;
71 char *raw_contents;
72 size_t raw_length;
73 GError *error = nullptr;
74
75 if (!g_file_get_contents(path.c_str(), &raw_contents, &raw_length, &error))
76 {
77 std::string msg {error->message};
78 g_error_free (error);
79 throw std::ifstream::failure {msg};
80 }
81
82 m_raw_contents = raw_contents;
83 g_free(raw_contents);
84
85 // Guess encoding, user can override if needed later on.
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(),
90 NULL);
91 if (guessed_enc)
92 this->encoding(guessed_enc);
93 else
94 m_enc_str.clear();
95
96}

Field Documentation

◆ m_tokenized_contents

std::vector<StrVec> GncTokenizer::m_tokenized_contents
protected

Definition at line 77 of file gnc-tokenizer.hpp.

◆ m_utf8_contents

std::string GncTokenizer::m_utf8_contents
protected

Definition at line 76 of file gnc-tokenizer.hpp.


The documentation for this class was generated from the following files: