36 original_encoding(enc)
50 original_encoding(enc)
53 in.open(fname.
CStr());
56 std::filebuf *pbuf = in.rdbuf();
57 size_t size = size_t(pbuf->pubseekoff(0, std::ios::end, std::ios::in));
58 pbuf->pubseekpos(0, std::ios::in);
61 size_t wsize = size /
sizeof(char32_t);
62 std::vector<char32_t> buffer(wsize + 1);
63 pbuf->sgetn((
char*)&(buffer.front()), size);
64 buffer[wsize] = U
'\0';
65 text = &(buffer.front());
69 std::vector<char> buffer(size + 1);
70 pbuf->sgetn(&(buffer.front()), size);
72 text = &(buffer.front());
88 out.open(fname.
CStr());
113 out.open(fname.
CStr());
118 original_encoding = enc;
136 out.open(filename.
CStr());
158 std::set<String> words;
183 std::map<String, int> occs;
194 std::map<int, String> words;
195 for (std::pair<const String, int>&p : occs)
197 words[p.second] = p.first;
size_t Size() const noexcept
Returns the length of the string.
const char * CStr() const
Conversion to UTF8 cstring.
Encoding
Allowed text encoding.
void Save()
Overwrites the loaded file.
A UTF32 character string class.
TextFile(Encoding enc=Encoding::UTF_8)
Blank constructor.
const char * CStr() const noexcept
Conversion to UTF8 cstring.
A convenience class for file paths.
std::vector< String > SplitText() const
Extract words.
const char32_t * CWStr() const noexcept
Conversion to wide cstring.
std::set< String > ExtractWords(bool case_sensitive=false) const
Extract unique words.
A character string class.
std::map< int, String > ExtractWordsByFrequency(bool case_sensitive=false) const
Extract unique words sorted by frequency.