1 /********************************************************************
3 * Copyright (c) 2007-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
13 #include "unicode/ulocdata.h"
14 #include "unicode/ucnv.h"
15 #include "unicode/unistr.h"
18 To add a new enum type
19 (For example: UShoeSize with values USHOE_WIDE=0, USHOE_REGULAR, USHOE_NARROW, USHOE_COUNT)
21 0. Make sure that all lines you add are protected with appropriate uconfig guards,
22 such as '#if !UCONFIG_NO_SHOES'.
23 1. udbgutil.h: add UDBG_UShoeSize to the UDebugEnumType enum before UDBG_ENUM_COUNT
24 ( The subsequent steps involve this file, udbgutil.cpp )
25 2. Find the marker "Add new enum types above this line"
26 3. Before that marker, add a #include of any header file you need.
27 4. Each enum type has three things in this section: a #define, a count_, and an array of Fields.
28 It may help to copy and paste a previous definition.
29 5. In the case of the USHOE_... strings above, "USHOE_" is common to all values- six characters
30 " #define LEN_USHOE 6 "
31 6 characters will strip off "USHOE_" leaving enum values of WIDE, REGULAR, and NARROW.
32 6. Define the 'count_' variable, with the number of enum values. If the enum has a _MAX or _COUNT value,
33 that can be helpful for automatically defining the count. Otherwise define it manually.
34 " static const int32_t count_UShoeSize = USHOE_COUNT; "
35 7. Define the field names, in order.
36 " static const Field names_UShoeSize[] = {
37 " FIELD_NAME_STR( LEN_USHOE, USHOE_WIDE ),
38 " FIELD_NAME_STR( LEN_USHOE, USHOE_REGULAR ),
39 " FIELD_NAME_STR( LEN_USHOE, USHOE_NARROW ),
41 ( The following command was usedfor converting ucol.h into partially correct entities )
42 grep "^[ ]*UCOL" < unicode/ucol.h |
43 sed -e 's%^[ ]*\([A-Z]*\)_\([A-Z_]*\).*% FIELD_NAME_STR( LEN_\1, \1_\2 ),%g'
44 8. Now, a bit farther down, add the name of the enum itself to the end of names_UDebugEnumType
45 ( UDebugEnumType is an enum, too!)
46 names_UDebugEnumType[] { ...
47 " FIELD_NAME_STR( LEN_UDBG, UDBG_UShoeSize ), "
48 9. Find the function _udbg_enumCount and add the count macro:
49 " COUNT_CASE(UShoeSize)
50 10. Find the function _udbg_enumFields and add the field macro:
51 " FIELD_CASE(UShoeSize)
52 11. verify that your test code, and Java data generation, works properly.
56 * Structure representing an enum value
59 int32_t prefix
; /**< how many characters to remove in the prefix - i.e. UCHAR_ = 5 */
60 const char *str
; /**< The actual string value */
61 int32_t num
; /**< The numeric value */
65 * Define another field name. Used in an array of Field s
66 * @param y the common prefix length (i.e. 6 for "USHOE_" )
67 * @param x the actual enum value - it will be copied in both string and symbolic form.
70 #define FIELD_NAME_STR(y,x) { y, #x, x }
73 // TODO: Currently, this whole functionality goes away with UCONFIG_NO_FORMATTING. Should be split up.
74 #if !UCONFIG_NO_FORMATTING
77 #include "unicode/ucal.h"
80 #define LEN_UCAL 5 /* UCAL_ */
81 static const int32_t count_UCalendarDateFields
= UCAL_FIELD_COUNT
;
82 static const Field names_UCalendarDateFields
[] =
84 FIELD_NAME_STR( LEN_UCAL
, UCAL_ERA
),
85 FIELD_NAME_STR( LEN_UCAL
, UCAL_YEAR
),
86 FIELD_NAME_STR( LEN_UCAL
, UCAL_MONTH
),
87 FIELD_NAME_STR( LEN_UCAL
, UCAL_WEEK_OF_YEAR
),
88 FIELD_NAME_STR( LEN_UCAL
, UCAL_WEEK_OF_MONTH
),
89 FIELD_NAME_STR( LEN_UCAL
, UCAL_DATE
),
90 FIELD_NAME_STR( LEN_UCAL
, UCAL_DAY_OF_YEAR
),
91 FIELD_NAME_STR( LEN_UCAL
, UCAL_DAY_OF_WEEK
),
92 FIELD_NAME_STR( LEN_UCAL
, UCAL_DAY_OF_WEEK_IN_MONTH
),
93 FIELD_NAME_STR( LEN_UCAL
, UCAL_AM_PM
),
94 FIELD_NAME_STR( LEN_UCAL
, UCAL_HOUR
),
95 FIELD_NAME_STR( LEN_UCAL
, UCAL_HOUR_OF_DAY
),
96 FIELD_NAME_STR( LEN_UCAL
, UCAL_MINUTE
),
97 FIELD_NAME_STR( LEN_UCAL
, UCAL_SECOND
),
98 FIELD_NAME_STR( LEN_UCAL
, UCAL_MILLISECOND
),
99 FIELD_NAME_STR( LEN_UCAL
, UCAL_ZONE_OFFSET
),
100 FIELD_NAME_STR( LEN_UCAL
, UCAL_DST_OFFSET
),
101 FIELD_NAME_STR( LEN_UCAL
, UCAL_YEAR_WOY
),
102 FIELD_NAME_STR( LEN_UCAL
, UCAL_DOW_LOCAL
),
103 FIELD_NAME_STR( LEN_UCAL
, UCAL_EXTENDED_YEAR
),
104 FIELD_NAME_STR( LEN_UCAL
, UCAL_JULIAN_DAY
),
105 FIELD_NAME_STR( LEN_UCAL
, UCAL_MILLISECONDS_IN_DAY
),
106 FIELD_NAME_STR( LEN_UCAL
, UCAL_IS_LEAP_MONTH
),
110 static const int32_t count_UCalendarMonths
= UCAL_UNDECIMBER
+1;
111 static const Field names_UCalendarMonths
[] =
113 FIELD_NAME_STR( LEN_UCAL
, UCAL_JANUARY
),
114 FIELD_NAME_STR( LEN_UCAL
, UCAL_FEBRUARY
),
115 FIELD_NAME_STR( LEN_UCAL
, UCAL_MARCH
),
116 FIELD_NAME_STR( LEN_UCAL
, UCAL_APRIL
),
117 FIELD_NAME_STR( LEN_UCAL
, UCAL_MAY
),
118 FIELD_NAME_STR( LEN_UCAL
, UCAL_JUNE
),
119 FIELD_NAME_STR( LEN_UCAL
, UCAL_JULY
),
120 FIELD_NAME_STR( LEN_UCAL
, UCAL_AUGUST
),
121 FIELD_NAME_STR( LEN_UCAL
, UCAL_SEPTEMBER
),
122 FIELD_NAME_STR( LEN_UCAL
, UCAL_OCTOBER
),
123 FIELD_NAME_STR( LEN_UCAL
, UCAL_NOVEMBER
),
124 FIELD_NAME_STR( LEN_UCAL
, UCAL_DECEMBER
),
125 FIELD_NAME_STR( LEN_UCAL
, UCAL_UNDECIMBER
)
128 #include "unicode/udat.h"
130 #define LEN_UDAT 5 /* "UDAT_" */
131 static const int32_t count_UDateFormatStyle
= UDAT_SHORT
+1;
132 static const Field names_UDateFormatStyle
[] =
134 FIELD_NAME_STR( LEN_UDAT
, UDAT_FULL
),
135 FIELD_NAME_STR( LEN_UDAT
, UDAT_LONG
),
136 FIELD_NAME_STR( LEN_UDAT
, UDAT_MEDIUM
),
137 FIELD_NAME_STR( LEN_UDAT
, UDAT_SHORT
),
140 * negative enums.. leave out for now.
141 FIELD_NAME_STR( LEN_UDAT, UDAT_NONE ),
142 FIELD_NAME_STR( LEN_UDAT, UDAT_PATTERN ),
148 #include "unicode/uloc.h"
150 #define LEN_UAR 12 /* "ULOC_ACCEPT_" */
151 static const int32_t count_UAcceptResult
= 3;
152 static const Field names_UAcceptResult
[] =
154 FIELD_NAME_STR( LEN_UAR
, ULOC_ACCEPT_FAILED
),
155 FIELD_NAME_STR( LEN_UAR
, ULOC_ACCEPT_VALID
),
156 FIELD_NAME_STR( LEN_UAR
, ULOC_ACCEPT_FALLBACK
),
159 #if !UCONFIG_NO_COLLATION
160 #include "unicode/ucol.h"
161 #define LEN_UCOL 5 /* UCOL_ */
162 static const int32_t count_UColAttributeValue
= UCOL_ATTRIBUTE_VALUE_COUNT
;
163 static const Field names_UColAttributeValue
[] = {
164 FIELD_NAME_STR( LEN_UCOL
, UCOL_PRIMARY
),
165 FIELD_NAME_STR( LEN_UCOL
, UCOL_SECONDARY
),
166 FIELD_NAME_STR( LEN_UCOL
, UCOL_TERTIARY
),
167 // FIELD_NAME_STR( LEN_UCOL, UCOL_CE_STRENGTH_LIMIT ),
168 FIELD_NAME_STR( LEN_UCOL
, UCOL_QUATERNARY
),
170 FIELD_NAME_STR( LEN_UCOL
, UCOL_IDENTICAL
),
171 // FIELD_NAME_STR( LEN_UCOL, UCOL_STRENGTH_LIMIT ),
172 FIELD_NAME_STR( LEN_UCOL
, UCOL_OFF
),
173 FIELD_NAME_STR( LEN_UCOL
, UCOL_ON
),
175 FIELD_NAME_STR( LEN_UCOL
, UCOL_SHIFTED
),
176 FIELD_NAME_STR( LEN_UCOL
, UCOL_NON_IGNORABLE
),
178 FIELD_NAME_STR( LEN_UCOL
, UCOL_LOWER_FIRST
),
179 FIELD_NAME_STR( LEN_UCOL
, UCOL_UPPER_FIRST
),
185 #if UCONFIG_ENABLE_PLUGINS
186 #include "unicode/icuplug.h"
188 #define LEN_UPLUG_REASON 13 /* UPLUG_REASON_ */
189 static const int32_t count_UPlugReason
= UPLUG_REASON_COUNT
;
190 static const Field names_UPlugReason
[] = {
191 FIELD_NAME_STR( LEN_UPLUG_REASON
, UPLUG_REASON_QUERY
),
192 FIELD_NAME_STR( LEN_UPLUG_REASON
, UPLUG_REASON_LOAD
),
193 FIELD_NAME_STR( LEN_UPLUG_REASON
, UPLUG_REASON_UNLOAD
),
196 #define LEN_UPLUG_LEVEL 12 /* UPLUG_LEVEL_ */
197 static const int32_t count_UPlugLevel
= UPLUG_LEVEL_COUNT
;
198 static const Field names_UPlugLevel
[] = {
199 FIELD_NAME_STR( LEN_UPLUG_LEVEL
, UPLUG_LEVEL_INVALID
),
200 FIELD_NAME_STR( LEN_UPLUG_LEVEL
, UPLUG_LEVEL_UNKNOWN
),
201 FIELD_NAME_STR( LEN_UPLUG_LEVEL
, UPLUG_LEVEL_LOW
),
202 FIELD_NAME_STR( LEN_UPLUG_LEVEL
, UPLUG_LEVEL_HIGH
),
206 #define LEN_UDBG 5 /* "UDBG_" */
207 static const int32_t count_UDebugEnumType
= UDBG_ENUM_COUNT
;
208 static const Field names_UDebugEnumType
[] =
210 FIELD_NAME_STR( LEN_UDBG
, UDBG_UDebugEnumType
),
211 #if !UCONFIG_NO_FORMATTING
212 FIELD_NAME_STR( LEN_UDBG
, UDBG_UCalendarDateFields
),
213 FIELD_NAME_STR( LEN_UDBG
, UDBG_UCalendarMonths
),
214 FIELD_NAME_STR( LEN_UDBG
, UDBG_UDateFormatStyle
),
216 #if UCONFIG_ENABLE_PLUGINS
217 FIELD_NAME_STR( LEN_UDBG
, UDBG_UPlugReason
),
218 FIELD_NAME_STR( LEN_UDBG
, UDBG_UPlugLevel
),
220 FIELD_NAME_STR( LEN_UDBG
, UDBG_UAcceptResult
),
221 #if !UCONFIG_NO_COLLATION
222 FIELD_NAME_STR( LEN_UDBG
, UDBG_UColAttributeValue
),
227 // --- Add new enum types above this line ---
229 #define COUNT_CASE(x) case UDBG_##x: return (actual?count_##x:UPRV_LENGTHOF(names_##x));
230 #define COUNT_FAIL_CASE(x) case UDBG_##x: return -1;
232 #define FIELD_CASE(x) case UDBG_##x: return names_##x;
233 #define FIELD_FAIL_CASE(x) case UDBG_##x: return NULL;
238 * @param type type of item
239 * @param actual TRUE: for the actual enum's type (UCAL_FIELD_COUNT, etc), or FALSE for the string count
241 static int32_t _udbg_enumCount(UDebugEnumType type
, UBool actual
) {
243 COUNT_CASE(UDebugEnumType
)
244 #if !UCONFIG_NO_FORMATTING
245 COUNT_CASE(UCalendarDateFields
)
246 COUNT_CASE(UCalendarMonths
)
247 COUNT_CASE(UDateFormatStyle
)
249 #if UCONFIG_ENABLE_PLUGINS
250 COUNT_CASE(UPlugReason
)
251 COUNT_CASE(UPlugLevel
)
253 COUNT_CASE(UAcceptResult
)
254 #if !UCONFIG_NO_COLLATION
255 COUNT_CASE(UColAttributeValue
)
257 // COUNT_FAIL_CASE(UNonExistentEnum)
263 static const Field
* _udbg_enumFields(UDebugEnumType type
) {
265 FIELD_CASE(UDebugEnumType
)
266 #if !UCONFIG_NO_FORMATTING
267 FIELD_CASE(UCalendarDateFields
)
268 FIELD_CASE(UCalendarMonths
)
269 FIELD_CASE(UDateFormatStyle
)
271 #if UCONFIG_ENABLE_PLUGINS
272 FIELD_CASE(UPlugReason
)
273 FIELD_CASE(UPlugLevel
)
275 FIELD_CASE(UAcceptResult
)
276 // FIELD_FAIL_CASE(UNonExistentEnum)
277 #if !UCONFIG_NO_COLLATION
278 FIELD_CASE(UColAttributeValue
)
287 int32_t udbg_enumCount(UDebugEnumType type
) {
288 return _udbg_enumCount(type
, FALSE
);
291 int32_t udbg_enumExpectedCount(UDebugEnumType type
) {
292 return _udbg_enumCount(type
, TRUE
);
295 const char * udbg_enumName(UDebugEnumType type
, int32_t field
) {
297 field
>=_udbg_enumCount(type
,FALSE
)) { // also will catch unsupported items
300 const Field
*fields
= _udbg_enumFields(type
);
304 return fields
[field
].str
+ fields
[field
].prefix
;
309 int32_t udbg_enumArrayValue(UDebugEnumType type
, int32_t field
) {
311 field
>=_udbg_enumCount(type
,FALSE
)) { // also will catch unsupported items
314 const Field
*fields
= _udbg_enumFields(type
);
318 return fields
[field
].num
;
323 int32_t udbg_enumByName(UDebugEnumType type
, const char *value
) {
324 if(type
<0||type
>=_udbg_enumCount(UDBG_UDebugEnumType
, TRUE
)) {
325 return -1; // type out of range
327 const Field
*fields
= _udbg_enumFields(type
);
328 if (fields
!= NULL
) {
329 for(int32_t field
= 0;field
<_udbg_enumCount(type
, FALSE
);field
++) {
330 if(!strcmp(value
, fields
[field
].str
+ fields
[field
].prefix
)) {
331 return fields
[field
].num
;
334 // try with the prefix
335 for(int32_t field
= 0;field
<_udbg_enumCount(type
, FALSE
);field
++) {
336 if(!strcmp(value
, fields
[field
].str
)) {
337 return fields
[field
].num
;
347 * Print the current platform
349 U_CAPI
const char *udbg_getPlatform(void)
351 #if U_PLATFORM_HAS_WIN32_API
353 #elif U_PLATFORM == U_PF_UNKNOWN
355 #elif U_PLATFORM == U_PF_DARWIN
357 #elif U_PLATFORM == U_PF_BSD
359 #elif U_PLATFORM == U_PF_QNX
361 #elif U_PLATFORM == U_PF_LINUX
363 #elif U_PLATFORM == U_PF_ANDROID
365 #elif U_PLATFORM == U_PF_CLASSIC_MACOS
366 return "MacOS (Classic)";
367 #elif U_PLATFORM == U_PF_OS390
369 #elif U_PLATFORM == U_PF_OS400
372 return "Other (POSIX-like)";
376 struct USystemParams
;
378 typedef int32_t U_CALLCONV
USystemParameterCallback(const USystemParams
*param
, char *target
, int32_t targetCapacity
, UErrorCode
*status
);
380 struct USystemParams
{
381 const char *paramName
;
382 USystemParameterCallback
*paramFunction
;
383 const char *paramStr
;
387 /* parameter types */
389 paramEmpty(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
390 if(U_FAILURE(*status
))return 0;
391 return u_terminateChars(target
, targetCapacity
, 0, status
);
395 paramStatic(const USystemParams
*param
, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
396 if(param
->paramStr
==NULL
) return paramEmpty(param
,target
,targetCapacity
,status
);
397 if(U_FAILURE(*status
))return 0;
398 int32_t len
= uprv_strlen(param
->paramStr
);
400 uprv_strncpy(target
,param
->paramStr
,uprv_min(len
,targetCapacity
));
402 return u_terminateChars(target
, targetCapacity
, len
, status
);
405 static const char *nullString
= "(null)";
407 static int32_t stringToStringBuffer(char *target
, int32_t targetCapacity
, const char *str
, UErrorCode
*status
) {
408 if(str
==NULL
) str
=nullString
;
410 int32_t len
= uprv_strlen(str
);
411 if (U_SUCCESS(*status
)) {
413 uprv_strncpy(target
,str
,uprv_min(len
,targetCapacity
));
416 const char *s
= u_errorName(*status
);
417 len
= uprv_strlen(s
);
419 uprv_strncpy(target
,s
,uprv_min(len
,targetCapacity
));
422 return u_terminateChars(target
, targetCapacity
, len
, status
);
425 static int32_t integerToStringBuffer(char *target
, int32_t targetCapacity
, int32_t n
, int32_t radix
, UErrorCode
*status
) {
426 if(U_FAILURE(*status
)) return 0;
428 T_CString_integerToString(str
,n
,radix
);
429 return stringToStringBuffer(target
,targetCapacity
,str
,status
);
433 paramInteger(const USystemParams
*param
, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
434 if(U_FAILURE(*status
))return 0;
435 if(param
->paramStr
==NULL
|| param
->paramStr
[0]=='d') {
436 return integerToStringBuffer(target
,targetCapacity
,param
->paramInt
, 10,status
);
437 } else if(param
->paramStr
[0]=='x') {
438 return integerToStringBuffer(target
,targetCapacity
,param
->paramInt
, 16,status
);
439 } else if(param
->paramStr
[0]=='o') {
440 return integerToStringBuffer(target
,targetCapacity
,param
->paramInt
, 8,status
);
441 } else if(param
->paramStr
[0]=='b') {
442 return integerToStringBuffer(target
,targetCapacity
,param
->paramInt
, 2,status
);
444 *status
= U_INTERNAL_PROGRAM_ERROR
;
451 paramCldrVersion(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
452 if(U_FAILURE(*status
))return 0;
456 ulocdata_getCLDRVersion(icu
, status
);
457 if(U_SUCCESS(*status
)) {
458 u_versionToString(icu
, str
);
459 return stringToStringBuffer(target
,targetCapacity
,str
,status
);
466 #if !UCONFIG_NO_FORMATTING
468 paramTimezoneDefault(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
469 if(U_FAILURE(*status
))return 0;
474 len
= ucal_getDefaultTimeZone(buf
, 100, status
);
475 if(U_SUCCESS(*status
)&&len
>0) {
476 u_UCharsToChars(buf
, buf2
, len
+1);
477 return stringToStringBuffer(target
,targetCapacity
, buf2
,status
);
485 paramLocaleDefaultBcp47(const USystemParams
* /* param */, char *target
, int32_t targetCapacity
, UErrorCode
*status
) {
486 if(U_FAILURE(*status
))return 0;
487 const char *def
= uloc_getDefault();
488 return uloc_toLanguageTag(def
,target
,targetCapacity
,FALSE
,status
);
492 /* simple 1-liner param functions */
493 #define STRING_PARAM(func, str) U_CAPI int32_t \
494 func(const USystemParams *, char *target, int32_t targetCapacity, UErrorCode *status) \
495 { return stringToStringBuffer(target,targetCapacity,(str),status); }
497 STRING_PARAM(paramIcudataPath
, u_getDataDirectory())
498 STRING_PARAM(paramPlatform
, udbg_getPlatform())
499 STRING_PARAM(paramLocaleDefault
, uloc_getDefault())
500 #if !UCONFIG_NO_CONVERSION
501 STRING_PARAM(paramConverterDefault
, ucnv_getDefaultName())
504 #if !UCONFIG_NO_FORMATTING
505 STRING_PARAM(paramTimezoneVersion
, ucal_getTZDataVersion(status
))
508 static const USystemParams systemParams
[] = {
509 { "copyright", paramStatic
, U_COPYRIGHT_STRING
,0 },
510 { "product", paramStatic
, "icu4c",0 },
511 { "product.full", paramStatic
, "International Components for Unicode for C/C++",0 },
512 { "version", paramStatic
, U_ICU_VERSION
,0 },
513 { "version.unicode", paramStatic
, U_UNICODE_VERSION
,0 },
514 { "platform.number", paramInteger
, "d",U_PLATFORM
},
515 { "platform.type", paramPlatform
, NULL
,0},
516 { "locale.default", paramLocaleDefault
, NULL
, 0},
517 { "locale.default.bcp47", paramLocaleDefaultBcp47
, NULL
, 0},
518 #if !UCONFIG_NO_CONVERSION
519 { "converter.default", paramConverterDefault
, NULL
, 0},
521 { "icudata.name", paramStatic
, U_ICUDATA_NAME
, 0},
522 { "icudata.path", paramIcudataPath
, NULL
, 0},
524 { "cldr.version", paramCldrVersion
, NULL
, 0},
526 #if !UCONFIG_NO_FORMATTING
527 { "tz.version", paramTimezoneVersion
, NULL
, 0},
528 { "tz.default", paramTimezoneDefault
, NULL
, 0},
531 { "cpu.bits", paramInteger
, "d", (sizeof(void*))*8},
532 { "cpu.big_endian", paramInteger
, "b", U_IS_BIG_ENDIAN
},
533 { "os.wchar_width", paramInteger
, "d", U_SIZEOF_WCHAR_T
},
534 { "os.charset_family", paramInteger
, "d", U_CHARSET_FAMILY
},
536 { "os.host", paramStatic
, U_HOST
, 0},
538 #if defined (U_BUILD)
539 { "build.build", paramStatic
, U_BUILD
, 0},
542 { "build.cc", paramStatic
, U_CC
, 0},
545 { "build.cxx", paramStatic
, U_CXX
, 0},
547 #if defined (CYGWINMSVC)
548 { "build.cygwinmsvc", paramInteger
, "b", 1},
550 { "uconfig.internal_digitlist", paramInteger
, "b", 1}, /* always 1 */
551 { "uconfig.have_parseallinput", paramInteger
, "b", UCONFIG_HAVE_PARSEALLINPUT
},
552 { "uconfig.format_fastpaths_49",paramInteger
, "b", UCONFIG_FORMAT_FASTPATHS_49
},
557 #define U_SYSPARAM_COUNT UPRV_LENGTHOF(systemParams)
559 U_CAPI
const char *udbg_getSystemParameterNameByIndex(int32_t i
) {
560 if(i
>=0 && i
< (int32_t)U_SYSPARAM_COUNT
) {
561 return systemParams
[i
].paramName
;
568 U_CAPI
int32_t udbg_getSystemParameterValueByIndex(int32_t i
, char *buffer
, int32_t bufferCapacity
, UErrorCode
*status
) {
569 if(i
>=0 && i
< (int32_t)U_SYSPARAM_COUNT
) {
570 return systemParams
[i
].paramFunction(&(systemParams
[i
]),buffer
,bufferCapacity
,status
);
576 U_CAPI
void udbg_writeIcuInfo(FILE *out
) {
578 /* todo: API for writing DTD? */
579 fprintf(out
, " <icuSystemParams type=\"icu4c\">\n");
580 const char *paramName
;
581 for(int32_t i
=0;(paramName
=udbg_getSystemParameterNameByIndex(i
))!=NULL
;i
++) {
582 UErrorCode status2
= U_ZERO_ERROR
;
583 udbg_getSystemParameterValueByIndex(i
, str
,2000,&status2
);
584 if(U_SUCCESS(status2
)) {
585 fprintf(out
," <param name=\"%s\">%s</param>\n", paramName
,str
);
587 fprintf(out
," <!-- n=\"%s\" ERROR: %s -->\n", paramName
, u_errorName(status2
));
590 fprintf(out
, " </icuSystemParams>\n");
593 #define ICU_TRAC_URL "http://bugs.icu-project.org/trac/ticket/"
594 #define CLDR_TRAC_URL "http://unicode.org/cldr/trac/ticket/"
595 #define CLDR_TICKET_PREFIX "cldrbug:"
597 U_CAPI
char *udbg_knownIssueURLFrom(const char *ticket
, char *buf
) {
602 if( !strncmp(ticket
, CLDR_TICKET_PREFIX
, strlen(CLDR_TICKET_PREFIX
)) ) {
603 strcpy( buf
, CLDR_TRAC_URL
);
604 strcat( buf
, ticket
+strlen(CLDR_TICKET_PREFIX
) );
606 strcpy( buf
, ICU_TRAC_URL
);
607 strcat( buf
, ticket
);
613 #if !U_HAVE_STD_STRING
614 const char *warning
= "WARNING: Don't have std::string (STL) - known issue logs will be deficient.";
616 U_CAPI
void *udbg_knownIssue_openU(void *ptr
, const char *ticket
, char *where
, const UChar
*msg
, UBool
*firstForTicket
,
617 UBool
*firstForWhere
) {
621 printf("%s\tKnown Issue #%s\n", where
, ticket
);
623 return (void*)warning
;
626 U_CAPI
void *udbg_knownIssue_open(void *ptr
, const char *ticket
, char *where
, const char *msg
, UBool
*firstForTicket
,
627 UBool
*firstForWhere
) {
631 if(msg
==NULL
) msg
= "";
632 printf("%s\tKnown Issue #%s \"%s\n", where
, ticket
, msg
);
634 return (void*)warning
;
637 U_CAPI UBool
udbg_knownIssue_print(void *ptr
) {
642 U_CAPI
void udbg_knownIssue_close(void *ptr
) {
657 void add(const char *ticket
, const char *where
, const UChar
*msg
, UBool
*firstForTicket
, UBool
*firstForWhere
);
658 void add(const char *ticket
, const char *where
, const char *msg
, UBool
*firstForTicket
, UBool
*firstForWhere
);
661 std::map
< std::string
,
662 std::map
< std::string
, std::set
< std::string
> > > fTable
;
665 KnownIssues::KnownIssues()
670 KnownIssues::~KnownIssues()
674 void KnownIssues::add(const char *ticket
, const char *where
, const UChar
*msg
, UBool
*firstForTicket
, UBool
*firstForWhere
)
676 if(fTable
.find(ticket
) == fTable
.end()) {
677 if(firstForTicket
!=NULL
) *firstForTicket
= TRUE
;
678 fTable
[ticket
] = std::map
< std::string
, std::set
< std::string
> >();
680 if(firstForTicket
!=NULL
) *firstForTicket
= FALSE
;
682 if(where
==NULL
) return;
684 if(fTable
[ticket
].find(where
) == fTable
[ticket
].end()) {
685 if(firstForWhere
!=NULL
) *firstForWhere
= TRUE
;
686 fTable
[ticket
][where
] = std::set
< std::string
>();
688 if(firstForWhere
!=NULL
) *firstForWhere
= FALSE
;
690 if(msg
==NULL
|| !*msg
) return;
693 fTable
[ticket
][where
].insert(icu::UnicodeString(msg
).toUTF8String(str
));
696 void KnownIssues::add(const char *ticket
, const char *where
, const char *msg
, UBool
*firstForTicket
, UBool
*firstForWhere
)
698 if(fTable
.find(ticket
) == fTable
.end()) {
699 if(firstForTicket
!=NULL
) *firstForTicket
= TRUE
;
700 fTable
[ticket
] = std::map
< std::string
, std::set
< std::string
> >();
702 if(firstForTicket
!=NULL
) *firstForTicket
= FALSE
;
704 if(where
==NULL
) return;
706 if(fTable
[ticket
].find(where
) == fTable
[ticket
].end()) {
707 if(firstForWhere
!=NULL
) *firstForWhere
= TRUE
;
708 fTable
[ticket
][where
] = std::set
< std::string
>();
710 if(firstForWhere
!=NULL
) *firstForWhere
= FALSE
;
712 if(msg
==NULL
|| !*msg
) return;
714 std::string
str(msg
);
715 fTable
[ticket
][where
].insert(str
);
718 UBool
KnownIssues::print()
724 std::cout
<< "KNOWN ISSUES" << std::endl
;
725 for( std::map
< std::string
,
726 std::map
< std::string
, std::set
< std::string
> > >::iterator i
= fTable
.begin();
730 std::cout
<< '#' << (*i
).first
<< " <" << udbg_knownIssueURLFrom( (*i
).first
.c_str(), URL
) << ">" << std::endl
;
732 for( std::map
< std::string
, std::set
< std::string
> >::iterator ii
= (*i
).second
.begin();
733 ii
!= (*i
).second
.end();
735 std::cout
<< " " << (*ii
).first
<< std::endl
;
736 for ( std::set
< std::string
>::iterator iii
= (*ii
).second
.begin();
737 iii
!= (*ii
).second
.end();
739 std::cout
<< " " << '"' << (*iii
) << '"' << std::endl
;
746 U_CAPI
void *udbg_knownIssue_openU(void *ptr
, const char *ticket
, char *where
, const UChar
*msg
, UBool
*firstForTicket
,
747 UBool
*firstForWhere
) {
748 KnownIssues
*t
= static_cast<KnownIssues
*>(ptr
);
750 t
= new KnownIssues();
753 t
->add(ticket
, where
, msg
, firstForTicket
, firstForWhere
);
755 return static_cast<void*>(t
);
758 U_CAPI
void *udbg_knownIssue_open(void *ptr
, const char *ticket
, char *where
, const char *msg
, UBool
*firstForTicket
,
759 UBool
*firstForWhere
) {
760 KnownIssues
*t
= static_cast<KnownIssues
*>(ptr
);
762 t
= new KnownIssues();
765 t
->add(ticket
, where
, msg
, firstForTicket
, firstForWhere
);
767 return static_cast<void*>(t
);
770 U_CAPI UBool
udbg_knownIssue_print(void *ptr
) {
771 KnownIssues
*t
= static_cast<KnownIssues
*>(ptr
);
780 U_CAPI
void udbg_knownIssue_close(void *ptr
) {
781 KnownIssues
*t
= static_cast<KnownIssues
*>(ptr
);