I have a simple code test for boost from_utf function :
#include <boost/locale.hpp>
#include <iostream>
#include <ctime>
int main()
{
using namespace boost::locale;
using namespace std;
generator gen;
locale loc=gen("");
// Create system default locale
locale::global(loc);
// Make it system global
cout.imbue(loc);
// Set as default locale for output
cout <<format("Today {1,date} at {1,time} we had run our first localization example") % time(0)
<<endl;
cout<<"This is how we show numbers in this locale "<<as::number << 103.34 <<endl;
cout<<"This is how we show currency in this locale "<<as::currency << 103.34 <<endl;
cout<<"This is typical date in the locale "<<as::date << std::time(0) <<endl;
cout<<"This is typical time in the locale "<<as::time << std::time(0) <<endl;
cout<<"This is upper case "<<to_upper("Hello World!")<<endl;
cout<<"This is lower case "<<to_lower("Hello World!")<<endl;
cout<<"This is title case "<<to_title("Hello World!")<<endl;
cout<<"This is fold case "<<fold_case("Hello World!")<<endl;
std::string my_string = "aeiou";
try
{
my_string = conv::from_utf(my_string,"Latin1");
cout<<"This is conversion from utf8 from latin "<< my_string <<endl;
my_string = conv::to_utf<char>(my_string,"Latin1");
cout<<"This is conversion to utf8 from latin "<< my_string <<endl;
}
catch(conv::conversion_error e)
{
std::cout << "Error !" << std::endl;
}
cout<<"end!"<<endl;
}
I have a simple CMakeFiles :
cmake_minimum_required(VERSION 3.17)
project(Lesson01)
set(CMAKE_CXX_STANDARD 14)
SET(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.75.0 COMPONENTS locale REQUIRED)
add_executable(Lesson01 main.cpp)
target_link_libraries(Lesson01
PUBLIC
Boost::locale
)
I tried to execute this code with mingw and visual studio.
Output from mingw :
This is how we show numbers in this locale 103,34
This is how we show currency in this locale 103,34 Ôé¼
This is typical date in the locale 16/12/2020
This is typical time in the locale 12:07:54
This is upper case HELLO WORLD!
This is lower case hello world!
This is title case Hello World!
This is fold case hello world!
This is conversion from utf8 from latin aeiou
This is conversion to utf8 from latin aeiou
end!
Output from mvsc 2019 :
Today 16/12/2020 at 12:08:12 we had run our first localization example
This is how we show numbers in this locale 103,34
This is how we show currency in this locale 103,34 Ôé¼
This is typical date in the locale 16/12/2020
This is typical time in the locale 12:08:12
This is upper case HELLO WORLD!
This is lower case hello world!
This is title case Hello World!
This is fold case hello world!
I have no error message but apparently, the function From_utf crash. In debug, with gdb, I have the following message :
gdb: unknown target exception 0xe06d7363 at 0x7ffcd6aa96c9
Thread 1 received signal ?, Unknown signal.
0x00007ffcd6aa96c9 in RaiseException () from C:\Windows\System32\KernelBase.dll
Any idea ?
User contributions licensed under CC BY-SA 3.0