Skip to content

Commit e9154e1

Browse files
committed
ICU-22284 dump Numeric_Value property in icuexportdata.cpp
1 parent 892d449 commit e9154e1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

icu4c/source/tools/icuexportdata/icuexportdata.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,44 @@ void dumpGeneralCategoryMask(FILE* f) {
291291
fprintf(f, "]\n");
292292
}
293293

294+
void dumpNumericValue(FILE* f) {
295+
IcuToolErrorCode status("icuexportdata: dumpNumericValue");
296+
UProperty uproperty = UCHAR_NUMERIC_VALUE;
297+
298+
fputs("[[value_property]]\n", f);
299+
const char* fullPropName = u_getPropertyName(uproperty, U_LONG_PROPERTY_NAME);
300+
const char* shortPropName = u_getPropertyName(uproperty, U_SHORT_PROPERTY_NAME);
301+
fprintf(f, "long_name = \"%s\"\n", fullPropName);
302+
if (shortPropName) fprintf(f, "short_name = \"%s\"\n", shortPropName);
303+
fprintf(f, "upropert_discr = 0x%X\n", uproperty);
304+
dumpPropertyAliases(uproperty, f);
305+
306+
UCPTrieValueWidth width = UCPTRIE_VALUE_BITS_32;
307+
LocalUMutableCPTriePointer builder(umutablecptrie_open(0, 0, status));
308+
309+
for(UChar32 c = UCHAR_MIN_VALUE; c <= UCHAR_MAX_VALUE; c++) {
310+
int32_t ntv = static_cast<int32_t>(GET_NUMERIC_TYPE_VALUE(u_getMainProperties(c)));
311+
312+
if (ntv != UPROPS_NTV_NONE) {
313+
umutablecptrie_set(builder.getAlias(), c, ntv, status);
314+
}
315+
}
316+
317+
LocalUCPTriePointer utrie(umutablecptrie_buildImmutable(
318+
builder.getAlias(),
319+
trieType,
320+
width,
321+
status));
322+
handleError(status, __LINE__, fullPropName);
323+
324+
const UCPMap* umap = reinterpret_cast<UCPMap *>(utrie.getAlias());
325+
usrc_writeUCPMap(f, umap, nullptr, UPRV_TARGET_SYNTAX_TOML);
326+
fputs("\n", f);
327+
328+
fputs("[value_property.code_point_trie]\n", f);
329+
usrc_writeUCPTrie(f, shortPropName, utrie.getAlias(), UPRV_TARGET_SYNTAX_TOML);
330+
}
331+
294332
namespace {
295333

296334
void U_CALLCONV
@@ -1110,6 +1148,9 @@ int exportUprops(int argc, char* argv[]) {
11101148
i = UCHAR_SCRIPT_EXTENSIONS;
11111149
}
11121150
if (i == UCHAR_SCRIPT_EXTENSIONS + 1) {
1151+
i = UCHAR_NUMERIC_VALUE;
1152+
}
1153+
if (i == UCHAR_NUMERIC_VALUE + 1) {
11131154
break;
11141155
}
11151156
UProperty uprop = static_cast<UProperty>(i);
@@ -1196,6 +1237,8 @@ int exportUprops(int argc, char* argv[]) {
11961237
dumpBidiMirroringGlyph(f);
11971238
} else if (propEnum == UCHAR_SCRIPT_EXTENSIONS) {
11981239
dumpScriptExtensions(f);
1240+
} else if (propEnum == UCHAR_NUMERIC_VALUE) {
1241+
dumpNumericValue(f);
11991242
} else {
12001243
std::cerr << "Don't know how to write property: " << propEnum << std::endl;
12011244
return U_INTERNAL_PROGRAM_ERROR;

0 commit comments

Comments
 (0)