c++ - Printing a UTF-32 character to terminal -


i'm reading user input glfw using callbacks (set using glfwsetcharcallback) according page: http://www.glfw.org/docs/latest/input.html#input_char

the callback function recieves pressed key 32-bit unsigned int. how can convert can print on screen? i've tried both codecvt c++11 , icu library, couldn't print readable characters terminal.

this code of callback function:

void inputmanager::charinputcallback(glfwwindow* window, unsigned int key)     {         uerrorcode errorstatus = u_zero_error; //initialize no error         uconverter *utf32tounicode = ucnv_open("utf-32", &errorstatus); //create converter utf-32 <=> unicode         if(u_failure(errorstatus))             std::cout << u_errorname(errorstatus) << std::endl;         uchar unicode[10] = {0};         ucnv_touchars(utf32tounicode, unicode, 10, (char*)key, 4, &errorstatus); // fails u_illegal_argument_error         if(u_failure(errorstatus))             std::cout << u_errorname(errorstatus) << std::endl;          std::cout << unicode << std::endl;     } 

if nothing input (key), nothing's shown @ all. blank line.

you're calling ucnv_touchars(), converts 8-bit string unicode. need go other way, , convert unicode string 8-bit, such utf-8. use unicodestring class, has constructor taking utf-32, , method toutf8string().


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -