michael@0: /******************************************************************** michael@0: * COPYRIGHT: michael@0: * Copyright (c) 2007-2012, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ********************************************************************/ michael@0: michael@0: #include "udbgutil.h" michael@0: #include "dbgutil.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/ustring.h" michael@0: #include "util.h" michael@0: #include "ucln.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: static UnicodeString **strs = NULL; michael@0: michael@0: static const UnicodeString& _fieldString(UDebugEnumType type, int32_t field, UnicodeString& fillin) { michael@0: const char *str = udbg_enumName(type, field); michael@0: if(str == NULL) { michael@0: return fillin.remove(); michael@0: } else { michael@0: return fillin = UnicodeString(str, ""); // optimize? michael@0: } michael@0: } michael@0: michael@0: U_CDECL_BEGIN michael@0: static void udbg_cleanup(void) { michael@0: if(strs != NULL) { michael@0: for(int t=0;t<=UDBG_ENUM_COUNT;t++) { michael@0: delete [] strs[t]; michael@0: } michael@0: delete[] strs; michael@0: strs = NULL; michael@0: } michael@0: } michael@0: michael@0: static UBool tu_cleanup(void) michael@0: { michael@0: udbg_cleanup(); michael@0: return TRUE; michael@0: } michael@0: michael@0: static void udbg_register_cleanup(void) { michael@0: ucln_registerCleanup(UCLN_TOOLUTIL, tu_cleanup); michael@0: } michael@0: U_CDECL_END michael@0: michael@0: static void udbg_setup(void) { michael@0: if(strs == NULL) { michael@0: udbg_register_cleanup(); michael@0: //fprintf(stderr,"Initializing string cache..\n"); michael@0: //fflush(stderr); michael@0: UnicodeString **newStrs = new UnicodeString*[UDBG_ENUM_COUNT+1]; michael@0: for(int t=0;t=UDBG_ENUM_COUNT) { michael@0: // use UDBG_ENUM_COUNT,0 to mean an empty string michael@0: //fprintf(stderr, "** returning out of range on %d\n",type); michael@0: //fflush(stderr); michael@0: return strs[UDBG_ENUM_COUNT][0]; michael@0: } michael@0: int32_t count = udbg_enumCount(type); michael@0: //fprintf(stderr, "enumString [%d,%d]: typecount %d, fieldcount %d\n", type,field,UDBG_ENUM_COUNT,count); michael@0: //fflush(stderr); michael@0: if(field<0 || field > count) { michael@0: return strs[type][count]; michael@0: } else { return strs[type][field]; michael@0: } michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 udbg_enumByString(UDebugEnumType type, const UnicodeString& string) { michael@0: if(type<0||type>=UDBG_ENUM_COUNT) { michael@0: return -1; michael@0: } michael@0: // initialize array michael@0: udbg_enumString(type,0); michael@0: // search michael@0: /// printf("type=%d\n", type); fflush(stdout); michael@0: for(int i=0;iremove(); michael@0: for (int32_t i = 0; i < src.length(); ++i) { michael@0: UChar c = src[i]; michael@0: if(ICU_Utility::isUnprintable(c)) { michael@0: *dst += UnicodeString("["); michael@0: ICU_Utility::escapeUnprintable(*dst, c); michael@0: *dst += UnicodeString("]"); michael@0: } michael@0: else { michael@0: *dst += c; michael@0: } michael@0: } michael@0: michael@0: return dst; michael@0: } michael@0: michael@0: michael@0: michael@0: #endif