index.md (2256B)
1 GRAPHEME\_NEXT\_LINE\_BREAK\_UTF8(3) - Library Functions Manual 2 3 # NAME 4 5 **grapheme\_next\_line\_break\_utf8** - determine byte-offset to next possible line break 6 7 # SYNOPSIS 8 9 **#include <grapheme.h>** 10 11 *size\_t* 12 **grapheme\_next\_line\_break\_utf8**(*const char \*str*, *size\_t len*); 13 14 # DESCRIPTION 15 16 The 17 **grapheme\_next\_line\_break\_utf8**() 18 function computes the offset (in bytes) to the next possible line 19 break (see 20 libgrapheme(7)) 21 in the UTF-8-encoded string 22 *str* 23 of length 24 *len*. 25 26 If 27 *len* 28 is set to 29 `SIZE_MAX` 30 (stdint.h is already included by grapheme.h) the string 31 *str* 32 is interpreted to be NUL-terminated and processing stops when 33 a NUL-byte is encountered. 34 35 For non-UTF-8 input 36 data 37 grapheme\_next\_line\_break(3) 38 can be used instead. 39 40 # RETURN VALUES 41 42 The 43 **grapheme\_next\_line\_break\_utf8**() 44 function returns the offset (in bytes) to the next possible line 45 break in 46 *str* 47 or 0 if 48 *str* 49 is 50 `NULL`. 51 52 # EXAMPLES 53 54 /* cc (-static) -o example example.c -lgrapheme */ 55 #include <grapheme.h> 56 #include <stdint.h> 57 #include <stdio.h> 58 59 int 60 main(void) 61 { 62 /* UTF-8 encoded input */ 63 char *s = "T\xC3\xABst \xF0\x9F\x91\xA8\xE2\x80\x8D\xF0" 64 "\x9F\x91\xA9\xE2\x80\x8D\xF0\x9F\x91\xA6 \xF0" 65 "\x9F\x87\xBA\xF0\x9F\x87\xB8 \xE0\xA4\xA8\xE0" 66 "\xA5\x80 \xE0\xAE\xA8\xE0\xAE\xBF!"; 67 size_t ret, len, off; 68 69 printf("Input: \"%s\"\n", s); 70 71 /* print each possible line with byte-length */ 72 printf("possible lines in NUL-delimited input:\n"); 73 for (off = 0; s[off] != '\0'; off += ret) { 74 ret = grapheme_next_line_break_utf8(s + off, SIZE_MAX); 75 printf("%2zu bytes | %.*s\n", ret, (int)ret, s + off); 76 } 77 printf("\n"); 78 79 /* do the same, but this time string is length-delimited */ 80 len = 17; 81 printf("possible lines in input delimited to %zu bytes:\n", len); 82 for (off = 0; off < len; off += ret) { 83 ret = grapheme_next_line_break_utf8(s + off, len - off); 84 printf("%2zu bytes | %.*s\n", ret, (int)ret, s + off); 85 } 86 87 return 0; 88 } 89 90 # SEE ALSO 91 92 grapheme\_next\_line\_break(3), 93 libgrapheme(7) 94 95 # STANDARDS 96 97 **grapheme\_next\_line\_break\_utf8**() 98 is compliant with the Unicode 15.0.0 specification. 99 100 # AUTHORS 101 102 Laslo Hunhold ([dev@frign.de](mailto:dev@frign.de)) 103 104 suckless.org - 2022-10-06