Variable Width Character Encoding in Eclipse Editor
Character encoding is still an important consideration when developing for embedded devices and other IoT devices.
Join the DZone community and get the full member experience.
Join For FreeDealing with variable width character encoding as with UTF-8 is pretty much a standard these days, at least in the desktop programming world. This is not so much true when programming embedded devices and microcontrollers. In any case, Eclipse has you covered. This is especially helpful in dealing with non-ASCII character codes in comments:
Comment With UTF-8 in Eclipse
In older Eclipse versions (e.g. Luna), the default character encoding in the Eclipse editor on Windows is the Cp1252, which is limited to 8 bits:
Cp1252 Encoding in Eclipse Luna
More modern Eclipse versions (e.g. Eclipse Oxygen in MCUXpresso IDE 10.3) are using UTF-8 by default. I can check the encoding in the properties menu für a file or folder:
UTF-8 in MCUXpresso IDE
UTF-8 is a variable length encoding that encodes a single character into 1, 2, 3, or 4 bytes.
Source file using UTF-8 wide characters
The ‘inherited from container’ means that the file is inheriting the settings from the container (or folder) where the file resides. If I try to save a file with characters not able to map to the selected encoding, Eclipse will warn me about this:
Saving non-confirming characters
The ‘Select First Character’ is a good choice to find a place where things might not be compliant.
I still have legacy projects with non-UTF-8 encoding, and I’m converting them to UTF-8 where applicable.
A helpful option is in the workspace preferences, which configures the default text file encoding:
Text File Encoding Workspace Preference
Other than that, the default encoding for each file can be configured under the menu Preferences > General > Content Types:
General Content Types Encoding Settings
Happy Encoding!
Links
- LCp1252 Encoding: https://en.wikipedia.org/wiki/Windows-1252
- UTF-8 Encoding: https://en.wikipedia.org/wiki/UTF-8
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments