}
}
+class PropertyValueNameGetter : public ValueNameGetter {
+public:
+ PropertyValueNameGetter(UProperty prop) : property(prop) {}
+ ~PropertyValueNameGetter() override;
+ const char *getName(uint32_t value) override {
+ return u_getPropertyValueName(property, value, U_SHORT_PROPERTY_NAME);
+ }
+
+private:
+ UProperty property;
+};
+
+PropertyValueNameGetter::~PropertyValueNameGetter() {}
+
void dumpBinaryProperty(UProperty uproperty, FILE* f) {
IcuToolErrorCode status("icuexportdata: dumpBinaryProperty");
const char* fullPropName = u_getPropertyName(uproperty, U_LONG_PROPERTY_NAME);
fputs("[[enum_property]]\n", f);
fprintf(f, "long_name = \"%s\"\n", fullPropName);
if (shortPropName) fprintf(f, "short_name = \"%s\"\n", shortPropName);
- usrc_writeUCPMap(f, umap, uproperty, UPRV_TARGET_SYNTAX_TOML);
+ PropertyValueNameGetter valueNameGetter(uproperty);
+ usrc_writeUCPMap(f, umap, &valueNameGetter, UPRV_TARGET_SYNTAX_TOML);
fputs("\n", f);
U_ASSERT(u_getIntPropertyMinValue(uproperty) >= 0);
local_defines = [
"U_TOOLUTIL_IMPLEMENTATION",
],
- deps = ["//icu4c/source/common:platform"],
+ deps = [
+ "//icu4c/source/common:bytestream",
+ "//icu4c/source/common:platform",
+ "//icu4c/source/common:uniset_core",
+ ],
)
cc_library(
#include "writesrc.h"
#include "util.h"
+U_NAMESPACE_BEGIN
+
+ValueNameGetter::~ValueNameGetter() {}
+
+U_NAMESPACE_END
+
U_NAMESPACE_USE
static FILE *
usrc_writeUCPMap(
FILE *f,
const UCPMap *pMap,
- UProperty uproperty,
+ icu::ValueNameGetter *valueNameGetter,
UTargetSyntax syntax) {
// ccode is not yet supported
U_ASSERT(syntax == UPRV_TARGET_SYNTAX_TOML);
fprintf(f, "# Code points `a` through `b` have value `v`, corresponding to `name`.\n");
fprintf(f, "ranges = [\n");
while ((end = ucpmap_getRange(pMap, start, UCPMAP_RANGE_NORMAL, 0, nullptr, nullptr, &value)) >= 0) {
- if (uproperty != UCHAR_INVALID_CODE) {
- const char* short_name = u_getPropertyValueName(uproperty, value, U_SHORT_PROPERTY_NAME);
- fprintf(f, " {a=0x%x, b=0x%x, v=%u, name=\"%s\"},\n", start, end, value, short_name);
+ if (valueNameGetter != nullptr) {
+ const char *name = valueNameGetter->getName(value);
+ fprintf(f, " {a=0x%x, b=0x%x, v=%u, name=\"%s\"},\n", start, end, value, name);
} else {
fprintf(f, " {a=0x%x, b=0x%x, v=%u},\n", start, end, value);
}
const USet *pSet,
UTargetSyntax syntax);
+#ifdef __cplusplus
+
+U_NAMESPACE_BEGIN
+
+class U_TOOLUTIL_API ValueNameGetter {
+public:
+ virtual ~ValueNameGetter();
+ virtual const char *getName(uint32_t value) = 0;
+};
+
+U_NAMESPACE_END
+
/**
* Writes the UCPMap ranges list.
*
- * The "uproperty" argument is optional; ignored if UCHAR_INVALID_CODE. If present, it will be used
- * to look up the property value name strings.
+ * The "valueNameGetter" argument is optional; ignored if nullptr.
+ * If present, it will be used to look up value name strings.
*/
U_CAPI void U_EXPORT2
usrc_writeUCPMap(
FILE *f,
const UCPMap *pMap,
- UProperty uproperty,
+ icu::ValueNameGetter *valueNameGetter,
UTargetSyntax syntax);
+#endif // __cplusplus
+
/**
* Writes the contents of an array of mostly invariant characters.
* Characters 0..0x1f are printed as numbers,