libunibreak
8.0
Toggle main menu visibility
Loading...
Searching...
No Matches
src
unibreakdef.h
Go to the documentation of this file.
1
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
2
3
/*
4
* Break processing in a Unicode sequence. Designed to be used in a
5
* generic text renderer.
6
*
7
* Copyright (C) 2015-2026 Wu Yongwei <wuyongwei at gmail dot com>
8
*
9
* This software is provided 'as-is', without any express or implied
10
* warranty. In no event will the author be held liable for any damages
11
* arising from the use of this software.
12
*
13
* Permission is granted to anyone to use this software for any purpose,
14
* including commercial applications, and to alter it and redistribute
15
* it freely, subject to the following restrictions:
16
*
17
* 1. The origin of this software must not be misrepresented; you must
18
* not claim that you wrote the original software. If you use this
19
* software in a product, an acknowledgement in the product
20
* documentation would be appreciated but is not required.
21
* 2. Altered source versions must be plainly marked as such, and must
22
* not be misrepresented as being the original software.
23
* 3. This notice may not be removed or altered from any source
24
* distribution.
25
*/
26
34
35
#ifndef UNIBREAKDEF_H
36
#define UNIBREAKDEF_H
37
38
#include <stdbool.h>
39
#include <stddef.h>
40
#include "
unibreakbase.h
"
41
42
#define ARRAY_LEN(x) (sizeof(x) / sizeof(x[0]))
43
44
#ifdef __cplusplus
45
extern
"C"
{
46
#endif
47
52
#define EOS 0xFFFFFFFF
53
58
typedef
utf32_t
(*
get_next_char_t
)(
const
void
*, size_t,
size_t
*);
59
60
/* Function Prototype */
61
utf32_t
ub_get_next_char_utf8
(
const
void
*sv,
size_t
len,
size_t
*ip);
62
utf32_t
ub_get_next_char_utf16
(
const
void
*sv,
size_t
len,
size_t
*ip);
63
utf32_t
ub_get_next_char_utf32
(
const
void
*sv,
size_t
len,
size_t
*ip);
64
65
inline
const
void
*
ub_bsearch
(
utf32_t
ch,
const
void
*ptr,
size_t
count,
66
size_t
size)
67
{
68
int
min = 0;
69
int
max = (int)(count - 1);;
70
int
mid;
71
72
do
73
{
74
mid = (min + max) / 2;
75
const
unsigned
char
*mid_ptr =
76
(
const
unsigned
char
*)ptr + mid * size;
77
utf32_t
mid_start = *(
const
utf32_t
*)mid_ptr;
78
utf32_t
mid_end = *((
const
utf32_t
*)mid_ptr + 1);
79
80
if
(ch < mid_start)
81
{
82
max = mid - 1;
83
}
84
else
if
(ch > mid_end)
85
{
86
min = mid + 1;
87
}
88
else
89
{
90
return
mid_ptr;
91
}
92
}
while
(min <= max);
93
94
return
NULL;
95
}
96
97
#ifdef __cplusplus
98
}
99
#endif
100
101
#endif
/* UNIBREAKDEF_H */
unibreakbase.h
Header file for common definitions in the libunibreak library.
utf32_t
unsigned int utf32_t
Type for UTF-32 data points.
Definition
unibreakbase.h:49
ub_get_next_char_utf8
utf32_t ub_get_next_char_utf8(const void *sv, size_t len, size_t *ip)
Gets the next Unicode character in a UTF-8 sequence.
Definition
unibreakdef.c:50
ub_get_next_char_utf32
utf32_t ub_get_next_char_utf32(const void *sv, size_t len, size_t *ip)
Gets the next Unicode character in a UTF-32 sequence.
Definition
unibreakdef.c:161
ub_bsearch
const void * ub_bsearch(utf32_t ch, const void *ptr, size_t count, size_t size)
Definition
unibreakdef.h:65
ub_get_next_char_utf16
utf32_t ub_get_next_char_utf16(const void *sv, size_t len, size_t *ip)
Gets the next Unicode character in a UTF-16 sequence.
Definition
unibreakdef.c:119
get_next_char_t
utf32_t(*) get_next_char_t(const void *, size_t, size_t *)
Abstract function interface for ub_get_next_char_utf8, ub_get_next_char_utf16, and ub_get_next_char_u...
Definition
unibreakdef.h:58
Generated by
1.18.0