Hi there,
For some time i was investigating how to use non-ASCII characters in my Mbed code.
I found a working way to output a wide range of special characters and also emojis on the screen attached to my board and also in the serial monitor which is great.
However i am facing another challenge: the user might input location names like “Bad Gottleuba-Berggießhübel” and my code should convert that string to ASCII characters only to generate a portable filename Mbed is happy with.
I used iconv in PHP for such purposes and this PHP code
<?php
echo iconv('UTF-8', 'ASCII//TRANSLIT', "Bad Gottleuba-Berggießhübel\n");
?>
outputs “Bad Gottleuba-Berggiesshubel”, exactly what i would need now in Mbed.
I found iconv.h also exists in C/C++ so came up with this code:
#include <iostream>
#include <fstream>
#include <iconv.h>
int main()
{
char src[] = "Bad Gottleuba-Berggießhübel";
char dst[100];
size_t srclen = 50;
size_t dstlen = 100;
fprintf(stderr,"in: %s\n",src);
char * pIn = src;
char * pOut = ( char*)dst;
iconv_t conv = iconv_open("ASCII//TRANSLIT","UTF-8");
iconv(conv, &pIn, &srclen, &pOut, &dstlen);
iconv_close(conv);
fprintf(stderr,"out: %s\n",dst);
}
Above code works on onlinegdb.com though it outputs “Bad Gottleuba-Berggiessh?bel” (notice the ü character has failed to get converted unlike in PHP – could actually remove ? characters after iconv to get acceptable filenames)
However the challenge is that in Mbed OS i can not make iconv.h work at all.
- Using ARMC 6.15 compiler it does not even compile, i get:
error: use of undeclared identifier ‘iconv_open’
- Using ARM_GCC compiler (8 2018-q4-major) it compiles 100%, but then it does not link by telling:
undefined reference to `iconv_open’
I have read somewhere that GNU´s implementation prefixes iconv function names with lib, so iconv_open is called libiconv_open… however doing so i get:
‘libiconv_open’ was not declared in this scope
All this is a huge problem as the majority of the world uses more than just 27 alphabetical letters found in ASCII, so the potential user base needing non-ASCII characters is far larger than the base of english users. Transliteration with C/C++ would be an acceptable compromise, but that does not seem to work with Mbed OS.
I am out of ideas how to generate filenames that contain ASCII characters only…or maybe i just miss something in my code.
Can anyone help me how to do this in Mbed?