libgrapheme

unicode string library
git clone git://git.suckless.org/libgrapheme
Log | Files | Refs | README | LICENSE

commit fdfcc49755f22074116fd52765bea1a60d3539ba
parent 82b85a60b3a334c928aa22de2555a55367bf739d
Author: Laslo Hunhold <dev@frign.de>
Date:   Sat, 18 Dec 2021 13:13:37 +0100

Rename GRAPHEME_SEGMENTATION_STATE to GRAPHEME_STATE

The name was getting a bit long and the user doesn't really have to
care about the fact it's specifically a segmentation state. If we,
for any reason, require another state type, we could simply define
a union accordingly:

typedef union grapheme_internal_state {
	struct grapheme_internal_segmentation_state {
		...
	} segmentation;
	struct grapheme_internal_whatever_state {
		...
	} whatever;
} GRAPHEME_STATE;

This would not change the outside behaviour (given we defined
GRAPHEME_STATE as an opaque state), but we guarantee that

   GRAPHEME_STATE state = { 0 };

and

   memset(&state, 0, sizeof(state));

continue to work.

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

Diffstat:
Mgrapheme.h | 5++---
Mman/grapheme_character_isbreak.3 | 4++--
Msrc/character.c | 5++---
Mtest/character-performance.c | 2+-
Mtest/character.c | 2+-
5 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/grapheme.h b/grapheme.h @@ -15,14 +15,13 @@ typedef struct grapheme_internal_segmentation_state { struct grapheme_internal_heisenstate a; struct grapheme_internal_heisenstate b; uint_least16_t flags; -} GRAPHEME_SEGMENTATION_STATE; +} GRAPHEME_STATE; #define GRAPHEME_INVALID_CODE_POINT UINT32_C(0xFFFD) size_t grapheme_character_nextbreak(const char *); -bool grapheme_character_isbreak(uint_least32_t, uint_least32_t, - GRAPHEME_SEGMENTATION_STATE *); +bool grapheme_character_isbreak(uint_least32_t, uint_least32_t, GRAPHEME_STATE *); size_t grapheme_utf8_decode(const char *, size_t, uint_least32_t *); size_t grapheme_utf8_encode(uint_least32_t, char *, size_t); diff --git a/man/grapheme_character_isbreak.3 b/man/grapheme_character_isbreak.3 @@ -7,7 +7,7 @@ .Sh SYNOPSIS .In grapheme.h .Ft size_t -.Fn grapheme_character_isbreak "uint_least32_t cp1" "uint_least32_t cp2" "GRAPHEME_SEGMENTATION_STATE *state" +.Fn grapheme_character_isbreak "uint_least32_t cp1" "uint_least32_t cp2" "GRAPHEME_STATE *state" .Sh DESCRIPTION The .Fn grapheme_character_isbreak @@ -51,7 +51,7 @@ if there is not. int main(void) { - GRAPHEME_SEGMENTATION_STATE state = { 0 }; + GRAPHEME_STATE state = { 0 }; uint_least32_t s1[] = ..., s2[] = ...; /* two input arrays */ size_t i; diff --git a/src/character.c b/src/character.c @@ -14,8 +14,7 @@ enum { }; bool -grapheme_character_isbreak(uint_least32_t a, uint_least32_t b, - GRAPHEME_SEGMENTATION_STATE *state) +grapheme_character_isbreak(uint_least32_t a, uint_least32_t b, GRAPHEME_STATE *state) { struct grapheme_internal_heisenstate *p[2] = { 0 }; uint_least16_t flags = 0; @@ -184,7 +183,7 @@ grapheme_character_nextbreak(const char *str) { uint_least32_t cp0, cp1; size_t ret, len = 0; - GRAPHEME_SEGMENTATION_STATE state = { 0 }; + GRAPHEME_STATE state = { 0 }; if (str == NULL) { return 0; diff --git a/test/character-performance.c b/test/character-performance.c @@ -17,7 +17,7 @@ main(int argc, char *argv[]) struct timespec start, end; size_t i, j, bufsiz, off; uint32_t *buf; - GRAPHEME_SEGMENTATION_STATE state; + GRAPHEME_STATE state; double cp_per_sec; (void)argc; diff --git a/test/character.c b/test/character.c @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) { - GRAPHEME_SEGMENTATION_STATE state; + GRAPHEME_STATE state; size_t i, j, k, len, failed; (void)argc;