aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/unicode/string.h16
-rw-r--r--lib/unicode/string/u8norm.c20
-rw-r--r--test/_norm-test.h8
-rw-r--r--test/norm-nfc-test.c2
-rw-r--r--test/norm-nfd-test.c2
-rw-r--r--test/norm-nfkc-test.c2
-rw-r--r--test/norm-nfkd-test.c2
7 files changed, 26 insertions, 26 deletions
diff --git a/include/unicode/string.h b/include/unicode/string.h
index 17ce561..975e4eb 100644
--- a/include/unicode/string.h
+++ b/include/unicode/string.h
@@ -18,14 +18,14 @@ enum [[clang::flag_enum]] caseflags {
CF_ẞ = 1 << 3, /* Use ‘ẞ’ as the uppercase of ‘ß’; alias for CF_SS */
};
-enum normtype {
+enum normform {
/* If bit 0 is set, then composition is performed after decomposition. If
bit-1 is set then compatibility (de)composition is used as opposed to
canonical (de)composition. */
- NT_NFD = 0b00,
- NT_NFC = 0b01,
- NT_NFKD = 0b10,
- NT_NFKC = 0b11,
+ NF_NFD = 0b00,
+ NF_NFC = 0b01,
+ NF_NFKD = 0b10,
+ NF_NFKC = 0b11,
};
/* clang-format on */
@@ -45,7 +45,7 @@ size_t u8wnext_human(struct u8view *, struct u8view *);
[[nodiscard]] char8_t *u8upper(size_t *, struct u8view, enum caseflags,
alloc_fn, void *);
[[nodiscard]] char8_t *u8norm(size_t *, struct u8view, alloc_fn, void *,
- enum normtype);
+ enum normform);
/* Encoding-generic macros */
#define ucsgcnt(sv) _Generic((sv), struct u8view: u8gcnt)((sv))
@@ -67,8 +67,8 @@ size_t u8wnext_human(struct u8view *, struct u8view *);
#define ucsupper(dstn, sv, flags, alloc, ctx) \
_Generic((sv), struct u8view: u8upper)((dstn), (sv), (flags), (alloc), \
(ctx))
-#define ucsnorm(dstn, sv, alloc, ctx, nt) \
- _Generic((sv), struct u8view: u8norm)((dstn), (sv), (alloc), (ctx), (nt))
+#define ucsnorm(dstn, sv, alloc, ctx, nf) \
+ _Generic((sv), struct u8view: u8norm)((dstn), (sv), (alloc), (ctx), (nf))
constexpr double U8CASEFOLD_SCALE = 3;
constexpr double U8LOWER_SCALE = 1.5;
diff --git a/lib/unicode/string/u8norm.c b/lib/unicode/string/u8norm.c
index a918479..128a67a 100644
--- a/lib/unicode/string/u8norm.c
+++ b/lib/unicode/string/u8norm.c
@@ -8,7 +8,7 @@
#define BETWEEN(x, y, z) ((x) <= (y) && (y) <= (z))
-static void decomp(char8_t *, size_t *, size_t, rune, enum normtype);
+static void decomp(char8_t *, size_t *, size_t, rune, enum normform);
static void compbuf(char8_t *, size_t *);
/* Computed using a gen/scale-norm.c */
@@ -28,23 +28,23 @@ constexpr int SCNT = LCNT * NCNT;
char8_t *
u8norm(size_t *dstn, struct u8view src, alloc_fn alloc, void *ctx,
- enum normtype nt)
+ enum normform nf)
{
ASSUME(dstn != nullptr);
ASSUME(alloc != nullptr);
- ASSUME(BETWEEN(0, nt, 4));
+ ASSUME(BETWEEN(0, nf, 4));
/* Pre-allocate a buffer with some initial capacity; there is no need to
check for overflow when computing bufsz because alloc() will handle the
overflow error for us. */
- int scale = (nt & 0b10) ? NFKD_SCALE : NFD_SCALE;
+ int scale = (nf & 0b10) ? NFKD_SCALE : NFD_SCALE;
size_t bufsz = src.len * scale;
char8_t *dst = alloc(ctx, nullptr, 0, src.len, scale, alignof(char8_t));
*dstn = 0;
- for (rune ch; ucsnext(&ch, &src) != 0; decomp(dst, dstn, bufsz, ch, nt))
+ for (rune ch; ucsnext(&ch, &src) != 0; decomp(dst, dstn, bufsz, ch, nf))
;
- if (nt & 0b01)
+ if (nf & 0b01)
compbuf(dst, dstn);
return alloc(ctx, dst, src.len, *dstn, 1, alignof(char8_t));
}
@@ -52,7 +52,7 @@ u8norm(size_t *dstn, struct u8view src, alloc_fn alloc, void *ctx,
#define WRITE(ch) *dstn += rtoucs(dst + *dstn, bufsz - *dstn, (ch))
void
-decomp(char8_t *dst, size_t *dstn, size_t bufsz, rune ch, enum normtype nt)
+decomp(char8_t *dst, size_t *dstn, size_t bufsz, rune ch, enum normform nf)
{
if (uprop_get_hst(ch) != HST_NA) {
int si = ch - SBASE;
@@ -68,12 +68,12 @@ decomp(char8_t *dst, size_t *dstn, size_t bufsz, rune ch, enum normtype nt)
WRITE(v);
if (t != TBASE)
WRITE(t);
- } else if (((nt & 0b10) && uprop_get_dt(ch) != DT_NONE)
- || ((nt & 0b10) == 0 && uprop_get_dt(ch) == DT_CAN))
+ } else if (((nf & 0b10) && uprop_get_dt(ch) != DT_NONE)
+ || ((nf & 0b10) == 0 && uprop_get_dt(ch) == DT_CAN))
{
struct rview rv = uprop_get_dm(ch);
for (size_t i = 0; i < rv.len; i++)
- decomp(dst, dstn, bufsz, rv.p[i], nt);
+ decomp(dst, dstn, bufsz, rv.p[i], nf);
} else {
enum uprop_ccc ccc = uprop_get_ccc(ch);
if (ccc == CCC_NR) {
diff --git a/test/_norm-test.h b/test/_norm-test.h
index 8df9f3f..43f8731 100644
--- a/test/_norm-test.h
+++ b/test/_norm-test.h
@@ -85,13 +85,13 @@ test(struct u8view sv, int id)
for (size_t i = 0; i < 5; i++) {
size_t base;
const char *nt = STR(NORMTYPE);
- if (streq(nt, "NT_NFC"))
+ if (streq(nt, "NF_NFC"))
base = i < 3 ? 1 : 3;
- else if (streq(nt, "NT_NFD"))
+ else if (streq(nt, "NF_NFD"))
base = i < 3 ? 2 : 4;
- else if (streq(nt, "NT_NFKC"))
+ else if (streq(nt, "NF_NFKC"))
base = 3;
- else if (streq(nt, "NT_NFKD"))
+ else if (streq(nt, "NF_NFKD"))
base = 4;
else
err("invalid NORMTYPE ‘%s’", nt);
diff --git a/test/norm-nfc-test.c b/test/norm-nfc-test.c
index 176cd69..2d1f089 100644
--- a/test/norm-nfc-test.c
+++ b/test/norm-nfc-test.c
@@ -1,2 +1,2 @@
-#define NORMTYPE NT_NFC
+#define NORMTYPE NF_NFC
#include "_norm-test.h"
diff --git a/test/norm-nfd-test.c b/test/norm-nfd-test.c
index 816bba5..15d67ef 100644
--- a/test/norm-nfd-test.c
+++ b/test/norm-nfd-test.c
@@ -1,2 +1,2 @@
-#define NORMTYPE NT_NFD
+#define NORMTYPE NF_NFD
#include "_norm-test.h"
diff --git a/test/norm-nfkc-test.c b/test/norm-nfkc-test.c
index cddce1c..193da52 100644
--- a/test/norm-nfkc-test.c
+++ b/test/norm-nfkc-test.c
@@ -1,2 +1,2 @@
-#define NORMTYPE NT_NFKC
+#define NORMTYPE NF_NFKC
#include "_norm-test.h"
diff --git a/test/norm-nfkd-test.c b/test/norm-nfkd-test.c
index 34bebca..79feb46 100644
--- a/test/norm-nfkd-test.c
+++ b/test/norm-nfkd-test.c
@@ -1,2 +1,2 @@
-#define NORMTYPE NT_NFKD
+#define NORMTYPE NF_NFKD
#include "_norm-test.h"