libgrapheme

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

grapheme_is_character_break.sh (1949B)


      1cat << EOF
      2.Dd ${MAN_DATE}
      3.Dt GRAPHEME_IS_CHARACTER_BREAK 3
      4.Os suckless.org
      5.Sh NAME
      6.Nm grapheme_is_character_break
      7.Nd test for a grapheme cluster break between two codepoints
      8.Sh SYNOPSIS
      9.In grapheme.h
     10.Ft size_t
     11.Fn grapheme_is_character_break "uint_least32_t cp1" "uint_least32_t cp2" "uint_least16_t *state"
     12.Sh DESCRIPTION
     13The
     14.Fn grapheme_is_character_break
     15function determines if there is a grapheme cluster break (see
     16.Xr libgrapheme 7 )
     17between the two codepoints
     18.Va cp1
     19and
     20.Va cp2 .
     21By specification this decision depends on a
     22.Va state
     23that can at most be completely reset after detecting a break and must
     24be reset every time one deviates from sequential processing.
     25.Pp
     26If
     27.Va state
     28is
     29.Dv NULL
     30.Fn grapheme_is_character_break
     31behaves as if it was called with a fully reset state.
     32.Sh RETURN VALUES
     33The
     34.Fn grapheme_is_character_break
     35function returns
     36.Va true
     37if there is a grapheme cluster break between the codepoints
     38.Va cp1
     39and
     40.Va cp2
     41and
     42.Va false
     43if there is not.
     44.Sh EXAMPLES
     45.Bd -literal
     46/* cc (-static) -o example example.c -lgrapheme */
     47#include <grapheme.h>
     48#include <stdint.h>
     49#include <stdio.h>
     50#include <stdlib.h>
     51
     52int
     53main(void)
     54{
     55	uint_least16_t state = 0;
     56	uint_least32_t s1[] = ..., s2[] = ...; /* two input arrays */
     57	size_t i;
     58
     59	for (i = 0; i + 1 < sizeof(s1) / sizeof(*s1); i++) {
     60		if (grapheme_is_character_break(s[i], s[i + 1], &state)) {
     61			printf("break in s1 at offset %zu\n", i);
     62		}
     63	}
     64	memset(&state, 0, sizeof(state)); /* reset state */
     65	for (i = 0; i + 1 < sizeof(s2) / sizeof(*s2); i++) {
     66		if (grapheme_is_character_break(s[i], s[i + 1], &state)) {
     67			printf("break in s2 at offset %zu\n", i);
     68		}
     69	}
     70
     71	return 0;
     72}
     73.Ed
     74.Sh SEE ALSO
     75.Xr grapheme_next_character_break 3 ,
     76.Xr grapheme_next_character_break_utf8 3 ,
     77.Xr libgrapheme 7
     78.Sh STANDARDS
     79.Fn grapheme_is_character_break
     80is compliant with the Unicode ${UNICODE_VERSION} specification.
     81.Sh AUTHORS
     82.An Laslo Hunhold Aq Mt dev@frign.de
     83EOF