Debian Codegraph @

rpython/rlib/fastutf8/src/utf8.h

raw symbols SCIP
1 #pragma once
2
3 #include <unistd.h>
4 #include <stdint.h>
5 #include <stddef.h>
6
7 #ifdef RPYTHON_LL2CTYPES
8 /* only for testing: ll2ctypes sets RPY_EXTERN from the command-line */
9 #ifndef RPY_EXTERN
10 # define RPY_EXTERN RPY_EXPORTED
11 #endif
12
13 #ifdef _WIN32
14 # define RPY_EXPORTED __declspec(dllexport)
15 #else
16 # define RPY_EXPORTED extern __attribute__((visibility("default")))
17 #endif
18
19 #endif
20
21 /**
22 * Returns -1 if the given string is not a valid utf8 encoded string.
23 * Otherwise returns the amount code point in the given string.
24 * len: length in bytes (8-bit)
25 *
26 * The above documentation also applies for several vectorized implementations
27 * found below.
28 *
29 * fu8_count_utf8_codepoints dispatches amongst several
30 * implementations (e.g. seq, SSE4, AVX)
31 */
32 // TODO rename (fu8 prefix)
33 RPY_EXTERN ssize_t fu8_count_utf8_codepoints(const char * utf8, size_t len);
34 RPY_EXTERN ssize_t fu8_count_utf8_codepoints_seq(const char * utf8, size_t len);
35 RPY_EXTERN ssize_t fu8_count_utf8_codepoints_sse4(const char * utf8, size_t len);
36 RPY_EXTERN ssize_t fu8_count_utf8_codepoints_avx(const char * utf8, size_t len);
37
38
39 struct fu8_idxtab;
40
41 /**
42 * Looks up the byte position of the utf8 code point at the index.
43 * Assumptions:
44 *
45 * * utf8 parameter is utf8 encoded, otherwise the result is undefined.
46 * * passing one struct fu8_idxtab instance to several different utf8 strings
47 * yields undefined behaviour
48 *
49 * Return values:
50 *
51 * -1, if the index is out of bounds of utf8
52 * X, where X >= 0. X is the byte postion for the code point at index
53 *
54 * If table is not NULL, this routine builds up a lookup
55 * table to speed up indexing.
56 *
57 */
58 RPY_EXTERN ssize_t fu8_idx2bytepos(size_t index,
59 const uint8_t * utf8, size_t bytelen,
60 size_t cplen,
61 struct fu8_idxtab ** tab);
62 RPY_EXTERN void fu8_free_idxtab(struct fu8_idxtab * t);
63 RPY_EXTERN ssize_t fu8_idx2bytepso_sse4(size_t index,
64 const uint8_t * utf8, size_t len,
65 struct fu8_idxtab ** t);