International Components for Unicode

ICU Coding Guidelines


This page describes guidelines for writing code for the International Components for Unicode and how to add it to the project.

General Guidelines

C Guidelines

C++ Guidelines

Adding files to ICU

Adding .c, .cpp, and .h files

In order to add compilable files to ICU, you not only need to add them to the source code control system in the appropriate folder, but also add them to the build environment.

The first step is to choose one of the ICU libraries:

  1. The common library provides mostly low-level utilities and basic APIs that often do not make use of Locales. Examples are APIs that deal with character properties, the Locale APIs themselves, and ResourceBundle APIs.
  2. The i18n library provides Locale-dependent and -using APIs, like for collation and formatting, that are most useful for internationalized user input and output.

Put the source code files into the folder icu/source/library-name.

Then add them to the build system:

You also need to add test code to icu/source/test/cintltest for C APIs and to icu/source/test/intltest for C++ APIs.

All the API functions must be called by the test code (100% API coverage), and at least 85% of the implementation code should be exercised by the tests (>=85% code coverage).

  1. For C, create test code using the log_err(), log_info(), and log_verbose() APIs from cintltst.h (which uses ctest.h), and check it into the appropriate folder.
  2. In order to get your C test code called, you have to add its toplevel function and a descriptive test module path to the test system by calling addTest(). The function that makes the call to addTest() ultimately has to be called by addAllTests() in calltest.c. Groups of tests typically have a common addGroup() function that calls addTest() for the test functions in its group, according to the common part of the test module path.
  3. Add that test code to the build system, too. Modify Makefile.in and the appropriate .dsp file like for the library code.

Build Tools

We are using the following tools to build ICU: