Loading...
Searching...
No Matches
linebreakdef.h
Go to the documentation of this file.
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/*
* Line breaking in a Unicode sequence. Designed to be used in a
* generic text renderer.
*
* Copyright (C) 2008-2026 Wu Yongwei <wuyongwei at gmail dot com>
* Copyright (C) 2013 Petr Filipsky <philodej at gmail dot com>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the author be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must
* not claim that you wrote the original software. If you use this
* software in a product, an acknowledgement in the product
* documentation would be appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must
* not be misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source
* distribution.
*
* The main reference is Unicode Standard Annex 14 (UAX #14):
* <URL:http://www.unicode.org/reports/tr14/>
*
* When this library was designed, this annex was at Revision 19, for
* Unicode 5.0.0:
* <URL:http://www.unicode.org/reports/tr14/tr14-19.html>
*
* This library has been updated according to Revision 49, for
* Unicode 15.0.0:
* <URL:http://www.unicode.org/reports/tr14/tr14-49.html>
*
* The Unicode Terms of Use are available at
* <URL:http://www.unicode.org/copyright.html>
*/
#ifndef LINEBREAKDEF_H
#define LINEBREAKDEF_H
#include "unibreakdef.h"
#ifndef UB_LANG_FLAGS
#define UB_LANG_FLAGS 1
#endif
enum LineBreakClass
{
/* This is used to signal an error condition. */
LBP_Undefined,
/* The following break classes are treated in the pair table. */
LBP_OP,
LBP_CL,
LBP_CP,
LBP_QU,
LBP_GL,
LBP_NS,
LBP_EX,
LBP_SY,
LBP_IS,
LBP_PR,
LBP_PO,
LBP_NU,
LBP_AL,
LBP_HL,
LBP_ID,
LBP_IN,
LBP_HY,
LBP_BA,
LBP_BB,
LBP_B2,
LBP_ZW,
LBP_CM,
LBP_WJ,
LBP_H2,
LBP_H3,
LBP_JL,
LBP_JV,
LBP_JT,
LBP_RI,
LBP_EB,
LBP_EM,
LBP_ZWJ,
/* The following break class is treated in the pair table, but it is
* not part of Table 2 of UAX #14-37. */
LBP_CB,
/* The following break classes are not treated in the pair table */
LBP_AI,
LBP_BK,
LBP_CJ,
LBP_CR,
LBP_LF,
LBP_NL,
LBP_SA,
LBP_SG,
LBP_SP,
LBP_XX
};
enum Lb25State
{
LB25_NONE,
LB25_PREFIX,
LB25_PREFIXOP,
LB25_NUM,
LB25_NUMCLOSE,
};
enum BreakOutputType
{
LBOT_PER_CODE_UNIT,
LBOT_PER_CODE_POINT
};
struct LineBreakProperties
{
utf32_t start;
utf32_t end;
enum LineBreakClass prop;
};
struct LineBreakPropertiesLang
{
const char *lang;
size_t namelen;
const struct LineBreakProperties *lbp;
};
struct LineBreakContext
{
const char *lang;
const struct LineBreakProperties *lbpLang;
enum LineBreakClass lbcCur;
enum LineBreakClass lbcNew;
enum LineBreakClass lbcLast;
size_t posLast;
#if UB_LANG_FLAGS
bool fLangCjk;
bool fLangStrict;
#endif
bool fLb8aZwj;
bool fLb21aHebrew;
int cLb30aRI;
enum Lb25State eLb25;
size_t posLb25Fixup;
bool fLb25Mark;
};
/* Declarations */
extern const struct LineBreakProperties lb_prop_supplementary[];
extern const unsigned int lb_prop_supplementary_len;
extern const char lb_prop_bmp[];
extern const struct LineBreakPropertiesLang lb_prop_lang_map[];
/* Function Prototype */
void lb_init_break_context(
struct LineBreakContext *lbpCtx,
utf32_t ch,
const char *lang);
int lb_process_next_char(
struct LineBreakContext *lbpCtx,
utf32_t ch);
enum LineBreakClass lb_get_char_class(
const struct LineBreakContext *lbpCtx,
utf32_t ch);
size_t set_linebreaks(
const void *s,
size_t len,
const char *lang,
enum BreakOutputType outputType,
char *brks,
get_next_char_t get_next_char);
#endif /* LINEBREAKDEF_H */
lb_prop_supplementary_len
const unsigned int lb_prop_supplementary_len
Definition linebreakdata.c:711
lb_prop_bmp
const char lb_prop_bmp[]
Line breaking properties for BMP.
Definition linebreakdata.c:715
lb_prop_supplementary
const struct LineBreakProperties lb_prop_supplementary[]
Line breaking properties for supplementary planes.
Definition linebreakdata.c:9
lb_prop_lang_map
const struct LineBreakPropertiesLang lb_prop_lang_map[]
Association data of language-specific line breaking properties with language names.
Definition linebreakdef.c:121
lb_init_break_context
void lb_init_break_context(struct LineBreakContext *lbpCtx, utf32_t ch, const char *lang)
Initializes line breaking context for a given language.
Definition linebreak.c:875
Lb25State
Lb25State
LB25 state for numeric expression context tracking.
Definition linebreakdef.h:126
LB25_PREFIX
@ LB25_PREFIX
Seen PR or PO (prefix).
Definition linebreakdef.h:128
LB25_PREFIXOP
@ LB25_PREFIXOP
Saw (PR|PO) then OP or HY.
Definition linebreakdef.h:129
LB25_NUM
@ LB25_NUM
Inside NU (NU|SY|IS)*.
Definition linebreakdef.h:130
LB25_NUMCLOSE
@ LB25_NUMCLOSE
Saw NU (NU|SY|IS)* (CL|CP).
Definition linebreakdef.h:131
LB25_NONE
@ LB25_NONE
Not in numeric expression.
Definition linebreakdef.h:127
lb_get_char_class
enum LineBreakClass lb_get_char_class(const struct LineBreakContext *lbpCtx, utf32_t ch)
Gets the line breaking class of a character for a line breaking context.
Definition linebreak.c:970
LineBreakClass
LineBreakClass
Line break classes.
Definition linebreakdef.h:66
LBP_WJ
@ LBP_WJ
Word joiner.
Definition linebreakdef.h:93
LBP_GL
@ LBP_GL
Glue.
Definition linebreakdef.h:75
LBP_CL
@ LBP_CL
Closing punctuation.
Definition linebreakdef.h:72
LBP_NS
@ LBP_NS
Non-starters.
Definition linebreakdef.h:76
LBP_RI
@ LBP_RI
Regional indicator.
Definition linebreakdef.h:99
LBP_ID
@ LBP_ID
Ideographic.
Definition linebreakdef.h:85
LBP_JL
@ LBP_JL
Hangul L Jamo.
Definition linebreakdef.h:96
LBP_SA
@ LBP_SA
South-East Asian.
Definition linebreakdef.h:115
LBP_B2
@ LBP_B2
Break on either side (but not pair).
Definition linebreakdef.h:90
LBP_SY
@ LBP_SY
Symbols allowing break after.
Definition linebreakdef.h:78
LBP_CB
@ LBP_CB
Contingent break.
Definition linebreakdef.h:106
LBP_XX
@ LBP_XX
Unknown.
Definition linebreakdef.h:118
LBP_EM
@ LBP_EM
Emoji modifier.
Definition linebreakdef.h:101
LBP_CJ
@ LBP_CJ
Conditional Japanese starter.
Definition linebreakdef.h:111
LBP_ZWJ
@ LBP_ZWJ
Zero width joiner.
Definition linebreakdef.h:102
LBP_EX
@ LBP_EX
Exclamation/Interrogation.
Definition linebreakdef.h:77
LBP_SP
@ LBP_SP
Space.
Definition linebreakdef.h:117
LBP_JV
@ LBP_JV
Hangul V Jamo.
Definition linebreakdef.h:97
LBP_JT
@ LBP_JT
Hangul T Jamo.
Definition linebreakdef.h:98
LBP_BK
@ LBP_BK
Break (mandatory).
Definition linebreakdef.h:110
LBP_HY
@ LBP_HY
Hyphen.
Definition linebreakdef.h:87
LBP_NU
@ LBP_NU
Numeric.
Definition linebreakdef.h:82
LBP_BA
@ LBP_BA
Break after.
Definition linebreakdef.h:88
LBP_H2
@ LBP_H2
Hangul LV.
Definition linebreakdef.h:94
LBP_EB
@ LBP_EB
Emoji base.
Definition linebreakdef.h:100
LBP_CR
@ LBP_CR
Carriage return.
Definition linebreakdef.h:112
LBP_Undefined
@ LBP_Undefined
Undefined.
Definition linebreakdef.h:68
LBP_LF
@ LBP_LF
Line feed.
Definition linebreakdef.h:113
LBP_PR
@ LBP_PR
Prefix.
Definition linebreakdef.h:80
LBP_BB
@ LBP_BB
Break before.
Definition linebreakdef.h:89
LBP_IS
@ LBP_IS
Infix separator.
Definition linebreakdef.h:79
LBP_AL
@ LBP_AL
Alphabetic.
Definition linebreakdef.h:83
LBP_ZW
@ LBP_ZW
Zero-width space.
Definition linebreakdef.h:91
LBP_HL
@ LBP_HL
Hebrew letter.
Definition linebreakdef.h:84
LBP_QU
@ LBP_QU
Ambiguous quotation.
Definition linebreakdef.h:74
LBP_CP
@ LBP_CP
Closing parenthesis.
Definition linebreakdef.h:73
LBP_PO
@ LBP_PO
Postfix.
Definition linebreakdef.h:81
LBP_AI
@ LBP_AI
Ambiguous (alphabetic or ideograph).
Definition linebreakdef.h:109
LBP_OP
@ LBP_OP
Opening punctuation.
Definition linebreakdef.h:71
LBP_NL
@ LBP_NL
Next line.
Definition linebreakdef.h:114
LBP_SG
@ LBP_SG
Surrogates.
Definition linebreakdef.h:116
LBP_CM
@ LBP_CM
Combining marks.
Definition linebreakdef.h:92
LBP_IN
@ LBP_IN
Inseparable characters.
Definition linebreakdef.h:86
LBP_H3
@ LBP_H3
Hangul LVT.
Definition linebreakdef.h:95
set_linebreaks
size_t set_linebreaks(const void *s, size_t len, const char *lang, enum BreakOutputType outputType, char *brks, get_next_char_t get_next_char)
Sets the line breaking information for a generic input string.
Definition linebreak.c:1010
lb_process_next_char
int lb_process_next_char(struct LineBreakContext *lbpCtx, utf32_t ch)
Updates LineBreakingContext for the next codepoint and returns the detected break.
Definition linebreak.c:916
BreakOutputType
BreakOutputType
Definition linebreakdef.h:135
LBOT_PER_CODE_UNIT
@ LBOT_PER_CODE_UNIT
Definition linebreakdef.h:136
LBOT_PER_CODE_POINT
@ LBOT_PER_CODE_POINT
Definition linebreakdef.h:137
LineBreakContext
Context representing internal state of the line breaking algorithm.
Definition linebreakdef.h:167
LineBreakContext::eLb25
enum Lb25State eLb25
LB25 state for numeric expression.
Definition linebreakdef.h:182
LineBreakContext::fLb8aZwj
bool fLb8aZwj
Flag for ZWJ (LB8a).
Definition linebreakdef.h:179
LineBreakContext::posLast
size_t posLast
Last position in input string.
Definition linebreakdef.h:174
LineBreakContext::lbcCur
enum LineBreakClass lbcCur
Breaking class of current codepoint.
Definition linebreakdef.h:171
LineBreakContext::fLb25Mark
bool fLb25Mark
Flag for pending fixup.
Definition linebreakdef.h:184
LineBreakContext::fLangStrict
bool fLangStrict
-strict suffix
Definition linebreakdef.h:177
LineBreakContext::cLb30aRI
int cLb30aRI
Count of RI characters (LB30a).
Definition linebreakdef.h:181
LineBreakContext::fLangCjk
bool fLangCjk
zh/ja/ko language
Definition linebreakdef.h:176
LineBreakContext::lbcNew
enum LineBreakClass lbcNew
Breaking class of next codepoint.
Definition linebreakdef.h:172
LineBreakContext::fLb21aHebrew
bool fLb21aHebrew
Flag for Hebrew letters (LB21a).
Definition linebreakdef.h:180
LineBreakContext::lbcLast
enum LineBreakClass lbcLast
Breaking class of last codepoint.
Definition linebreakdef.h:173
LineBreakContext::lbpLang
const struct LineBreakProperties * lbpLang
Pointer to LineBreakProperties.
Definition linebreakdef.h:169
LineBreakContext::posLb25Fixup
size_t posLb25Fixup
Position to fix for LB25.
Definition linebreakdef.h:183
LineBreakContext::lang
const char * lang
Language name.
Definition linebreakdef.h:168
LineBreakPropertiesLang
Struct for association of language-specific line breaking properties with language names.
Definition linebreakdef.h:156
LineBreakPropertiesLang::namelen
size_t namelen
Length of name to match.
Definition linebreakdef.h:158
LineBreakPropertiesLang::lbp
const struct LineBreakProperties * lbp
Pointer to associated data.
Definition linebreakdef.h:159
LineBreakPropertiesLang::lang
const char * lang
Language name.
Definition linebreakdef.h:157
LineBreakProperties
Struct for entries of line break properties.
Definition linebreakdef.h:145
LineBreakProperties::start
utf32_t start
Start codepoint.
Definition linebreakdef.h:146
LineBreakProperties::prop
enum LineBreakClass prop
The line breaking property.
Definition linebreakdef.h:148
LineBreakProperties::end
utf32_t end
End codepoint, inclusive.
Definition linebreakdef.h:147
utf32_t
unsigned int utf32_t
Type for UTF-32 data points.
Definition unibreakbase.h:49
unibreakdef.h
Header file for private definitions in the libunibreak library.
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:67