Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Variable Width Character Encoding in Eclipse Editor

DZone's Guide to

Variable Width Character Encoding in Eclipse Editor

Character encoding is still an important consideration when developing for embedded devices and other IoT devices.

· IoT Zone ·
Free Resource

Digi-Key Electronics’ Internet of Things (IoT) Resource Center Inspires the Future: Read More

Dealing 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

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

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 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

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:

Image title

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

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

General Content Types Encoding Settings

Happy Encoding!

Links

Digi-Key’s IoT Component Selector is your one-stop-shop for the IoT

Topics:
microcontrollers ,embedded devices ,character encoding ,eclipse ,ide ,iot

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}