Skip to content

Commit 3326b56

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

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

icu4c/source/tools/icuexportdata/icuexportdata.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,48 @@ void dumpBidiMirroringGlyph(FILE* f) {
247247
usrc_writeUCPTrie(f, shortPropName, utrie.getAlias(), UPRV_TARGET_SYNTAX_TOML);
248248
}
249249

250+
/*
251+
* Export Numeric_Value values in a similar way to how enumerated
252+
* properties are dumped to file.
253+
*/
254+
void dumpNumericValue(FILE* f) {
255+
IcuToolErrorCode status("icuexportdata: dumpNumericValue");
256+
UProperty uproperty = UCHAR_NUMERIC_VALUE;
257+
const char* fullPropName = u_getPropertyName(uproperty, U_LONG_PROPERTY_NAME);
258+
const char* shortPropName = u_getPropertyName(uproperty, U_SHORT_PROPERTY_NAME);
259+
260+
UCPTrieValueWidth width = UCPTRIE_VALUE_BITS_32;
261+
LocalUMutableCPTriePointer builder(umutablecptrie_open(0, 0, status));
262+
263+
for(UChar32 c = UCHAR_MIN_VALUE; c <= UCHAR_MAX_VALUE; c++) {
264+
int32_t ntv = static_cast<int32_t>(GET_NUMERIC_TYPE_VALUE(u_getMainProperties(c)));
265+
266+
if (ntv != UPROPS_NTV_NONE) {
267+
umutablecptrie_set(builder.getAlias(), c, ntv, status);
268+
}
269+
}
270+
271+
LocalUCPTriePointer utrie(umutablecptrie_buildImmutable(
272+
builder.getAlias(),
273+
trieType,
274+
width,
275+
status));
276+
handleError(status, __LINE__, fullPropName);
277+
278+
fputs("[[enum_property]]\n", f);
279+
fprintf(f, "long_name = \"%s\"\n", fullPropName);
280+
if (shortPropName) fprintf(f, "short_name = \"%s\"\n", shortPropName);
281+
fprintf(f, "upropert_discr = 0x%X\n", uproperty);
282+
dumpPropertyAliases(uproperty, f);
283+
284+
const UCPMap* umap = reinterpret_cast<UCPMap *>(utrie.getAlias());
285+
usrc_writeUCPMap(f, umap, nullptr, UPRV_TARGET_SYNTAX_TOML);
286+
fputs("\n", f);
287+
288+
fputs("[enum_property.code_point_trie]\n", f);
289+
usrc_writeUCPTrie(f, shortPropName, utrie.getAlias(), UPRV_TARGET_SYNTAX_TOML);
290+
}
291+
250292
// After printing property value `v`, print `mask` if and only if `mask` comes immediately
251293
// after the property in the listing
252294
void maybeDumpMaskValue(UProperty uproperty, uint32_t v, uint32_t mask, FILE* f) {
@@ -1110,6 +1152,9 @@ int exportUprops(int argc, char* argv[]) {
11101152
i = UCHAR_SCRIPT_EXTENSIONS;
11111153
}
11121154
if (i == UCHAR_SCRIPT_EXTENSIONS + 1) {
1155+
i = UCHAR_NUMERIC_VALUE;
1156+
}
1157+
if (i == UCHAR_NUMERIC_VALUE + 1) {
11131158
break;
11141159
}
11151160
UProperty uprop = static_cast<UProperty>(i);
@@ -1196,6 +1241,8 @@ int exportUprops(int argc, char* argv[]) {
11961241
dumpBidiMirroringGlyph(f);
11971242
} else if (propEnum == UCHAR_SCRIPT_EXTENSIONS) {
11981243
dumpScriptExtensions(f);
1244+
} else if (propEnum == UCHAR_NUMERIC_VALUE) {
1245+
dumpNumericValue(f);
11991246
} else {
12001247
std::cerr << "Don't know how to write property: " << propEnum << std::endl;
12011248
return U_INTERNAL_PROGRAM_ERROR;

0 commit comments

Comments
 (0)