Borrar filtros
Borrar filtros

Is it possible to have a string constant (output datatype: string) generated in UTF-8?

13 visualizaciones (últimos 30 días)
"Simulink strings support 256 characters of the ISO/IEC 8859-1 character set" according to Simulink Strings in the Help Center.
I've created a "string constant" block called "String ãºç" in a simulink model where I've inserted the value "exampleàñçº".
The block's name is exported correctly in UTF-8 ("String ãºç"), but what I get in the exported file for the value is "example\340\361\347\272" (octal values for extended characters in ISO/IEC 8859-1).
I was wondering if there was a way to export the string value in UTF-8.

Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Ag. de 2024 a las 23:33
No, you cannot do this. Strings are exported as plain C / C++ character vectors, and plain C / C++ character vectors are 8 bit characters. There is no way in C / C++ to mark strings as being UTF-8. The closest you can come with constant char vectors is to have a sequence of bytes that happens to encode UTF-8
Unfortunately std::wstring uses 16 bit code points on Windows. For portability you need to use std:u32string
  1 comentario
Eduardo
Eduardo el 12 de Ag. de 2024 a las 9:33
Thank you for the answer! In the end, we ended up encoding the generated character vector ourselves.

Iniciar sesión para comentar.

Más respuestas (1)

Amith
Amith el 11 de Ag. de 2024 a las 6:44
Hi Eduardo,
When saving Simulink models, you can ensure that the string data is stored in UTF-8 format. Here’s how:
Save Models in SLX Format: Starting from R2023a release Simulink saves models in the SLX format by default. This format uses Unicode UTF-8 in XML and other international formats. It typically reduces file size compared to MDL files and enables incremental loading and saving.
You can learn more about this by clicking on the link below: https://www.mathworks.com/help/simulink/ug/save-models.html
Hope this helps!
  1 comentario
Eduardo
Eduardo el 12 de Ag. de 2024 a las 9:30
Thank you for the answer! However, it unfortunately doesn't solve our issue...
Sorry for the misleading question and poor explanation of our issue.
Our issue is with code generation for C/C++.

Iniciar sesión para comentar.

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by