diff options
| author | Walker Thompson <walker.thompson@urz.uni-heidelberg.de> | 2026-01-27 17:28:59 +0000 |
|---|---|---|
| committer | Walker Thompson <walker.thompson@urz.uni-heidelberg.de> | 2026-01-27 19:39:34 +0000 |
| commit | 3d7ab959fb8fe8aec889650b20693ff88907f799 (patch) | |
| tree | f43d53fe15dffd0d54c87d03aa018a8ff2588c00 /funcs.cpp | |
| parent | a2d7ebcdc396fcaa505251dd1625df34fdd00771 (diff) | |
Fix crash with non-ASCII filenames; change CSV to TSV
Diffstat (limited to 'funcs.cpp')
| -rw-r--r-- | funcs.cpp | 37 |
1 files changed, 20 insertions, 17 deletions
@@ -1,4 +1,5 @@ #include "transcode.h" +#include <codecvt> string random_anum_string(int len) { @@ -12,7 +13,7 @@ string random_anum_string(int len) return alphan.substr(0, len); } -bool to_bool(const wstring& s) +bool to_bool(const string& s) { return s != "0"; } @@ -23,7 +24,7 @@ void uniq(vector <wstring>& vec) vec.erase(unique(vec.begin(), vec.end()), vec.end()); } -inline wstring& wtrim(wstring& s, const wchar_t* t = L" \t\n\r\f\v") +inline string& trim(string& s, const char *t = " \t\n\r\f\v") { s.erase(s.find_last_not_of(t) + 1); s.erase(0, s.find_first_not_of(t)); @@ -31,21 +32,21 @@ inline wstring& wtrim(wstring& s, const wchar_t* t = L" \t\n\r\f\v") } void read_config_file(const char* configfile, - map<wstring, wstring>& config_options) + map<string, string>& config_options) { - wifstream config(configfile); + ifstream config(configfile); if (!config.is_open()) return; - wstring line; + string line; while(getline(config, line)) { - wistringstream config_line(line); - wstring key; - if(getline(config_line, key, L'=')) { - wtrim(key); - wstring value; + istringstream config_line(line); + string key; + if(getline(config_line, key, '=')) { + trim(key); + string value; if(getline(config_line, value)) { - wtrim(value); + trim(value); config_options.insert({key, value}); } } @@ -55,13 +56,15 @@ void read_config_file(const char* configfile, } void write_config_file(const char* configfile, - map<wstring, wstring>& config_options) + map<string, string>& config_options) { - wofstream config(configfile); + ofstream config(configfile); for (auto const& config_option: config_options) { - config << config_option.first << " = " - << config_option.second << endl; + string key = config_option.first; + string val = config_option.second; + + config << key << " = " << val << endl; } config.close(); @@ -138,7 +141,7 @@ void get_default_pfont(wstring& default_pfont, const char* styles_xmlfile) } -void update_default_pfont(const char * styles_xmlfile, wstring& targ_font, +void update_default_pfont(const char * styles_xmlfile, const wstring& targ_font, const vector<wstring>& doc_fonts) { xml_document styles_xmldoc; @@ -181,7 +184,7 @@ void detect_fonts(const char* xmlfile, vector<wstring>& doc_fonts, uniq(doc_fonts); } -void process_xml(const char * xmlfile, wstring& targ_font, +void process_xml(const char * xmlfile, const wstring& targ_font, const vector<wstring>& doc_fonts, const vector<wstring>& doc_encs, map<wstring, vector<wstring>>& char_map, vector<wstring>& utf_chars, const wstring& default_font, bool do_greek) |
