From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- intl/icu/source/tools/toolutil/dbgutil.cpp | 160 +++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 intl/icu/source/tools/toolutil/dbgutil.cpp (limited to 'intl/icu/source/tools/toolutil/dbgutil.cpp') diff --git a/intl/icu/source/tools/toolutil/dbgutil.cpp b/intl/icu/source/tools/toolutil/dbgutil.cpp new file mode 100644 index 0000000000..d42b267f73 --- /dev/null +++ b/intl/icu/source/tools/toolutil/dbgutil.cpp @@ -0,0 +1,160 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html +/******************************************************************** + * COPYRIGHT: + * Copyright (c) 2007-2012, International Business Machines Corporation and + * others. All Rights Reserved. + ********************************************************************/ + +#include "udbgutil.h" +#include "dbgutil.h" + +#if !UCONFIG_NO_FORMATTING + +#include "unicode/unistr.h" +#include "unicode/ustring.h" +#include "util.h" +#include "ucln.h" + +#include +#include +#include + +U_NAMESPACE_USE + +static UnicodeString **strs = nullptr; + +static const UnicodeString& _fieldString(UDebugEnumType type, int32_t field, UnicodeString& fillin) { + const char *str = udbg_enumName(type, field); + if(str == nullptr) { + return fillin.remove(); + } else { + return fillin = UnicodeString(str, -1, US_INV); + } +} + +U_CDECL_BEGIN +static void udbg_cleanup() { + if(strs != nullptr) { + for(int t=0;t<=UDBG_ENUM_COUNT;t++) { + delete [] strs[t]; + } + delete[] strs; + strs = nullptr; + } +} + +static UBool tu_cleanup() +{ + udbg_cleanup(); + return true; +} + +static void udbg_register_cleanup() { + ucln_registerCleanup(UCLN_TOOLUTIL, tu_cleanup); +} +U_CDECL_END + +static void udbg_setup() { + if(strs == nullptr) { + udbg_register_cleanup(); + //fprintf(stderr,"Initializing string cache..\n"); + //fflush(stderr); + UnicodeString **newStrs = new UnicodeString*[UDBG_ENUM_COUNT+1]; + for(int t=0;t=UDBG_ENUM_COUNT) { + // use UDBG_ENUM_COUNT,0 to mean an empty string + //fprintf(stderr, "** returning out of range on %d\n",type); + //fflush(stderr); + return strs[UDBG_ENUM_COUNT][0]; + } + int32_t count = udbg_enumCount(type); + //fprintf(stderr, "enumString [%d,%d]: typecount %d, fieldcount %d\n", type,field,UDBG_ENUM_COUNT,count); + //fflush(stderr); + if(field<0 || field > count) { + return strs[type][count]; + } else { return strs[type][field]; + } +} + +U_CAPI int32_t U_EXPORT2 udbg_enumByString(UDebugEnumType type, const UnicodeString& string) { + if(type<0||type>=UDBG_ENUM_COUNT) { + return -1; + } + // initialize array + udbg_enumString(type,0); + // search + /// printf("type=%d\n", type); fflush(stdout); + for(int i=0;iremove(); + for (int32_t i = 0; i < src.length(); ++i) { + char16_t c = src[i]; + if(ICU_Utility::isUnprintable(c)) { + *dst += UnicodeString("["); + ICU_Utility::escapeUnprintable(*dst, c); + *dst += UnicodeString("]"); + } + else { + *dst += c; + } + } + + return dst; +} + + + +#endif -- cgit v1.2.3