1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 2007-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
16 #include "unicode/ulocdata.h"
17 #include "unicode/ucnv.h"
18 #include "unicode/unistr.h"
19 #include "unicode/ucol.h"
23 To add a new enum type
24 (For example: UShoeSize with values USHOE_WIDE=0, USHOE_REGULAR, USHOE_NARROW, USHOE_COUNT)
26 0. Make sure that all lines you add are protected with appropriate uconfig guards,
27 such as '#if !UCONFIG_NO_SHOES'.
28 1. udbgutil.h: add UDBG_UShoeSize to the UDebugEnumType enum before UDBG_ENUM_COUNT
29 ( The subsequent steps involve this file, udbgutil.cpp )
30 2. Find the marker "Add new enum types above this line"
31 3. Before that marker, add a #include of any header file you need.
32 4. Each enum type has three things in this section: a #define, a count_, and an array of Fields.
33 It may help to copy and paste a previous definition.
34 5. In the case of the USHOE_... strings above, "USHOE_" is common to all values- six characters
35 " #define LEN_USHOE 6 "
36 6 characters will strip off "USHOE_" leaving enum values of WIDE, REGULAR, and NARROW.
37 6. Define the 'count_' variable, with the number of enum values. If the enum has a _MAX or _COUNT value,
38 that can be helpful for automatically defining the count. Otherwise define it manually.
39 " static const int32_t count_UShoeSize = USHOE_COUNT; "
40 7. Define the field names, in order.
41 " static const Field names_UShoeSize[] = {
42 " FIELD_NAME_STR( LEN_USHOE, USHOE_WIDE ),
43 " FIELD_NAME_STR( LEN_USHOE, USHOE_REGULAR ),
44 " FIELD_NAME_STR( LEN_USHOE, USHOE_NARROW ),
46 ( The following command was usedfor converting ucol.h into partially correct entities )
47 grep "^[ ]*UCOL" < unicode/ucol.h |
48 sed -e 's%^[ ]*\([A-Z]*\)_\([A-Z_]*\).*% FIELD_NAME_STR( LEN_\1, \1_\2 ),%g'
49 8. Now, a bit farther down, add the name of the enum itself to the end of names_UDebugEnumType
50 ( UDebugEnumType is an enum, too!)
51 names_UDebugEnumType[] { ...
52 " FIELD_NAME_STR( LEN_UDBG, UDBG_UShoeSize ), "
53 9. Find the function _udbg_enumCount and add the count macro:
54 " COUNT_CASE(UShoeSize)
55 10. Find the function _udbg_enumFields and add the field macro:
56 " FIELD_CASE(UShoeSize)
57 11. verify that your test code, and Java data generation, works properly.
61 * Structure representing an enum value
64 int32_t prefix
; /**< how many characters to remove in the prefix - i.e. UCHAR_ = 5 */
65 const char *str
; /**< The actual string value */
66 int32_t num
; /**< The numeric value */
70 * Define another field name. Used in an array of Field s
71 * @param y the common prefix length (i.e. 6 for "USHOE_" )
72 * @param x the actual enum value - it will be copied in both string and symbolic form.
75 #define FIELD_NAME_STR(y,x) { y, #x, x }
78 // TODO: Currently, this whole functionality goes away with UCONFIG_NO_FORMATTING. Should be split up.
79 #if !UCONFIG_NO_FORMATTING
82 #include "unicode/ucal.h"
85 #define LEN_UCAL 5 /* UCAL_ */
86 static const int32_t count_UCalendarDateFields
= UCAL_FIELD_COUNT
;
87 static const Field names_UCalendarDateFields
[] =
89 FIELD_NAME_STR( LEN_UCAL
, UCAL_ERA
),
90 FIELD_NAME_STR( LEN_UCAL
, UCAL_YEAR
),
91 FIELD_NAME_STR( LEN_UCAL
, UCAL_MONTH
),
92 FIELD_NAME_STR( LEN_UCAL
, UCAL_WEEK_OF_YEAR
),
93 FIELD_NAME_STR( LEN_UCAL
, UCAL_WEEK_OF_MONTH
),
94 FIELD_NAME_STR( LEN_UCAL
, UCAL_DATE
),
95 FIELD_NAME_STR( LEN_UCAL
, UCAL_DAY_OF_YEAR
),
96 FIELD_NAME_STR( LEN_UCAL
, UCAL_DAY_OF_WEEK
),
97 FIELD_NAME_STR( LEN_UCAL
, UCAL_DAY_OF_WEEK_IN_MONTH
),
98 FIELD_NAME_STR( LEN_UCAL
, UCAL_AM_PM
),
99 FIELD_NAME_STR( LEN_UCAL
, UCAL_HOUR
),
100 FIELD_NAME_STR( LEN_UCAL
, UCAL_HOUR_OF_DAY
),
101 FIELD_NAME_STR( LEN_UCAL
, UCAL_MINUTE
),
102 FIELD_NAME_STR( LEN_UCAL
, UCAL_SECOND
),
103 FIELD_NAME_STR( LEN_UCAL
, UCAL_MILLISECOND
),
104 FIELD_NAME_STR( LEN_UCAL
, UCAL_ZONE_OFFSET
),
105 FIELD_NAME_STR( LEN_UCAL
, UCAL_DST_OFFSET
),
106 FIELD_NAME_STR( LEN_UCAL
, UCAL_YEAR_WOY
),
107 FIELD_NAME_STR( LEN_UCAL
, UCAL_DOW_LOCAL
),
108 FIELD_NAME_STR( LEN_UCAL
, UCAL_EXTENDED_YEAR
),
109 FIELD_NAME_STR( LEN_UCAL
, UCAL_JULIAN_DAY
),
110 FIELD_NAME_STR( LEN_UCAL
, UCAL_MILLISECONDS_IN_DAY
),
111 FIELD_NAME_STR( LEN_UCAL
, UCAL_IS_LEAP_MONTH
),
115 static const int32_t count_UCalendarMonths
= UCAL_UNDECIMBER
+1;
116 static const Field names_UCalendarMonths
[] =
118 FIELD_NAME_STR( LEN_UCAL
, UCAL_JANUARY
),
119 FIELD_NAME_STR( LEN_UCAL
, UCAL_FEBRUARY
),
120 FIELD_NAME_STR( LEN_UCAL
, UCAL_MARCH
),
121 FIELD_NAME_STR( LEN_UCAL
, UCAL_APRIL
),
122 FIELD_NAME_STR( LEN_UCAL
, UCAL_MAY
),
123 FIELD_NAME_STR( LEN_UCAL
, UCAL_JUNE
),
124 FIELD_NAME_STR( LEN_UCAL
, UCAL_JULY
),
125 FIELD_NAME_STR( LEN_UCAL
, UCAL_AUGUST
),
126 FIELD_NAME_STR( LEN_UCAL
, UCAL_SEPTEMBER
),
127 FIELD_NAME_STR( LEN_UCAL
, UCAL_OCTOBER
),
128 FIELD_NAME_STR( LEN_UCAL
, UCAL_NOVEMBER
),
129 FIELD_NAME_STR( LEN_UCAL
, UCAL_DECEMBER
),
130 FIELD_NAME_STR( LEN_UCAL
, UCAL_UNDECIMBER
)
133 #include "unicode/udat.h"
135 #define LEN_UDAT 5 /* "UDAT_" */
136 static const int32_t count_UDateFormatStyle
= UDAT_SHORT
+1;
137 static const Field names_UDateFormatStyle
[] =
139 FIELD_NAME_STR( LEN_UDAT
, UDAT_FULL
),
140 FIELD_NAME_STR( LEN_UDAT
, UDAT_LONG
),
141 FIELD_NAME_STR( LEN_UDAT
, UDAT_MEDIUM
),
142 FIELD_NAME_STR( LEN_UDAT
, UDAT_SHORT
),
145 * negative enums.. leave out for now.
146 FIELD_NAME_STR( LEN_UDAT, UDAT_NONE ),
147 FIELD_NAME_STR( LEN_UDAT, UDAT_PATTERN ),
153 #include "unicode/uloc.h"
155 #define LEN_UAR 12 /* "ULOC_ACCEPT_" */
156 static const int32_t count_UAcceptResult
= 3;
157 static const Field names_UAcceptResult
[] =
159 FIELD_NAME_STR( LEN_UAR
, ULOC_ACCEPT_FAILED
),
160 FIELD_NAME_STR( LEN_UAR
, ULOC_ACCEPT_VALID
),
161 FIELD_NAME_STR( LEN_UAR
, ULOC_ACCEPT_FALLBACK
),
164 #if !UCONFIG_NO_COLLATION
165 #include "unicode/ucol.h"
166 #define LEN_UCOL 5 /* UCOL_ */
167 static const int32_t count_UColAttributeValue
= UCOL_ATTRIBUTE_VALUE_COUNT
;
168 static const Field names_UColAttributeValue
[] = {
169 FIELD_NAME_STR( LEN_UCOL
, UCOL_PRIMARY
),
170 FIELD_NAME_STR( LEN_UCOL
, UCOL_SECONDARY
),
171 FIELD_NAME_STR( LEN_UCOL
, UCOL_TERTIARY
),
172 // FIELD_NAME_STR( LEN_UCOL, UCOL_CE_STRENGTH_LIMIT ),
173 FIELD_NAME_STR( LEN_UCOL
, UCOL_QUATERNARY
),
175 FIELD_NAME_STR( LEN_UCOL
, UCOL_IDENTICAL
),
176 // FIELD_NAME_STR( LEN_UCOL, UCOL_STRENGTH_LIMIT ),
177 FIELD_NAME_STR( LEN_UCOL
, UCOL_OFF
),
178 FIELD_NAME_STR( LEN_UCOL
, UCOL_ON
),
180 FIELD_NAME_STR( LEN_UCOL
, UCOL_SHIFTED
),
181 FIELD_NAME_STR( LEN_UCOL
, UCOL_NON_IGNORABLE
),
183 FIELD_NAME_STR( LEN_UCOL
, UCOL_LOWER_FIRST
),
184 FIELD_NAME_STR( LEN_UCOL
, UCOL_UPPER_FIRST
),
190 #if UCONFIG_ENABLE_PLUGINS
191 #include "unicode/icuplug.h"
193 #define LEN_UPLUG_REASON 13 /* UPLUG_REASON_ */
194 static const int32_t count_UPlugReason
= UPLUG_REASON_COUNT
;
195 static const Field names_UPlugReason
[] = {
196 FIELD_NAME_STR( LEN_UPLUG_REASON
, UPLUG_REASON_QUERY
),
197 FIELD_NAME_STR( LEN_UPLUG_REASON
, UPLUG_REASON_LOAD
),
198 FIELD_NAME_STR( LEN_UPLUG_REASON
, UPLUG_REASON_UNLOAD
),
201 #define LEN_UPLUG_LEVEL 12 /* UPLUG_LEVEL_ */
202 static const int32_t count_UPlugLevel
= UPLUG_LEVEL_COUNT
;
203 static const Field names_UPlugLevel
[] = {
204 FIELD_NAME_STR( LEN_UPLUG_LEVEL
, UPLUG_LEVEL_INVALID
),
205 FIELD_NAME_STR( LEN_UPLUG_LEVEL
, UPLUG_LEVEL_UNKNOWN
),
206 FIELD_NAME_STR( LEN_UPLUG_LEVEL
, UPLUG_LEVEL_LOW
),
207 FIELD_NAME_STR( LEN_UPLUG_LEVEL
, UPLUG_LEVEL_HIGH
),
211 #define LEN_UDBG 5 /* "UDBG_" */
212 static const int32_t count_UDebugEnumType
= UDBG_ENUM_COUNT
;
213 static const Field names_UDebugEnumType
[] =
215 FIELD_NAME_STR( LEN_UDBG
, UDBG_UDebugEnumType
),
216 #if !UCONFIG_NO_FORMATTING
217 FIELD_NAME_STR( LEN_UDBG
, UDBG_UCalendarDateFields
),
218 FIELD_NAME_STR( LEN_UDBG
, UDBG_UCalendarMonths
),
219 FIELD_NAME_STR( LEN_UDBG
, UDBG_UDateFormatStyle
),
221 #if UCONFIG_ENABLE_PLUGINS
222 FIELD_NAME_STR( LEN_UDBG
, UDBG_UPlugReason
),
223 FIELD_NAME_STR( LEN_UDBG
, UDBG_UPlugLevel
),
225 FIELD_NAME_STR( LEN_UDBG
, UDBG_UAcceptResult
),
226 #if !UCONFIG_NO_COLLATION
227 FIELD_NAME_STR( LEN_UDBG
, UDBG_UColAttributeValue
),
232 // --- Add new enum types above this line ---
234 #define COUNT_CASE(x) case UDBG_##x: return (actual?count_##x:UPRV_LENGTHOF(names_##x));
235 #define COUNT_FAIL_CASE(x) case UDBG_##x: return -1;
237 #define FIELD_CASE(x) case UDBG_##x: return names_##x;
238 #define FIELD_FAIL_CASE(x) case UDBG_##x: return NULL;
243 * @param type type of item
244 * @param actual TRUE: for the actual enum's type (UCAL_FIELD_COUNT, etc), or FALSE for the string count
246 static int32_t _udbg_enumCount(UDebugEnumType type
, UBool actual
) {
248 COUNT_CASE(UDebugEnumType
)
249 #if !UCONFIG_NO_FORMATTING
250 COUNT_CASE(UCalendarDateFields
)
251 COUNT_CASE(UCalendarMonths
)
252 COUNT_CASE(UDateFormatStyle
)
254 #if UCONFIG_ENABLE_PLUGINS
255 COUNT_CASE(UPlugReason
)
256 COUNT_CASE(UPlugLevel
)
258 COUNT_CASE(UAcceptResult
)
259 #if !UCONFIG_NO_COLLATION
260 COUNT_CASE(UColAttributeValue
)
262 // COUNT_FAIL_CASE(UNonExistentEnum)
268 static const Field
* _udbg_enumFields(UDebugEnumType type
) {
270 FIELD_CASE(UDebugEnumType
)
271 #if !UCONFIG_NO_FORMATTING
272 FIELD_CASE(UCalendarDateFields
)
273 FIELD_CASE(UCalendarMonths
)
274 FIELD_CASE(UDateFormatStyle
)
276 #if UCONFIG_ENABLE_PLUGINS
277 FIELD_CASE(UPlugReason
)
278 FIELD_CASE(UPlugLevel
)
280 FIELD_CASE(UAcceptResult
)
281 // FIELD_FAIL_CASE(UNonExistentEnum)
282 #if !UCONFIG_NO_COLLATION
283 FIELD_CASE(UColAttributeValue
)
292 int32_t udbg_enumCount(UDebugEnumType type
) {
293 return _udbg_enumCount(type
, FALSE
);
296 int32_t udbg_enumExpectedCount(UDebugEnumType type
) {
297 return _udbg_enumCount(type
, TRUE
);
300 const char * udbg_enumName(UDebugEnumType type
, int32_t field
) {
302 field
>=_udbg_enumCount(type
,FALSE
)) { // also will catch unsupported items
305 const Field
*fields
= _udbg_enumFields(type
);
309 return fields
[field
].str
+ fields
[field
].prefix
;
314 int32_t udbg_enumArrayValue(UDebugEnumType type
, int32_t field
) {
316 field
>=_udbg_enumCount(type
,FALSE
)) { // also will catch unsupported items
319 const Field
*fields
= _udbg_enumFields(type
);
323 return fields
[field
].num
;
328 int32_t udbg_enumByName(UDebugEnumType type
, const char *value
) {
329 if(type
<0||type
>=_udbg_enumCount(UDBG_UDebugEnumType
, TRUE
)) {
330 return -1; // type out of range
332 const Field
*fields
= _udbg_enumFields(type
);
333 if (fields
!= NULL
) {
334 for(int32_t field
= 0;field
<_udbg_enumCount(type
, FALSE
);field
++) {
335 if(!strcmp(value
, fields
[field
].str
+ fields
[field
].prefix
)) {
336 return fields
[field
].num
;
339 // try with the prefix
340 for(int32_t field
= 0;field
<_udbg_enumCount(type
, FALSE
);field
++) {
341 if(!strcmp(value
, fields
[field
].str
)) {
342 return fields
[field
].num
;
352 * Print the current platform
354 U_CAPI
const char *udbg_getPlatform(void)
356 #if U_PLATFORM_USES_ONLY_WIN32_API
358 #elif U_PLATFORM == U_PF_CYGWIN
360 #elif U_PLATFORM == U_PF_UNKNOWN
362 #elif U_PLATFORM == U_PF_DARWIN
364 #elif U_PLATFORM == U_PF_BSD
366 #elif U_PLATFORM == U_PF_QNX
368 #elif U_PLATFORM == U_PF_LINUX
370 #elif U_PLATFORM == U_PF_ANDROID
372 #elif U_PLATFORM == U_PF_CLASSIC_MACOS
373 return "MacOS (Classic)";
374 #elif U_PLATFORM == U_PF_OS390
376 #elif U_PLATFORM == U_PF_OS400
379 return "Other (POSIX-like)";
383 struct USystemParams
;
385 typedef int32_t U_CALLCONV
USystemParameterCallback(const USystemParams
*param
, char *target
, int32_t targetCapacity
, UErrorCode
*status
);
387 struct USystemParams
{
388 const char *paramName
;
389 USystemParameterCallback
*paramFunction
;
390 const char *paramStr
;
394 /* parameter types */
396 paramEmpty(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
397 if(U_FAILURE(*status
))return 0;
398 return u_terminateChars(target
, targetCapacity
, 0, status
);
402 paramStatic(const USystemParams
*param
, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
403 if(param
->paramStr
==NULL
) return paramEmpty(param
,target
,targetCapacity
,status
);
404 if(U_FAILURE(*status
))return 0;
405 int32_t len
= static_cast<int32_t>(uprv_strlen(param
->paramStr
));
407 uprv_strncpy(target
,param
->paramStr
,uprv_min(len
,targetCapacity
));
409 return u_terminateChars(target
, targetCapacity
, len
, status
);
412 static const char *nullString
= "(null)";
414 static int32_t stringToStringBuffer(char *target
, int32_t targetCapacity
, const char *str
, UErrorCode
*status
) {
415 if(str
==NULL
) str
=nullString
;
417 int32_t len
= static_cast<int32_t>(uprv_strlen(str
));
418 if (U_SUCCESS(*status
)) {
420 uprv_strncpy(target
,str
,uprv_min(len
,targetCapacity
));
423 const char *s
= u_errorName(*status
);
424 len
= static_cast<int32_t>(uprv_strlen(s
));
426 uprv_strncpy(target
,s
,uprv_min(len
,targetCapacity
));
429 return u_terminateChars(target
, targetCapacity
, len
, status
);
432 static int32_t integerToStringBuffer(char *target
, int32_t targetCapacity
, int32_t n
, int32_t radix
, UErrorCode
*status
) {
433 if(U_FAILURE(*status
)) return 0;
435 T_CString_integerToString(str
,n
,radix
);
436 return stringToStringBuffer(target
,targetCapacity
,str
,status
);
440 paramInteger(const USystemParams
*param
, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
441 if(U_FAILURE(*status
))return 0;
442 if(param
->paramStr
==NULL
|| param
->paramStr
[0]=='d') {
443 return integerToStringBuffer(target
,targetCapacity
,param
->paramInt
, 10,status
);
444 } else if(param
->paramStr
[0]=='x') {
445 return integerToStringBuffer(target
,targetCapacity
,param
->paramInt
, 16,status
);
446 } else if(param
->paramStr
[0]=='o') {
447 return integerToStringBuffer(target
,targetCapacity
,param
->paramInt
, 8,status
);
448 } else if(param
->paramStr
[0]=='b') {
449 return integerToStringBuffer(target
,targetCapacity
,param
->paramInt
, 2,status
);
451 *status
= U_INTERNAL_PROGRAM_ERROR
;
458 paramCldrVersion(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
459 if(U_FAILURE(*status
))return 0;
463 ulocdata_getCLDRVersion(icu
, status
);
464 if(U_SUCCESS(*status
)) {
465 u_versionToString(icu
, str
);
466 return stringToStringBuffer(target
,targetCapacity
,str
,status
);
473 static void versionBinToString(UVersionInfo icu
, char* str
) {
474 sprintf(str
, "%d.%d.%d.%d", icu
[0], icu
[1], icu
[2], icu
[3]);
479 paramCollUCAVersion(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
480 if(U_FAILURE(*status
))return 0;
484 UCollator
* ucol
= ucol_open("root", status
);
485 if(U_SUCCESS(*status
)) {
486 ucol_getUCAVersion(ucol
, icu
);
487 versionBinToString(icu
, str
);
489 return stringToStringBuffer(target
,targetCapacity
,str
,status
);
497 paramCollRootVersion(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
498 if(U_FAILURE(*status
))return 0;
502 UCollator
* ucol
= ucol_open("root", status
);
503 if(U_SUCCESS(*status
)) {
504 ucol_getVersion(ucol
, icu
);
505 versionBinToString(icu
, str
);
507 return stringToStringBuffer(target
,targetCapacity
,str
,status
);
515 paramCollEnVersion(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
516 if(U_FAILURE(*status
))return 0;
520 UCollator
* ucol
= ucol_open("en", status
);
521 if(U_SUCCESS(*status
)) {
522 ucol_getVersion(ucol
, icu
);
523 versionBinToString(icu
, str
);
525 return stringToStringBuffer(target
,targetCapacity
,str
,status
);
533 paramCollZhVersion(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
534 if(U_FAILURE(*status
))return 0;
538 UCollator
* ucol
= ucol_open("zh", status
);
539 if(U_SUCCESS(*status
)) {
540 ucol_getVersion(ucol
, icu
);
541 versionBinToString(icu
, str
);
543 return stringToStringBuffer(target
,targetCapacity
,str
,status
);
550 #if !UCONFIG_NO_FORMATTING
552 paramTimezoneDefault(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
553 if(U_FAILURE(*status
))return 0;
558 len
= ucal_getDefaultTimeZone(buf
, 100, status
);
559 if(U_SUCCESS(*status
)&&len
>0) {
560 u_UCharsToChars(buf
, buf2
, len
+1);
561 return stringToStringBuffer(target
,targetCapacity
, buf2
,status
);
569 paramLocaleDefaultBcp47(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
570 if(U_FAILURE(*status
))return 0;
571 const char *def
= uloc_getDefault();
572 return uloc_toLanguageTag(def
,target
,targetCapacity
,FALSE
,status
);
576 /* simple 1-liner param functions */
577 #define STRING_PARAM(func, str) U_CAPI int32_t \
578 func(const USystemParams *, char *target, int32_t targetCapacity, UErrorCode *status) \
579 { return stringToStringBuffer(target,targetCapacity,(str),status); }
581 STRING_PARAM(paramIcudataPath
, u_getDataDirectory())
582 STRING_PARAM(paramPlatform
, udbg_getPlatform())
583 STRING_PARAM(paramLocaleDefault
, uloc_getDefault())
584 #if !UCONFIG_NO_CONVERSION
585 STRING_PARAM(paramConverterDefault
, ucnv_getDefaultName())
588 #if !UCONFIG_NO_FORMATTING
589 STRING_PARAM(paramTimezoneVersion
, ucal_getTZDataVersion(status
))
592 static const USystemParams systemParams
[] = {
593 { "copyright", paramStatic
, U_COPYRIGHT_STRING
,0 },
594 { "product", paramStatic
, "icu4c",0 },
595 { "product.full", paramStatic
, "International Components for Unicode for C/C++",0 },
596 { "version", paramStatic
, U_ICU_VERSION
,0 },
597 { "version.unicode", paramStatic
, U_UNICODE_VERSION
,0 },
598 { "platform.number", paramInteger
, "d",U_PLATFORM
},
599 { "platform.type", paramPlatform
, NULL
,0},
600 { "locale.default", paramLocaleDefault
, NULL
, 0},
601 { "locale.default.bcp47", paramLocaleDefaultBcp47
, NULL
, 0},
602 #if !UCONFIG_NO_CONVERSION
603 { "converter.default", paramConverterDefault
, NULL
, 0},
605 { "icudata.name", paramStatic
, U_ICUDATA_NAME
, 0},
606 { "icudata.path", paramIcudataPath
, NULL
, 0},
608 { "cldr.version", paramCldrVersion
, NULL
, 0},
609 { "coll-uca.version", paramCollUCAVersion
, NULL
, 0},
610 { "coll-root.version", paramCollRootVersion
, NULL
, 0},
611 { "coll-en.version", paramCollEnVersion
, NULL
, 0},
612 { "coll-zh.version", paramCollZhVersion
, NULL
, 0},
614 #if !UCONFIG_NO_FORMATTING
615 { "tz.version", paramTimezoneVersion
, NULL
, 0},
616 { "tz.default", paramTimezoneDefault
, NULL
, 0},
619 { "cpu.bits", paramInteger
, "d", (sizeof(void*))*8},
620 { "cpu.big_endian", paramInteger
, "b", U_IS_BIG_ENDIAN
},
621 { "os.wchar_width", paramInteger
, "d", U_SIZEOF_WCHAR_T
},
622 { "os.charset_family", paramInteger
, "d", U_CHARSET_FAMILY
},
624 { "os.host", paramStatic
, U_HOST
, 0},
626 #if defined (U_BUILD)
627 { "build.build", paramStatic
, U_BUILD
, 0},
630 { "build.cc", paramStatic
, U_CC
, 0},
633 { "build.cxx", paramStatic
, U_CXX
, 0},
635 #if defined (CYGWINMSVC)
636 { "build.cygwinmsvc", paramInteger
, "b", 1},
638 { "uconfig.internal_digitlist", paramInteger
, "b", 1}, /* always 1 */
639 { "uconfig.have_parseallinput", paramInteger
, "b", UCONFIG_HAVE_PARSEALLINPUT
},
644 #define U_SYSPARAM_COUNT UPRV_LENGTHOF(systemParams)
646 U_CAPI
const char *udbg_getSystemParameterNameByIndex(int32_t i
) {
647 if(i
>=0 && i
< (int32_t)U_SYSPARAM_COUNT
) {
648 return systemParams
[i
].paramName
;
655 U_CAPI
int32_t udbg_getSystemParameterValueByIndex(int32_t i
, char *buffer
, int32_t bufferCapacity
, UErrorCode
*status
) {
656 if(i
>=0 && i
< (int32_t)U_SYSPARAM_COUNT
) {
657 return systemParams
[i
].paramFunction(&(systemParams
[i
]),buffer
,bufferCapacity
,status
);
663 U_CAPI
void udbg_writeIcuInfo(FILE *out
) {
665 /* todo: API for writing DTD? */
666 fprintf(out
, " <icuSystemParams type=\"icu4c\">\n");
667 const char *paramName
;
668 for(int32_t i
=0;(paramName
=udbg_getSystemParameterNameByIndex(i
))!=NULL
;i
++) {
669 UErrorCode status2
= U_ZERO_ERROR
;
670 udbg_getSystemParameterValueByIndex(i
, str
,2000,&status2
);
671 if(U_SUCCESS(status2
)) {
672 fprintf(out
," <param name=\"%s\">%s</param>\n", paramName
,str
);
674 fprintf(out
," <!-- n=\"%s\" ERROR: %s -->\n", paramName
, u_errorName(status2
));
677 fprintf(out
, " </icuSystemParams>\n");
680 #define ICU_TRAC_URL "http://bugs.icu-project.org/trac/ticket/"
681 #define CLDR_TRAC_URL "http://unicode.org/cldr/trac/ticket/"
682 #define CLDR_TICKET_PREFIX "cldrbug:"
684 U_CAPI
char *udbg_knownIssueURLFrom(const char *ticket
, char *buf
) {
689 if( !strncmp(ticket
, CLDR_TICKET_PREFIX
, strlen(CLDR_TICKET_PREFIX
)) ) {
690 strcpy( buf
, CLDR_TRAC_URL
);
691 strcat( buf
, ticket
+strlen(CLDR_TICKET_PREFIX
) );
693 strcpy( buf
, ICU_TRAC_URL
);
694 strcat( buf
, ticket
);
710 void add(const char *ticket
, const char *where
, const UChar
*msg
, UBool
*firstForTicket
, UBool
*firstForWhere
);
711 void add(const char *ticket
, const char *where
, const char *msg
, UBool
*firstForTicket
, UBool
*firstForWhere
);
714 std::map
< std::string
,
715 std::map
< std::string
, std::set
< std::string
> > > fTable
;
718 KnownIssues::KnownIssues()
723 KnownIssues::~KnownIssues()
727 void KnownIssues::add(const char *ticket
, const char *where
, const UChar
*msg
, UBool
*firstForTicket
, UBool
*firstForWhere
)
729 if(fTable
.find(ticket
) == fTable
.end()) {
730 if(firstForTicket
!=NULL
) *firstForTicket
= TRUE
;
731 fTable
[ticket
] = std::map
< std::string
, std::set
< std::string
> >();
733 if(firstForTicket
!=NULL
) *firstForTicket
= FALSE
;
735 if(where
==NULL
) return;
737 if(fTable
[ticket
].find(where
) == fTable
[ticket
].end()) {
738 if(firstForWhere
!=NULL
) *firstForWhere
= TRUE
;
739 fTable
[ticket
][where
] = std::set
< std::string
>();
741 if(firstForWhere
!=NULL
) *firstForWhere
= FALSE
;
743 if(msg
==NULL
|| !*msg
) return;
745 const icu::UnicodeString
ustr(msg
);
747 fTable
[ticket
][where
].insert(std::string(icu::CStr(ustr
)()));
750 void KnownIssues::add(const char *ticket
, const char *where
, const char *msg
, UBool
*firstForTicket
, UBool
*firstForWhere
)
752 if(fTable
.find(ticket
) == fTable
.end()) {
753 if(firstForTicket
!=NULL
) *firstForTicket
= TRUE
;
754 fTable
[ticket
] = std::map
< std::string
, std::set
< std::string
> >();
756 if(firstForTicket
!=NULL
) *firstForTicket
= FALSE
;
758 if(where
==NULL
) return;
760 if(fTable
[ticket
].find(where
) == fTable
[ticket
].end()) {
761 if(firstForWhere
!=NULL
) *firstForWhere
= TRUE
;
762 fTable
[ticket
][where
] = std::set
< std::string
>();
764 if(firstForWhere
!=NULL
) *firstForWhere
= FALSE
;
766 if(msg
==NULL
|| !*msg
) return;
768 std::string
str(msg
);
769 fTable
[ticket
][where
].insert(str
);
772 UBool
KnownIssues::print()
778 std::cout
<< "KNOWN ISSUES" << std::endl
;
779 for( std::map
< std::string
,
780 std::map
< std::string
, std::set
< std::string
> > >::iterator i
= fTable
.begin();
784 std::cout
<< '#' << (*i
).first
<< " <" << udbg_knownIssueURLFrom( (*i
).first
.c_str(), URL
) << ">" << std::endl
;
786 for( std::map
< std::string
, std::set
< std::string
> >::iterator ii
= (*i
).second
.begin();
787 ii
!= (*i
).second
.end();
789 std::cout
<< " " << (*ii
).first
<< std::endl
;
790 for ( std::set
< std::string
>::iterator iii
= (*ii
).second
.begin();
791 iii
!= (*ii
).second
.end();
793 std::cout
<< " " << '"' << (*iii
) << '"' << std::endl
;
800 U_CAPI
void *udbg_knownIssue_openU(void *ptr
, const char *ticket
, char *where
, const UChar
*msg
, UBool
*firstForTicket
,
801 UBool
*firstForWhere
) {
802 KnownIssues
*t
= static_cast<KnownIssues
*>(ptr
);
804 t
= new KnownIssues();
807 t
->add(ticket
, where
, msg
, firstForTicket
, firstForWhere
);
809 return static_cast<void*>(t
);
812 U_CAPI
void *udbg_knownIssue_open(void *ptr
, const char *ticket
, char *where
, const char *msg
, UBool
*firstForTicket
,
813 UBool
*firstForWhere
) {
814 KnownIssues
*t
= static_cast<KnownIssues
*>(ptr
);
816 t
= new KnownIssues();
819 t
->add(ticket
, where
, msg
, firstForTicket
, firstForWhere
);
821 return static_cast<void*>(t
);
824 U_CAPI UBool
udbg_knownIssue_print(void *ptr
) {
825 KnownIssues
*t
= static_cast<KnownIssues
*>(ptr
);
834 U_CAPI
void udbg_knownIssue_close(void *ptr
) {
835 KnownIssues
*t
= static_cast<KnownIssues
*>(ptr
);