libgrapheme

Freestanding C library for unicode string handling
git clone https://git.sinitax.com/suckless/libgrapheme
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 6375ae6d522413ba1a6e3b2a62c6e5e99349aafa
parent cd3a639d18c25942d0d48c8001f18222ba5899ef
Author: Laslo Hunhold <dev@frign.de>
Date:   Fri, 28 Oct 2022 17:08:41 +0200

Refactor post_process()-function to take the entire property-array

This does not make much of a difference, but gives enough flexibility
for a later change to incorporate the bidi-bracket-property into the
bidi-LUT.

Signed-off-by: Laslo Hunhold <dev@frign.de>

Diffstat:
Mgen/line.c | 88++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mgen/util.c | 13++++---------
Mgen/util.h | 4++--
3 files changed, 51 insertions(+), 54 deletions(-)

diff --git a/gen/line.c b/gen/line.c @@ -392,55 +392,57 @@ handle_conflict(uint_least32_t cp, uint_least8_t prop1, uint_least8_t prop2) return result; } -static uint_least8_t -post_process(uint_least32_t cp, uint_least8_t prop) +static void +post_process(struct properties *prop) { - const char *target = NULL; + const char *target; uint_least8_t result; + size_t i; - (void)cp; - - /* LB1 */ - if (!strcmp(line_break_property[prop].enumname, "TMP_AI") || - !strcmp(line_break_property[prop].enumname, "TMP_SG") || - !strcmp(line_break_property[prop].enumname, "TMP_XX")) { - /* map AI, SG and XX to AL */ - target = "AL"; - } else if (!strcmp(line_break_property[prop].enumname, "TMP_SA_WITH_MN_OR_MC")) { - /* map SA (with General_Category Mn or Mc) to CM */ - target = "CM"; - } else if (!strcmp(line_break_property[prop].enumname, "TMP_SA_WITHOUT_MN_OR_MC")) { - /* map SA (without General_Category Mn or Mc) to AL */ - target = "AL"; - } else if (!strcmp(line_break_property[prop].enumname, "TMP_CJ")) { - /* map CJ to NS */ - target = "NS"; - } else if (!strcmp(line_break_property[prop].enumname, "TMP_CN") || - !strcmp(line_break_property[prop].enumname, "TMP_EXTENDED_PICTOGRAPHIC") || - !strcmp(line_break_property[prop].enumname, "TMP_MN") || - !strcmp(line_break_property[prop].enumname, "TMP_MC") || - !strcmp(line_break_property[prop].enumname, "TMP_EAW_H") || - !strcmp(line_break_property[prop].enumname, "TMP_EAW_W") || - !strcmp(line_break_property[prop].enumname, "TMP_EAW_F")) { - /* map all the temporary classes "residue" to AL */ - target = "AL"; - } + /* post-mapping according to the line breaking algorithm */ + for (i = 0; i < UINT32_C(0x110000); i++) { + /* LB1 */ + if (!strcmp(line_break_property[prop[i].property].enumname, "TMP_AI") || + !strcmp(line_break_property[prop[i].property].enumname, "TMP_SG") || + !strcmp(line_break_property[prop[i].property].enumname, "TMP_XX")) { + /* map AI, SG and XX to AL */ + target = "AL"; + } else if (!strcmp(line_break_property[prop[i].property].enumname, "TMP_SA_WITH_MN_OR_MC")) { + /* map SA (with General_Category Mn or Mc) to CM */ + target = "CM"; + } else if (!strcmp(line_break_property[prop[i].property].enumname, "TMP_SA_WITHOUT_MN_OR_MC")) { + /* map SA (without General_Category Mn or Mc) to AL */ + target = "AL"; + } else if (!strcmp(line_break_property[prop[i].property].enumname, "TMP_CJ")) { + /* map CJ to NS */ + target = "NS"; + } else if (!strcmp(line_break_property[prop[i].property].enumname, "TMP_CN") || + !strcmp(line_break_property[prop[i].property].enumname, "TMP_EXTENDED_PICTOGRAPHIC") || + !strcmp(line_break_property[prop[i].property].enumname, "TMP_MN") || + !strcmp(line_break_property[prop[i].property].enumname, "TMP_MC") || + !strcmp(line_break_property[prop[i].property].enumname, "TMP_EAW_H") || + !strcmp(line_break_property[prop[i].property].enumname, "TMP_EAW_W") || + !strcmp(line_break_property[prop[i].property].enumname, "TMP_EAW_F")) { + /* map all the temporary classes "residue" to AL */ + target = "AL"; + } else { + target = NULL; + } - if (target) { - for (result = 0; result < LEN(line_break_property); result++) { - if (!strcmp(line_break_property[result].enumname, - target)) { - break; + if (target) { + for (result = 0; result < LEN(line_break_property); result++) { + if (!strcmp(line_break_property[result].enumname, + target)) { + break; + } + } + if (result == LEN(line_break_property)) { + fprintf(stderr, "handle_conflict: Internal error.\n"); + exit(1); } - } - if (result == LEN(line_break_property)) { - fprintf(stderr, "handle_conflict: Internal error.\n"); - exit(1); - } - return result; - } else { - return prop; + prop[i].property = result; + } } } diff --git a/gen/util.c b/gen/util.c @@ -495,10 +495,9 @@ properties_generate_break_property(const struct property_spec *spec, uint_least32_t), uint_least8_t (*handle_conflict)( uint_least32_t, uint_least8_t, - uint_least8_t), uint_least8_t - (*post_process)(uint_least32_t, - uint_least8_t), const char *prefix, - const char *argv0) + uint_least8_t), void + (*post_process)(struct properties *), + const char *prefix, const char *argv0) { struct properties_compressed comp; struct properties_major_minor mm; @@ -556,11 +555,7 @@ properties_generate_break_property(const struct property_spec *spec, /* post-processing */ if (post_process != NULL) { - for (i = 0; i < UINT32_C(0x110000); i++) { - payload.prop[i].property = - post_process((uint_least32_t)i, - (uint_least8_t)payload.prop[i].property); - } + post_process(payload.prop); } /* compress data */ diff --git a/gen/util.h b/gen/util.h @@ -51,8 +51,8 @@ void properties_generate_break_property(const struct property_spec *, uint_least8_t (*handle_conflict)(uint_least32_t, uint_least8_t, uint_least8_t), - uint_least8_t (*post_process) - (uint_least32_t, uint_least8_t), + void (*post_process) + (struct properties *), const char *, const char *); void break_test_list_parse(char *, struct break_test **, size_t *);