From 0799513ea2a53ac91cea33f7a85e48218032ecf6 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Wed, 12 Jun 2024 09:45:30 +0200 Subject: [PATCH] by default use codepage1252 for metadata including non-ascii characters while missing codepage info --- lib/imc_channel.hpp | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/imc_channel.hpp b/lib/imc_channel.hpp index 0c801fb..87a2475 100644 --- a/lib/imc_channel.hpp +++ b/lib/imc_channel.hpp @@ -496,28 +496,35 @@ namespace imc // convert any description, units etc. to UTF-8 (by default) void convert_encoding() { + // actual input codepage + std::string cpn; + if ( !codepage_.empty() ) { // construct iconv-compatible name for respective codepage - std::string cpn = std::string("CP") + codepage_; - - // set up converter - std::string utf = std::string("UTF-8"); - iconverter conv(cpn,utf); - - conv.convert(name_); - conv.convert(comment_); - conv.convert(origin_); - conv.convert(origin_comment_); - conv.convert(text_); - conv.convert(language_code_); - conv.convert(yname_); - conv.convert(yunit_); - conv.convert(xname_); - conv.convert(xunit_); - conv.convert(group_name_); - conv.convert(group_comment_); + cpn = std::string("CP") + codepage_; } + else { + // assume codepage 1252 by default + cpn = std::string("CP1252"); + } + + // set up converter + std::string utf = std::string("UTF-8"); + iconverter conv(cpn,utf); + + conv.convert(name_); + conv.convert(comment_); + conv.convert(origin_); + conv.convert(origin_comment_); + conv.convert(text_); + conv.convert(language_code_); + conv.convert(yname_); + conv.convert(yunit_); + conv.convert(xname_); + conv.convert(xunit_); + conv.convert(group_name_); + conv.convert(group_comment_); } // get info string