Variable Width Character Encoding in Eclipse Editor

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 microcontroller. In any case, Eclipse has you covered. This is especially helpful 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 which 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:

Saving non-confirming characters

Saving non-confirming characters

The ‘Select First Character’ is a good choice to find the 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

Advertisements

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.