| OLD | NEW |
| 1 /******************************************************************** | 1 /******************************************************************** |
| 2 * COPYRIGHT: | 2 * COPYRIGHT: |
| 3 * Copyright (c) 2007-2013, International Business Machines Corporation and | 3 * Copyright (c) 2007-2015, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ********************************************************************/ | 5 ********************************************************************/ |
| 6 | 6 |
| 7 #include "udbgutil.h" | 7 #include "udbgutil.h" |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include "ustr_imp.h" | 9 #include "ustr_imp.h" |
| 10 #include "cstring.h" | 10 #include "cstring.h" |
| 11 #include "putilimp.h" | 11 #include "putilimp.h" |
| 12 #include "unicode/ulocdata.h" | 12 #include "unicode/ulocdata.h" |
| 13 #include "unicode/ucnv.h" | 13 #include "unicode/ucnv.h" |
| 14 #include "unicode/unistr.h" | 14 #include "unicode/unistr.h" |
| 15 | 15 |
| 16 /* | 16 /* |
| 17 To add a new enum type | 17 To add a new enum type |
| 18 (For example: UShoeSize with values USHOE_WIDE=0, USHOE_REGULAR, USHOE_NA
RROW, USHOE_COUNT) | 18 (For example: UShoeSize with values USHOE_WIDE=0, USHOE_REGULAR, USHOE_NA
RROW, USHOE_COUNT) |
| 19 | 19 |
| 20 0. Make sure that all lines you add are protected with appropriate uconfig g
uards, |
| 21 such as '#if !UCONFIG_NO_SHOES'. |
| 20 1. udbgutil.h: add UDBG_UShoeSize to the UDebugEnumType enum before UDBG_E
NUM_COUNT | 22 1. udbgutil.h: add UDBG_UShoeSize to the UDebugEnumType enum before UDBG_E
NUM_COUNT |
| 21 ( The subsequent steps involve this file, udbgutil.cpp ) | 23 ( The subsequent steps involve this file, udbgutil.cpp ) |
| 22 2. Find the marker "Add new enum types above this line" | 24 2. Find the marker "Add new enum types above this line" |
| 23 3. Before that marker, add a #include of any header file you need. | 25 3. Before that marker, add a #include of any header file you need. |
| 24 4. Each enum type has three things in this section: a #define, a count_, an
d an array of Fields. | 26 4. Each enum type has three things in this section: a #define, a count_, an
d an array of Fields. |
| 25 It may help to copy and paste a previous definition. | 27 It may help to copy and paste a previous definition. |
| 26 5. In the case of the USHOE_... strings above, "USHOE_" is common to all val
ues- six characters | 28 5. In the case of the USHOE_... strings above, "USHOE_" is common to all val
ues- six characters |
| 27 " #define LEN_USHOE 6 " | 29 " #define LEN_USHOE 6 " |
| 28 6 characters will strip off "USHOE_" leaving enum values of WIDE, REGULAR
, and NARROW. | 30 6 characters will strip off "USHOE_" leaving enum values of WIDE, REGULAR
, and NARROW. |
| 29 6. Define the 'count_' variable, with the number of enum values. If the enum
has a _MAX or _COUNT value, | 31 6. Define the 'count_' variable, with the number of enum values. If the enum
has a _MAX or _COUNT value, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 FIELD_NAME_STR( LEN_UCOL, UCOL_SHIFTED ), | 179 FIELD_NAME_STR( LEN_UCOL, UCOL_SHIFTED ), |
| 178 FIELD_NAME_STR( LEN_UCOL, UCOL_NON_IGNORABLE ), | 180 FIELD_NAME_STR( LEN_UCOL, UCOL_NON_IGNORABLE ), |
| 179 // gap | 181 // gap |
| 180 FIELD_NAME_STR( LEN_UCOL, UCOL_LOWER_FIRST ), | 182 FIELD_NAME_STR( LEN_UCOL, UCOL_LOWER_FIRST ), |
| 181 FIELD_NAME_STR( LEN_UCOL, UCOL_UPPER_FIRST ), | 183 FIELD_NAME_STR( LEN_UCOL, UCOL_UPPER_FIRST ), |
| 182 }; | 184 }; |
| 183 | 185 |
| 184 #endif | 186 #endif |
| 185 | 187 |
| 186 | 188 |
| 189 #if UCONFIG_ENABLE_PLUGINS |
| 187 #include "unicode/icuplug.h" | 190 #include "unicode/icuplug.h" |
| 188 | 191 |
| 189 #define LEN_UPLUG_REASON 13 /* UPLUG_REASON_ */ | 192 #define LEN_UPLUG_REASON 13 /* UPLUG_REASON_ */ |
| 190 static const int32_t count_UPlugReason = UPLUG_REASON_COUNT; | 193 static const int32_t count_UPlugReason = UPLUG_REASON_COUNT; |
| 191 static const Field names_UPlugReason[] = { | 194 static const Field names_UPlugReason[] = { |
| 192 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_QUERY ), | 195 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_QUERY ), |
| 193 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_LOAD ), | 196 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_LOAD ), |
| 194 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_UNLOAD ), | 197 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_UNLOAD ), |
| 195 }; | 198 }; |
| 196 | 199 |
| 197 #define LEN_UPLUG_LEVEL 12 /* UPLUG_LEVEL_ */ | 200 #define LEN_UPLUG_LEVEL 12 /* UPLUG_LEVEL_ */ |
| 198 static const int32_t count_UPlugLevel = UPLUG_LEVEL_COUNT; | 201 static const int32_t count_UPlugLevel = UPLUG_LEVEL_COUNT; |
| 199 static const Field names_UPlugLevel[] = { | 202 static const Field names_UPlugLevel[] = { |
| 200 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_INVALID ), | 203 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_INVALID ), |
| 201 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_UNKNOWN ), | 204 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_UNKNOWN ), |
| 202 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_LOW ), | 205 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_LOW ), |
| 203 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_HIGH ), | 206 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_HIGH ), |
| 204 }; | 207 }; |
| 208 #endif |
| 205 | 209 |
| 206 #define LEN_UDBG 5 /* "UDBG_" */ | 210 #define LEN_UDBG 5 /* "UDBG_" */ |
| 207 static const int32_t count_UDebugEnumType = UDBG_ENUM_COUNT; | 211 static const int32_t count_UDebugEnumType = UDBG_ENUM_COUNT; |
| 208 static const Field names_UDebugEnumType[] = | 212 static const Field names_UDebugEnumType[] = |
| 209 { | 213 { |
| 210 FIELD_NAME_STR( LEN_UDBG, UDBG_UDebugEnumType ), | 214 FIELD_NAME_STR( LEN_UDBG, UDBG_UDebugEnumType ), |
| 211 #if !UCONFIG_NO_FORMATTING | 215 #if !UCONFIG_NO_FORMATTING |
| 212 FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarDateFields ), | 216 FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarDateFields ), |
| 213 FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarMonths ), | 217 FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarMonths ), |
| 214 FIELD_NAME_STR( LEN_UDBG, UDBG_UDateFormatStyle ), | 218 FIELD_NAME_STR( LEN_UDBG, UDBG_UDateFormatStyle ), |
| 215 #endif | 219 #endif |
| 220 #if UCONFIG_ENABLE_PLUGINS |
| 216 FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugReason ), | 221 FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugReason ), |
| 217 FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugLevel ), | 222 FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugLevel ), |
| 223 #endif |
| 218 FIELD_NAME_STR( LEN_UDBG, UDBG_UAcceptResult ), | 224 FIELD_NAME_STR( LEN_UDBG, UDBG_UAcceptResult ), |
| 219 #if !UCONFIG_NO_COLLATION | 225 #if !UCONFIG_NO_COLLATION |
| 220 FIELD_NAME_STR( LEN_UDBG, UDBG_UColAttributeValue ), | 226 FIELD_NAME_STR( LEN_UDBG, UDBG_UColAttributeValue ), |
| 221 #endif | 227 #endif |
| 222 }; | 228 }; |
| 223 | 229 |
| 224 | 230 |
| 225 // --- Add new enum types above this line --- | 231 // --- Add new enum types above this line --- |
| 226 | 232 |
| 227 #define COUNT_CASE(x) case UDBG_##x: return (actual?count_##x:DBG_ARRAY_COUNT(n
ames_##x)); | 233 #define COUNT_CASE(x) case UDBG_##x: return (actual?count_##x:DBG_ARRAY_COUNT(n
ames_##x)); |
| 228 #define COUNT_FAIL_CASE(x) case UDBG_##x: return -1; | 234 #define COUNT_FAIL_CASE(x) case UDBG_##x: return -1; |
| 229 | 235 |
| 230 #define FIELD_CASE(x) case UDBG_##x: return names_##x; | 236 #define FIELD_CASE(x) case UDBG_##x: return names_##x; |
| 231 #define FIELD_FAIL_CASE(x) case UDBG_##x: return NULL; | 237 #define FIELD_FAIL_CASE(x) case UDBG_##x: return NULL; |
| 232 | 238 |
| 233 // low level | 239 // low level |
| 234 | 240 |
| 235 /** | 241 /** |
| 236 * @param type type of item | 242 * @param type type of item |
| 237 * @param actual TRUE: for the actual enum's type (UCAL_FIELD_COUNT, etc), or FA
LSE for the string count | 243 * @param actual TRUE: for the actual enum's type (UCAL_FIELD_COUNT, etc), or FA
LSE for the string count |
| 238 */ | 244 */ |
| 239 static int32_t _udbg_enumCount(UDebugEnumType type, UBool actual) { | 245 static int32_t _udbg_enumCount(UDebugEnumType type, UBool actual) { |
| 240 switch(type) { | 246 switch(type) { |
| 241 COUNT_CASE(UDebugEnumType) | 247 COUNT_CASE(UDebugEnumType) |
| 242 #if !UCONFIG_NO_FORMATTING | 248 #if !UCONFIG_NO_FORMATTING |
| 243 COUNT_CASE(UCalendarDateFields) | 249 COUNT_CASE(UCalendarDateFields) |
| 244 COUNT_CASE(UCalendarMonths) | 250 COUNT_CASE(UCalendarMonths) |
| 245 COUNT_CASE(UDateFormatStyle) | 251 COUNT_CASE(UDateFormatStyle) |
| 246 #endif | 252 #endif |
| 253 #if UCONFIG_ENABLE_PLUGINS |
| 247 COUNT_CASE(UPlugReason) | 254 COUNT_CASE(UPlugReason) |
| 248 COUNT_CASE(UPlugLevel) | 255 COUNT_CASE(UPlugLevel) |
| 256 #endif |
| 249 COUNT_CASE(UAcceptResult) | 257 COUNT_CASE(UAcceptResult) |
| 250 #if !UCONFIG_NO_COLLATION | 258 #if !UCONFIG_NO_COLLATION |
| 251 COUNT_CASE(UColAttributeValue) | 259 COUNT_CASE(UColAttributeValue) |
| 252 #endif | 260 #endif |
| 253 // COUNT_FAIL_CASE(UNonExistentEnum) | 261 // COUNT_FAIL_CASE(UNonExistentEnum) |
| 254 default: | 262 default: |
| 255 return -1; | 263 return -1; |
| 256 } | 264 } |
| 257 } | 265 } |
| 258 | 266 |
| 259 static const Field* _udbg_enumFields(UDebugEnumType type) { | 267 static const Field* _udbg_enumFields(UDebugEnumType type) { |
| 260 switch(type) { | 268 switch(type) { |
| 261 FIELD_CASE(UDebugEnumType) | 269 FIELD_CASE(UDebugEnumType) |
| 262 #if !UCONFIG_NO_FORMATTING | 270 #if !UCONFIG_NO_FORMATTING |
| 263 FIELD_CASE(UCalendarDateFields) | 271 FIELD_CASE(UCalendarDateFields) |
| 264 FIELD_CASE(UCalendarMonths) | 272 FIELD_CASE(UCalendarMonths) |
| 265 FIELD_CASE(UDateFormatStyle) | 273 FIELD_CASE(UDateFormatStyle) |
| 266 #endif | 274 #endif |
| 275 #if UCONFIG_ENABLE_PLUGINS |
| 267 FIELD_CASE(UPlugReason) | 276 FIELD_CASE(UPlugReason) |
| 268 FIELD_CASE(UPlugLevel) | 277 FIELD_CASE(UPlugLevel) |
| 278 #endif |
| 269 FIELD_CASE(UAcceptResult) | 279 FIELD_CASE(UAcceptResult) |
| 270 » » // FIELD_FAIL_CASE(UNonExistentEnum) | 280 // FIELD_FAIL_CASE(UNonExistentEnum) |
| 271 #if !UCONFIG_NO_COLLATION | 281 #if !UCONFIG_NO_COLLATION |
| 272 FIELD_CASE(UColAttributeValue) | 282 FIELD_CASE(UColAttributeValue) |
| 273 #endif | 283 #endif |
| 274 default: | 284 default: |
| 275 return NULL; | 285 return NULL; |
| 276 } | 286 } |
| 277 } | 287 } |
| 278 | 288 |
| 279 // implementation | 289 // implementation |
| 280 | 290 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 return fields[field].num; | 322 return fields[field].num; |
| 313 } | 323 } |
| 314 } | 324 } |
| 315 } | 325 } |
| 316 | 326 |
| 317 int32_t udbg_enumByName(UDebugEnumType type, const char *value) { | 327 int32_t udbg_enumByName(UDebugEnumType type, const char *value) { |
| 318 if(type<0||type>=_udbg_enumCount(UDBG_UDebugEnumType, TRUE)) { | 328 if(type<0||type>=_udbg_enumCount(UDBG_UDebugEnumType, TRUE)) { |
| 319 return -1; // type out of range | 329 return -1; // type out of range |
| 320 } | 330 } |
| 321 const Field *fields = _udbg_enumFields(type); | 331 const Field *fields = _udbg_enumFields(type); |
| 322 for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) { | 332 if (fields != NULL) { |
| 323 if(!strcmp(value, fields[field].str + fields[field].prefix)) { | 333 for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) { |
| 324 return fields[field].num; | 334 if(!strcmp(value, fields[field].str + fields[field].prefix)) { |
| 335 return fields[field].num; |
| 336 } |
| 325 } | 337 } |
| 326 } | 338 // try with the prefix |
| 327 // try with the prefix | 339 for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) { |
| 328 for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) { | 340 if(!strcmp(value, fields[field].str)) { |
| 329 if(!strcmp(value, fields[field].str)) { | 341 return fields[field].num; |
| 330 return fields[field].num; | 342 } |
| 331 } | 343 } |
| 332 } | 344 } |
| 333 // fail | 345 // fail |
| 334 return -1; | 346 return -1; |
| 335 } | 347 } |
| 336 | 348 |
| 337 /* platform info */ | 349 /* platform info */ |
| 338 /** | 350 /** |
| 339 * Print the current platform | 351 * Print the current platform |
| 340 */ | 352 */ |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 return TRUE; | 780 return TRUE; |
| 769 } | 781 } |
| 770 } | 782 } |
| 771 | 783 |
| 772 U_CAPI void udbg_knownIssue_close(void *ptr) { | 784 U_CAPI void udbg_knownIssue_close(void *ptr) { |
| 773 KnownIssues *t = static_cast<KnownIssues*>(ptr); | 785 KnownIssues *t = static_cast<KnownIssues*>(ptr); |
| 774 delete t; | 786 delete t; |
| 775 } | 787 } |
| 776 | 788 |
| 777 #endif | 789 #endif |
| OLD | NEW |