Convert ISO-8859-1 string to GSM string in C

I read some text (known in ISO-8859-1) from a TCP socket using the read function, then I am replacing the base substring. Finally, I would like to convert the string to the equivalent of GSM.

Preferably (but not necessarily) I would do something like this:

size_t i; for (i=0; i<size; i++) { switch (string[i]) { case 65: //Convert this character case 163: //Convert this character (the pound symbol Β£) } } 

I prefer the switch for readability, but also reviewed if-else statements.

This works for regular ASCII characters, but the top of ISO-8859-1 causes me all the problems. Apparently, they are considered as several characters. Any help on how to proceed with the conversion would be greatly appreciated.

+4
source share
1 answer

In your case, char seems to be signed. You can use char literals and work around the whole problem with the sign of char values ​​outside of ASCII 127:

 /* ascii: */ case '\000': /* U+0000 - nul */ ... /* extended ascii: */ case '\200': /* U+0080 - non-printable control character */ ... case '\243': /* U+00A3 - sterling pound */ ... case '\377': /* U+00ff - lower case y with dieresis */ 

The conversion is probably more efficient to implement by searching in an array.

If part of the extended ASCII of your input is represented as a few characters, then your input is probably encoded in UTF-8 or something similar.

+4
source

Source: https://habr.com/ru/post/1440038/


All Articles