From a5790173c177d28ab7cae401f334e05376ab5bf2 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Fri, 3 Dec 1999 19:53:10 +0000 Subject: [PATCH] [ICU-158] add getCharName() X-Commit-URL: https://ssl.icu-project.org/trac/changeset/288 --- icu4c/source/common/unicode.h | 41 ++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/icu4c/source/common/unicode.h b/icu4c/source/common/unicode.h index 7648e6ac523..adacd5d0b4c 100644 --- a/icu4c/source/common/unicode.h +++ b/icu4c/source/common/unicode.h @@ -28,7 +28,7 @@ #define UNICODE_H #include "utypes.h" - +#include "uchar.h" /** * The Unicode class allows you to query the properties associated with individual @@ -640,6 +640,37 @@ public: */ static uint16_t getCellWidth(UChar ch); + /** + * Retrieve the name of a Unicode character. + * Depending on nameChoice, the character name written + * into the buffer is the "modern" name or the name that was defined + * in Unicode version 1.0. + * The name contains only "invariant" characters + * like A-Z, 0-9, space, and '-'. + * + * @param code The character (code point) for which to get the name. + * It must be 0<=code<0x10ffff. + * @param buffer Destination address for copying the name. + * @param bufferLength ==sizeof(buffer) + * @param nameChoice Selector for which name to get. + * + * @see UCharNameChoice + * + * Example: + *
+     *     char buffer[100];
+     *     UTextOffset length=Unicode::getCharName(
+     *             0x284, buffer, sizeof(buffer));
+     *     
+     *     // use invariant-character conversion to Unicode
+     *     UnicodeString name(buffer, length, "");
+     * 
+ */ + static inline UTextOffset + getCharName(uint32_t code, + char *buffer, UTextOffset bufferLength, + UCharNameChoice nameChoice=U_UNICODE_CHAR_NAME); + /** * Retrives the decimal numeric value of a digit character. * @param ch the digit character for which to get the numeric value @@ -736,5 +767,13 @@ protected: }; +inline UTextOffset +Unicode::getCharName(uint32_t code, + char *buffer, UTextOffset bufferLength, + UCharNameChoice nameChoice) { + UErrorCode errorCode=U_ZERO_ERROR; + UTextOffset length=u_charName(code, nameChoice, buffer, bufferLength, &errorCode); + return U_SUCCESS(errorCode) ? length : 0; +} #endif