| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
//! Line breaking implementation for [`SegmenterBreakLineV3`] data, i.e. Unicode 17.0.0. |
| 6 |
//! |
| 7 |
//! The implementation for [`SegmenterBreakLineV1`] data (Unicode 15.1.0) lives in [`crate::line`] |
| 8 |
//! and is retained so that data generated by older versions of ICU4X keeps working. The two |
| 9 |
//! implementations don't share code: the property values in the data, and the rules that consume |
| 10 |
//! them, changed in incompatible ways between the two Unicode versions. |
| 11 |
|
| 12 |
use super::{LineBreakStrictness, LineBreakWordOption, ResolvedLineBreakOptions}; |
| 13 |
use crate::complex::*; |
| 14 |
use crate::provider::*; |
| 15 |
use crate::scaffold::*; |
| 16 |
use alloc::string::String; |
| 17 |
use alloc::vec; |
| 18 |
use alloc::vec::Vec; |
| 19 |
use core::char; |
| 20 |
|
| 21 |
#[allow(dead_code)] |
| 22 |
#[doc(hidden)] |
| 23 |
impl RuleBreakData<'_> { |
| 24 |
pub const LINE_V3_PROPERTY_AI: u8 = 1; |
| 25 |
pub const LINE_V3_PROPERTY_AI_EASTASIAN: u8 = 2; |
| 26 |
pub const LINE_V3_PROPERTY_AK: u8 = 3; |
| 27 |
pub const LINE_V3_PROPERTY_AL: u8 = 4; |
| 28 |
pub const LINE_V3_PROPERTY_AL_DOTTED_CIRCLE: u8 = 5; |
| 29 |
pub const LINE_V3_PROPERTY_AL_EASTASIAN: u8 = 6; |
| 30 |
pub const LINE_V3_PROPERTY_AP: u8 = 7; |
| 31 |
pub const LINE_V3_PROPERTY_AS: u8 = 8; |
| 32 |
pub const LINE_V3_PROPERTY_B2: u8 = 9; |
| 33 |
pub const LINE_V3_PROPERTY_BA: u8 = 10; |
| 34 |
pub const LINE_V3_PROPERTY_BA_EASTASIAN: u8 = 11; |
| 35 |
pub const LINE_V3_PROPERTY_BB: u8 = 12; |
| 36 |
pub const LINE_V3_PROPERTY_BK: u8 = 13; |
| 37 |
pub const LINE_V3_PROPERTY_CB: u8 = 14; |
| 38 |
pub const LINE_V3_PROPERTY_CJ: u8 = 15; |
| 39 |
pub const LINE_V3_PROPERTY_CL: u8 = 16; |
| 40 |
pub const LINE_V3_PROPERTY_CL_EASTASIAN: u8 = 17; |
| 41 |
pub const LINE_V3_PROPERTY_CM: u8 = 18; |
| 42 |
pub const LINE_V3_PROPERTY_CM_EASTASIAN: u8 = 19; |
| 43 |
pub const LINE_V3_PROPERTY_CP: u8 = 20; |
| 44 |
pub const LINE_V3_PROPERTY_CR: u8 = 21; |
| 45 |
pub const LINE_V3_PROPERTY_EB: u8 = 22; |
| 46 |
pub const LINE_V3_PROPERTY_EB_EASTASIAN: u8 = 23; |
| 47 |
pub const LINE_V3_PROPERTY_EM: u8 = 24; |
| 48 |
pub const LINE_V3_PROPERTY_EX: u8 = 25; |
| 49 |
pub const LINE_V3_PROPERTY_EX_EASTASIAN: u8 = 26; |
| 50 |
pub const LINE_V3_PROPERTY_GL: u8 = 27; |
| 51 |
pub const LINE_V3_PROPERTY_GL_EASTASIAN: u8 = 28; |
| 52 |
pub const LINE_V3_PROPERTY_H2: u8 = 29; |
| 53 |
pub const LINE_V3_PROPERTY_H3: u8 = 30; |
| 54 |
pub const LINE_V3_PROPERTY_HH: u8 = 31; |
| 55 |
pub const LINE_V3_PROPERTY_HL: u8 = 32; |
| 56 |
pub const LINE_V3_PROPERTY_HY: u8 = 33; |
| 57 |
pub const LINE_V3_PROPERTY_ID: u8 = 34; |
| 58 |
pub const LINE_V3_PROPERTY_ID_CN: u8 = 35; |
| 59 |
pub const LINE_V3_PROPERTY_ID_EASTASIAN: u8 = 36; |
| 60 |
pub const LINE_V3_PROPERTY_IN: u8 = 37; |
| 61 |
pub const LINE_V3_PROPERTY_IN_EASTASIAN: u8 = 38; |
| 62 |
pub const LINE_V3_PROPERTY_IS: u8 = 39; |
| 63 |
pub const LINE_V3_PROPERTY_JL: u8 = 40; |
| 64 |
pub const LINE_V3_PROPERTY_JT: u8 = 41; |
| 65 |
pub const LINE_V3_PROPERTY_JV: u8 = 42; |
| 66 |
pub const LINE_V3_PROPERTY_LF: u8 = 43; |
| 67 |
pub const LINE_V3_PROPERTY_NL: u8 = 44; |
| 68 |
pub const LINE_V3_PROPERTY_NS: u8 = 45; |
| 69 |
pub const LINE_V3_PROPERTY_NS_EASTASIAN: u8 = 46; |
| 70 |
pub const LINE_V3_PROPERTY_NU: u8 = 47; |
| 71 |
pub const LINE_V3_PROPERTY_OP: u8 = 48; |
| 72 |
pub const LINE_V3_PROPERTY_OP_EASTASIAN: u8 = 49; |
| 73 |
pub const LINE_V3_PROPERTY_PO: u8 = 50; |
| 74 |
pub const LINE_V3_PROPERTY_PO_EASTASIAN: u8 = 51; |
| 75 |
pub const LINE_V3_PROPERTY_PR: u8 = 52; |
| 76 |
pub const LINE_V3_PROPERTY_PR_EASTASIAN: u8 = 53; |
| 77 |
pub const LINE_V3_PROPERTY_QU: u8 = 54; |
| 78 |
pub const LINE_V3_PROPERTY_QU_PF: u8 = 55; |
| 79 |
pub const LINE_V3_PROPERTY_QU_PI: u8 = 56; |
| 80 |
pub const LINE_V3_PROPERTY_RI: u8 = 57; |
| 81 |
pub const LINE_V3_PROPERTY_SA: u8 = 58; |
| 82 |
pub const LINE_V3_PROPERTY_SA_MC_MN: u8 = 59; |
| 83 |
pub const LINE_V3_PROPERTY_SP: u8 = 60; |
| 84 |
pub const LINE_V3_PROPERTY_SY: u8 = 61; |
| 85 |
pub const LINE_V3_PROPERTY_VF: u8 = 62; |
| 86 |
pub const LINE_V3_PROPERTY_VI: u8 = 63; |
| 87 |
pub const LINE_V3_PROPERTY_WJ: u8 = 64; |
| 88 |
pub const LINE_V3_PROPERTY_XX: u8 = 65; |
| 89 |
pub const LINE_V3_PROPERTY_XX_EXTPICT: u8 = 66; |
| 90 |
pub const LINE_V3_PROPERTY_ZW: u8 = 67; |
| 91 |
pub const LINE_V3_PROPERTY_ZWJ: u8 = 68; |
| 92 |
} |
| 93 |
|
| 94 |
fn is_break_utf32_by_normal(codepoint: u32, ja_zh: bool) -> bool { |
| 95 |
matches!(codepoint, 0x301C | 0x30A0 if ja_zh) |
| 96 |
} |
| 97 |
|
| 98 |
#[inline] |
| 99 |
fn is_break_utf32_by_loose( |
| 100 |
left_codepoint: u32, |
| 101 |
right_codepoint: u32, |
| 102 |
left_prop: u8, |
| 103 |
right_prop: u8, |
| 104 |
ja_zh: bool, |
| 105 |
) -> Option<bool> { |
| 106 |
Some( |
| 107 |
match (right_prop, right_codepoint, left_prop, left_codepoint) { |
| 108 |
// breaks before hyphens |
| 109 |
( |
| 110 |
_, |
| 111 |
0x2010 | 0x2013, |
| 112 |
RuleBreakData::LINE_V3_PROPERTY_ID | RuleBreakData::LINE_V3_PROPERTY_ID_EASTASIAN, |
| 113 |
_, |
| 114 |
) => true, |
| 115 |
// breaks before certain CJK hyphen-like characters |
| 116 |
( |
| 117 |
RuleBreakData::LINE_V3_PROPERTY_NS | RuleBreakData::LINE_V3_PROPERTY_NS_EASTASIAN, |
| 118 |
0x301C | 0x30A0, |
| 119 |
_, |
| 120 |
_, |
| 121 |
) => ja_zh, |
| 122 |
// breaks before iteration marks |
| 123 |
( |
| 124 |
RuleBreakData::LINE_V3_PROPERTY_NS | RuleBreakData::LINE_V3_PROPERTY_NS_EASTASIAN, |
| 125 |
0x3005 | 0x303B | 0x309D | 0x309E | 0x30FD | 0x30FE, |
| 126 |
_, |
| 127 |
_, |
| 128 |
) => true, |
| 129 |
// breaks before certain centered punctuation marks: |
| 130 |
( |
| 131 |
RuleBreakData::LINE_V3_PROPERTY_NS | RuleBreakData::LINE_V3_PROPERTY_NS_EASTASIAN, |
| 132 |
0x30FB | 0xFF1A | 0xFF1B | 0xFF65 | 0x203C | 0x2047..=0x2049, |
| 133 |
_, |
| 134 |
_, |
| 135 |
) => ja_zh, |
| 136 |
// breaks between inseparable characters such as U+2025, U+2026 i.e. characters with the Unicode Line Break property IN |
| 137 |
( |
| 138 |
RuleBreakData::LINE_V3_PROPERTY_IN | RuleBreakData::LINE_V3_PROPERTY_IN_EASTASIAN, |
| 139 |
_, |
| 140 |
RuleBreakData::LINE_V3_PROPERTY_IN | RuleBreakData::LINE_V3_PROPERTY_IN_EASTASIAN, |
| 141 |
_, |
| 142 |
) => true, |
| 143 |
// breaks before certain centered punctuation marks: |
| 144 |
( |
| 145 |
RuleBreakData::LINE_V3_PROPERTY_EX | RuleBreakData::LINE_V3_PROPERTY_EX_EASTASIAN, |
| 146 |
0xFF01 | 0xFF1F, |
| 147 |
_, |
| 148 |
_, |
| 149 |
) => ja_zh, |
| 150 |
// breaks before suffixes: |
| 151 |
// Characters with the Unicode Line Break property PO and the East Asian Width property |
| 152 |
(RuleBreakData::LINE_V3_PROPERTY_PO_EASTASIAN, _, _, _) => ja_zh, |
| 153 |
( |
| 154 |
RuleBreakData::LINE_V3_PROPERTY_PO, |
| 155 |
0x00B0 | 0x2030 | 0x2032 | 0x2033 | 0x2035 | 0x2103 | 0x2109, |
| 156 |
_, |
| 157 |
_, |
| 158 |
) => ja_zh, |
| 159 |
// breaks after prefixes: |
| 160 |
// Characters with the Unicode Line Break property PR and the East Asian Width property |
| 161 |
(_, _, RuleBreakData::LINE_V3_PROPERTY_PR_EASTASIAN, _) => ja_zh, |
| 162 |
// Ambiguous characters should be CJK |
| 163 |
(_, _, RuleBreakData::LINE_V3_PROPERTY_PR, 0x00A4 | 0x00B1 | 0x20AC | 0x2116) => ja_zh, |
| 164 |
_ => return None, |
| 165 |
}, |
| 166 |
) |
| 167 |
} |
| 168 |
|
| 169 |
fn is_complex_rule(property: u8) -> bool { |
| 170 |
matches!( |
| 171 |
property, |
| 172 |
RuleBreakData::LINE_V3_PROPERTY_SA | RuleBreakData::LINE_V3_PROPERTY_SA_MC_MN |
| 173 |
) |
| 174 |
} |
| 175 |
|
| 176 |
#[derive(Debug)] |
| 177 |
pub(super) struct LineBreakIteratorV3<'data, 's, Y: RuleBreakType> { |
| 178 |
iter: Y::IterAttr<'s>, |
| 179 |
len: usize, |
| 180 |
current_pos_data: Option<(usize, Y::CharType)>, |
| 181 |
result_cache: Vec<usize>, |
| 182 |
data: &'data RuleBreakData<'data>, |
| 183 |
options: ResolvedLineBreakOptions, |
| 184 |
complex: ComplexPayloadsBorrowed<'data>, |
| 185 |
// Should return None if there is no complex handling |
| 186 |
handle_complex: HandleComplex<'data, 's, Y>, |
| 187 |
} |
| 188 |
|
| 189 |
type HandleComplex<'data, 's, Y> = |
| 190 |
fn(&mut LineBreakIteratorV3<'data, 's, Y>, <Y as RuleBreakType>::CharType) -> Option<usize>; |
| 191 |
|
| 192 |
impl<'data, 's, Y: RuleBreakType> LineBreakIteratorV3<'data, 's, Y> { |
| 193 |
pub(super) fn new( |
| 194 |
iter: Y::IterAttr<'s>, |
| 195 |
len: usize, |
| 196 |
data: &'data RuleBreakData<'data>, |
| 197 |
options: ResolvedLineBreakOptions, |
| 198 |
complex: ComplexPayloadsBorrowed<'data>, |
| 199 |
handle_complex: HandleComplex<'data, 's, Y>, |
| 200 |
) -> Self { |
| 201 |
Self { |
| 202 |
iter, |
| 203 |
len, |
| 204 |
current_pos_data: None, |
| 205 |
result_cache: Vec::new(), |
| 206 |
data, |
| 207 |
options, |
| 208 |
complex, |
| 209 |
handle_complex, |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
impl<Y: RuleBreakType> Iterator for LineBreakIteratorV3<'_, '_, Y> { |
| 215 |
type Item = usize; |
| 216 |
|
| 217 |
fn next(&mut self) -> Option<Self::Item> { |
| 218 |
if self.options.strictness == LineBreakStrictness::Anywhere { |
| 219 |
use crate::grapheme::*; |
| 220 |
let mut grapheme_iter = |
| 221 |
GraphemeClusterBreakIterator(GraphemeClusterBreakIteratorInner::V1( |
| 222 |
crate::rule_segmenter_v1::RuleBreakIterator { |
| 223 |
iter: self.iter.clone(), |
| 224 |
len: self.len, |
| 225 |
current_pos_data: self.current_pos_data, |
| 226 |
data: match self.complex.grapheme.0 { |
| 227 |
GraphemeClusterSegmenterBorrowedInner::V1(data) => data, |
| 228 |
#[cfg(feature = "unstable")] |
| 229 |
GraphemeClusterSegmenterBorrowedInner::V2(_) => unreachable!(), |
| 230 |
}, |
| 231 |
result_cache: Default::default(), |
| 232 |
complex: None, |
| 233 |
boundary_property: 0, |
| 234 |
locale_override: None, |
| 235 |
handle_complex: crate::rule_segmenter_v1::empty_handle_complex::<Y>, |
| 236 |
}, |
| 237 |
)); |
| 238 |
let r = grapheme_iter.next(); |
| 239 |
#[cfg_attr(not(feature = "unstable"), allow(irrefutable_let_patterns))] |
| 240 |
let GraphemeClusterBreakIterator(GraphemeClusterBreakIteratorInner::V1(grapheme_iter)) = |
| 241 |
grapheme_iter |
| 242 |
else { |
| 243 |
unreachable!(); |
| 244 |
}; |
| 245 |
self.iter = grapheme_iter.iter; |
| 246 |
self.len = grapheme_iter.len; |
| 247 |
self.current_pos_data = grapheme_iter.current_pos_data; |
| 248 |
return r; |
| 249 |
} |
| 250 |
|
| 251 |
match self.check_eof() { |
| 252 |
StringBoundaryPosType::Start => return Some(0), |
| 253 |
StringBoundaryPosType::End => return None, |
| 254 |
_ => (), |
| 255 |
} |
| 256 |
|
| 257 |
// If we have break point cache by previous run, return this result |
| 258 |
if let Some(&first_pos) = self.result_cache.first() { |
| 259 |
let mut i = 0; |
| 260 |
loop { |
| 261 |
if i == first_pos { |
| 262 |
self.result_cache = self.result_cache.iter().skip(1).map(|r| r - i).collect(); |
| 263 |
return self.get_current_position(); |
| 264 |
} |
| 265 |
i += self.get_current_codepoint().map_or(0, Y::char_len); |
| 266 |
self.advance_iter(); |
| 267 |
if self.is_eof() { |
| 268 |
self.result_cache.clear(); |
| 269 |
return Some(self.len); |
| 270 |
} |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
// The state prior to a sequence of CM and ZWJ affected by rule LB9. |
| 275 |
let mut lb9_left: Option<u8> = None; |
| 276 |
// Whether LB9 was applied to a ZWJ, so that breaks at the current |
| 277 |
// position must be suppressed. |
| 278 |
let mut lb8a_after_lb9 = false; |
| 279 |
|
| 280 |
let mut lb14 = false; |
| 281 |
|
| 282 |
'a: loop { |
| 283 |
debug_assert!(!self.is_eof()); |
| 284 |
|
| 285 |
let left_codepoint = self.get_current_codepoint()?; |
| 286 |
let mut left_prop = |
| 287 |
lb9_left.unwrap_or_else(|| self.get_linebreak_property(left_codepoint)); |
| 288 |
let after_zwj = lb8a_after_lb9 |
| 289 |
|| (lb9_left.is_none() && left_prop == RuleBreakData::LINE_V3_PROPERTY_ZWJ); |
| 290 |
let is_sot = self.get_current_position().unwrap_or(0) == 0; |
| 291 |
if is_sot { |
| 292 |
// LB19a/LB20a hack for SOT then. |
| 293 |
if matches!( |
| 294 |
left_prop, |
| 295 |
RuleBreakData::LINE_V3_PROPERTY_HY |
| 296 |
| RuleBreakData::LINE_V3_PROPERTY_HH |
| 297 |
| RuleBreakData::LINE_V3_PROPERTY_QU_PI |
| 298 |
| RuleBreakData::LINE_V3_PROPERTY_QU_PF |
| 299 |
| RuleBreakData::LINE_V3_PROPERTY_QU |
| 300 |
) { |
| 301 |
left_prop = match self |
| 302 |
.data |
| 303 |
.get_break_state_from_table(self.data.sot_property, left_prop) |
| 304 |
{ |
| 305 |
BreakState::Index(index) => index, |
| 306 |
_ => left_prop, |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
self.advance_iter(); |
| 312 |
let Some(right_codepoint) = self.get_current_codepoint() else { |
| 313 |
return Some(self.len); |
| 314 |
}; |
| 315 |
|
| 316 |
let right_prop = self.get_linebreak_property(right_codepoint); |
| 317 |
|
| 318 |
if Y::CAN_CONTAIN_SA |
| 319 |
&& is_complex_rule(left_prop) |
| 320 |
&& right_prop == RuleBreakData::LINE_V3_PROPERTY_SA_MC_MN |
| 321 |
&& self.options.strictness != LineBreakStrictness::Anywhere |
| 322 |
{ |
| 323 |
// Use dictionary or LSTM instead of rules |
| 324 |
lb9_left = None; |
| 325 |
lb8a_after_lb9 = false; |
| 326 |
} else if (matches!( |
| 327 |
right_prop, |
| 328 |
RuleBreakData::LINE_V3_PROPERTY_CM |
| 329 |
| RuleBreakData::LINE_V3_PROPERTY_CM_EASTASIAN |
| 330 |
| RuleBreakData::LINE_V3_PROPERTY_SA_MC_MN |
| 331 |
) || (right_prop == RuleBreakData::LINE_V3_PROPERTY_ZWJ |
| 332 |
&& self.options.strictness != LineBreakStrictness::Anywhere)) |
| 333 |
&& !matches!( |
| 334 |
left_prop, |
| 335 |
RuleBreakData::LINE_V3_PROPERTY_BK |
| 336 |
| RuleBreakData::LINE_V3_PROPERTY_CR |
| 337 |
| RuleBreakData::LINE_V3_PROPERTY_LF |
| 338 |
| RuleBreakData::LINE_V3_PROPERTY_NL |
| 339 |
| RuleBreakData::LINE_V3_PROPERTY_SP |
| 340 |
| RuleBreakData::LINE_V3_PROPERTY_ZW |
| 341 |
) |
| 342 |
{ |
| 343 |
lb9_left = Some(left_prop); |
| 344 |
lb8a_after_lb9 = right_prop == RuleBreakData::LINE_V3_PROPERTY_ZWJ; |
| 345 |
continue; |
| 346 |
} else { |
| 347 |
if matches!( |
| 348 |
left_prop, |
| 349 |
RuleBreakData::LINE_V3_PROPERTY_OP |
| 350 |
| RuleBreakData::LINE_V3_PROPERTY_OP_EASTASIAN |
| 351 |
) && right_prop == RuleBreakData::LINE_V3_PROPERTY_SP |
| 352 |
{ |
| 353 |
lb14 = true; |
| 354 |
} |
| 355 |
lb9_left = None; |
| 356 |
lb8a_after_lb9 = false; |
| 357 |
} |
| 358 |
|
| 359 |
// CSS word-break property handling |
| 360 |
if self.options.word_option == LineBreakWordOption::KeepAll { |
| 361 |
// typographic letter units shouldn't be break |
| 362 |
if matches!( |
| 363 |
left_prop, |
| 364 |
RuleBreakData::LINE_V3_PROPERTY_AI |
| 365 |
| RuleBreakData::LINE_V3_PROPERTY_AI_EASTASIAN |
| 366 |
| RuleBreakData::LINE_V3_PROPERTY_AL |
| 367 |
| RuleBreakData::LINE_V3_PROPERTY_AL_DOTTED_CIRCLE |
| 368 |
| RuleBreakData::LINE_V3_PROPERTY_AL_EASTASIAN |
| 369 |
| RuleBreakData::LINE_V3_PROPERTY_ID |
| 370 |
| RuleBreakData::LINE_V3_PROPERTY_ID_EASTASIAN |
| 371 |
| RuleBreakData::LINE_V3_PROPERTY_NU |
| 372 |
| RuleBreakData::LINE_V3_PROPERTY_HY |
| 373 |
| RuleBreakData::LINE_V3_PROPERTY_H2 |
| 374 |
| RuleBreakData::LINE_V3_PROPERTY_H3 |
| 375 |
| RuleBreakData::LINE_V3_PROPERTY_JL |
| 376 |
| RuleBreakData::LINE_V3_PROPERTY_JV |
| 377 |
| RuleBreakData::LINE_V3_PROPERTY_JT |
| 378 |
| RuleBreakData::LINE_V3_PROPERTY_CJ |
| 379 |
) && matches!( |
| 380 |
right_prop, |
| 381 |
RuleBreakData::LINE_V3_PROPERTY_AI |
| 382 |
| RuleBreakData::LINE_V3_PROPERTY_AI_EASTASIAN |
| 383 |
| RuleBreakData::LINE_V3_PROPERTY_AL |
| 384 |
| RuleBreakData::LINE_V3_PROPERTY_AL_DOTTED_CIRCLE |
| 385 |
| RuleBreakData::LINE_V3_PROPERTY_AL_EASTASIAN |
| 386 |
| RuleBreakData::LINE_V3_PROPERTY_ID |
| 387 |
| RuleBreakData::LINE_V3_PROPERTY_ID_EASTASIAN |
| 388 |
| RuleBreakData::LINE_V3_PROPERTY_NU |
| 389 |
| RuleBreakData::LINE_V3_PROPERTY_HY |
| 390 |
| RuleBreakData::LINE_V3_PROPERTY_H2 |
| 391 |
| RuleBreakData::LINE_V3_PROPERTY_H3 |
| 392 |
| RuleBreakData::LINE_V3_PROPERTY_JL |
| 393 |
| RuleBreakData::LINE_V3_PROPERTY_JV |
| 394 |
| RuleBreakData::LINE_V3_PROPERTY_JT |
| 395 |
| RuleBreakData::LINE_V3_PROPERTY_CJ |
| 396 |
) { |
| 397 |
continue; |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
// CSS line-break property handling |
| 402 |
match self.options.strictness { |
| 403 |
LineBreakStrictness::Normal |
| 404 |
if is_break_utf32_by_normal(right_codepoint.into(), self.options.ja_zh) |
| 405 |
&& !after_zwj => |
| 406 |
{ |
| 407 |
return self.get_current_position(); |
| 408 |
} |
| 409 |
LineBreakStrictness::Loose => { |
| 410 |
if let Some(breakable) = is_break_utf32_by_loose( |
| 411 |
left_codepoint.into(), |
| 412 |
right_codepoint.into(), |
| 413 |
left_prop, |
| 414 |
right_prop, |
| 415 |
self.options.ja_zh, |
| 416 |
) { |
| 417 |
if breakable && !after_zwj { |
| 418 |
return self.get_current_position(); |
| 419 |
} |
| 420 |
continue; |
| 421 |
} |
| 422 |
} |
| 423 |
_ => (), |
| 424 |
}; |
| 425 |
|
| 426 |
// UAX14 doesn't have Thai etc, so use another way. |
| 427 |
if Y::CAN_CONTAIN_SA |
| 428 |
&& is_complex_rule(self.get_linebreak_property(left_codepoint)) |
| 429 |
&& is_complex_rule(right_prop) |
| 430 |
{ |
| 431 |
let result = (self.handle_complex)(self, left_codepoint); |
| 432 |
if result.is_some() { |
| 433 |
return result; |
| 434 |
} |
| 435 |
// I may have to fetch text until non-SA character?. |
| 436 |
} |
| 437 |
|
| 438 |
if self.options.strictness != LineBreakStrictness::Anywhere { |
| 439 |
// LB15 and LB19 have some special rules that are not covered by the break state |
| 440 |
// table. |
| 441 |
|
| 442 |
// LB15c (SP / IS NU) |
| 443 |
if left_prop == RuleBreakData::LINE_V3_PROPERTY_SP |
| 444 |
&& right_prop == RuleBreakData::LINE_V3_PROPERTY_IS |
| 445 |
&& let Some((_, next_char)) = self.peek_iter_until_no_combining_mark() |
| 446 |
&& self.get_linebreak_property(next_char) == RuleBreakData::LINE_V3_PROPERTY_NU |
| 447 |
{ |
| 448 |
return self.get_current_position(); |
| 449 |
} |
| 450 |
|
| 451 |
// LB4 and LB5 (BK | CR | LF | NL) ! |
| 452 |
// LB8 ZW SP* / |
| 453 |
// LB15a Any x QU_Pf ( SP | GL | WJ | CL | QU | CP | EX | IS | SY | BK | CR | LF | NL | ZW | eot ) |
| 454 |
// LB19a Any (x or /) QU x Any |
| 455 |
if right_prop == RuleBreakData::LINE_V3_PROPERTY_QU_PF { |
| 456 |
match left_prop { |
| 457 |
RuleBreakData::LINE_V3_PROPERTY_BK |
| 458 |
| RuleBreakData::LINE_V3_PROPERTY_CR |
| 459 |
| RuleBreakData::LINE_V3_PROPERTY_LF |
| 460 |
| RuleBreakData::LINE_V3_PROPERTY_NL |
| 461 |
| RuleBreakData::LINE_V3_PROPERTY_ZW => { |
| 462 |
// Apply LB15a |
| 463 |
let result = self.get_current_position(); |
| 464 |
if let Some((_, next_char)) = self.peek_iter_until_no_combining_mark() |
| 465 |
&& matches!( |
| 466 |
self.get_linebreak_property(next_char), |
| 467 |
RuleBreakData::LINE_V3_PROPERTY_HH |
| 468 |
| RuleBreakData::LINE_V3_PROPERTY_HY |
| 469 |
) |
| 470 |
{ |
| 471 |
return result; |
| 472 |
} |
| 473 |
if let Some((_, next_char)) = self.peek_iter() |
| 474 |
&& matches!( |
| 475 |
self.get_linebreak_property(next_char), |
| 476 |
RuleBreakData::LINE_V3_PROPERTY_CM |
| 477 |
| RuleBreakData::LINE_V3_PROPERTY_CM_EASTASIAN |
| 478 |
| RuleBreakData::LINE_V3_PROPERTY_ZWJ |
| 479 |
) |
| 480 |
{ |
| 481 |
self.advance_iter(); |
| 482 |
self.skip_combining_mark(); |
| 483 |
return result; |
| 484 |
} |
| 485 |
return result; |
| 486 |
} |
| 487 |
RuleBreakData::LINE_V3_PROPERTY_SP => { |
| 488 |
if lb14 { |
| 489 |
continue; |
| 490 |
} |
| 491 |
|
| 492 |
// LB18 is after LB15a |
| 493 |
let result = self.get_current_position(); |
| 494 |
if let Some((_, next_char)) = self.peek_iter_until_no_combining_mark() { |
| 495 |
match self.get_linebreak_property(next_char) { |
| 496 |
RuleBreakData::LINE_V3_PROPERTY_SP |
| 497 |
| RuleBreakData::LINE_V3_PROPERTY_GL |
| 498 |
| RuleBreakData::LINE_V3_PROPERTY_GL_EASTASIAN |
| 499 |
| RuleBreakData::LINE_V3_PROPERTY_WJ |
| 500 |
| RuleBreakData::LINE_V3_PROPERTY_CL |
| 501 |
| RuleBreakData::LINE_V3_PROPERTY_CL_EASTASIAN |
| 502 |
| RuleBreakData::LINE_V3_PROPERTY_QU |
| 503 |
| RuleBreakData::LINE_V3_PROPERTY_QU_PI |
| 504 |
| RuleBreakData::LINE_V3_PROPERTY_QU_PF |
| 505 |
| RuleBreakData::LINE_V3_PROPERTY_CP |
| 506 |
| RuleBreakData::LINE_V3_PROPERTY_EX |
| 507 |
| RuleBreakData::LINE_V3_PROPERTY_EX_EASTASIAN |
| 508 |
| RuleBreakData::LINE_V3_PROPERTY_IS |
| 509 |
| RuleBreakData::LINE_V3_PROPERTY_SY |
| 510 |
| RuleBreakData::LINE_V3_PROPERTY_BK |
| 511 |
| RuleBreakData::LINE_V3_PROPERTY_CR |
| 512 |
| RuleBreakData::LINE_V3_PROPERTY_LF |
| 513 |
| RuleBreakData::LINE_V3_PROPERTY_NL |
| 514 |
| RuleBreakData::LINE_V3_PROPERTY_ZW => (), |
| 515 |
RuleBreakData::LINE_V3_PROPERTY_HH |
| 516 |
| RuleBreakData::LINE_V3_PROPERTY_HY => { |
| 517 |
return result; |
| 518 |
} |
| 519 |
_ => { |
| 520 |
self.advance_iter(); |
| 521 |
self.skip_combining_mark(); |
| 522 |
return result; |
| 523 |
} |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
_ => (), |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
// LB20a - (BK | CR | LF | NL | SP | ZW | CB) / (HY | HH) x (AL | HL) |
| 532 |
if matches!( |
| 533 |
left_prop, |
| 534 |
RuleBreakData::LINE_V3_PROPERTY_BK |
| 535 |
| RuleBreakData::LINE_V3_PROPERTY_CB |
| 536 |
| RuleBreakData::LINE_V3_PROPERTY_CR |
| 537 |
| RuleBreakData::LINE_V3_PROPERTY_LF |
| 538 |
| RuleBreakData::LINE_V3_PROPERTY_NL |
| 539 |
| RuleBreakData::LINE_V3_PROPERTY_SP |
| 540 |
| RuleBreakData::LINE_V3_PROPERTY_ZW |
| 541 |
) && matches!( |
| 542 |
right_prop, |
| 543 |
RuleBreakData::LINE_V3_PROPERTY_HY | RuleBreakData::LINE_V3_PROPERTY_HH |
| 544 |
) && let Some((_, next_char)) = self.peek_iter_until_no_combining_mark() |
| 545 |
{ |
| 546 |
match self.get_linebreak_property(next_char) { |
| 547 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 548 |
| RuleBreakData::LINE_V3_PROPERTY_AL_EASTASIAN |
| 549 |
| RuleBreakData::LINE_V3_PROPERTY_AL_DOTTED_CIRCLE |
| 550 |
| RuleBreakData::LINE_V3_PROPERTY_HL |
| 551 |
| RuleBreakData::LINE_V3_PROPERTY_AI |
| 552 |
| RuleBreakData::LINE_V3_PROPERTY_AI_EASTASIAN |
| 553 |
| RuleBreakData::LINE_V3_PROPERTY_XX |
| 554 |
| RuleBreakData::LINE_V3_PROPERTY_XX_EXTPICT => { |
| 555 |
let result = self.get_current_position(); |
| 556 |
self.advance_iter(); |
| 557 |
if left_prop == RuleBreakData::LINE_V3_PROPERTY_CB && after_zwj { |
| 558 |
continue; |
| 559 |
} |
| 560 |
return result; |
| 561 |
} |
| 562 |
_ => (), |
| 563 |
} |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
// If break_state is equals or grater than 0, it is alias of property. |
| 568 |
match self.data.get_break_state_from_table(left_prop, right_prop) { |
| 569 |
BreakState::Break | BreakState::NoMatch => { |
| 570 |
if after_zwj { |
| 571 |
continue; |
| 572 |
} else { |
| 573 |
return self.get_current_position(); |
| 574 |
} |
| 575 |
} |
| 576 |
BreakState::Keep => continue, |
| 577 |
BreakState::Index(mut index) | BreakState::Intermediate(mut index) => { |
| 578 |
let mut intermediate_iter = self.iter.clone(); |
| 579 |
let mut intermediate_pos_data = self.current_pos_data; |
| 580 |
let mut intermediate_is_after_zwj = after_zwj; |
| 581 |
|
| 582 |
// Since we are building up a state in this inner loop, we do not |
| 583 |
// need an analogue of lb9_left; continuing the inner loop preserves |
| 584 |
// `index` which is the current state, and thus implements the |
| 585 |
// “treat as” rule. |
| 586 |
let mut left_prop_pre_lb9 = right_prop; |
| 587 |
|
| 588 |
// current state isn't resolved due to intermediating. |
| 589 |
// Example, [AK] [AS] is processing LB28a, but if not matched after fetching |
| 590 |
// data, we should break after [AK]. |
| 591 |
let is_intermediate_rule_no_match = if lb8a_after_lb9 { |
| 592 |
// left was ZWJ so we don't break between ZWJ. |
| 593 |
true |
| 594 |
} else { |
| 595 |
index > self.data.last_codepoint_property |
| 596 |
}; |
| 597 |
|
| 598 |
loop { |
| 599 |
self.advance_iter(); |
| 600 |
let after_zwj = left_prop_pre_lb9 == RuleBreakData::LINE_V3_PROPERTY_ZWJ; |
| 601 |
|
| 602 |
let previous_break_state_is_cp_prop = |
| 603 |
index <= self.data.last_codepoint_property; |
| 604 |
|
| 605 |
let Some(prop) = self.get_current_linebreak_property() else { |
| 606 |
// Reached EOF. But we are analyzing multiple characters now, so next break may be previous point. |
| 607 |
let break_state = self |
| 608 |
.data |
| 609 |
.get_break_state_from_table(index, self.data.eot_property); |
| 610 |
if break_state == BreakState::NoMatch { |
| 611 |
self.iter = intermediate_iter; |
| 612 |
self.current_pos_data = intermediate_pos_data; |
| 613 |
if intermediate_is_after_zwj { |
| 614 |
// Do not break [AK] [ZWJ] ÷ [AS] (eot). |
| 615 |
continue 'a; |
| 616 |
} else { |
| 617 |
return self.get_current_position(); |
| 618 |
} |
| 619 |
} |
| 620 |
// EOF |
| 621 |
return Some(self.len); |
| 622 |
}; |
| 623 |
|
| 624 |
if matches!( |
| 625 |
prop, |
| 626 |
RuleBreakData::LINE_V3_PROPERTY_CM |
| 627 |
| RuleBreakData::LINE_V3_PROPERTY_CM_EASTASIAN |
| 628 |
| RuleBreakData::LINE_V3_PROPERTY_SA_MC_MN |
| 629 |
| RuleBreakData::LINE_V3_PROPERTY_ZWJ |
| 630 |
) && !matches!( |
| 631 |
left_prop_pre_lb9, |
| 632 |
RuleBreakData::LINE_V3_PROPERTY_BK |
| 633 |
| RuleBreakData::LINE_V3_PROPERTY_CR |
| 634 |
| RuleBreakData::LINE_V3_PROPERTY_LF |
| 635 |
| RuleBreakData::LINE_V3_PROPERTY_NL |
| 636 |
| RuleBreakData::LINE_V3_PROPERTY_SP |
| 637 |
| RuleBreakData::LINE_V3_PROPERTY_ZW |
| 638 |
) { |
| 639 |
left_prop_pre_lb9 = prop; |
| 640 |
continue; |
| 641 |
} |
| 642 |
|
| 643 |
// LB14 is OP SP* x Any |
| 644 |
if lb14 && prop != RuleBreakData::LINE_V3_PROPERTY_SP { |
| 645 |
lb14 = false; |
| 646 |
// This might be LB20a |
| 647 |
if !matches!( |
| 648 |
prop, |
| 649 |
RuleBreakData::LINE_V3_PROPERTY_HH |
| 650 |
| RuleBreakData::LINE_V3_PROPERTY_HY |
| 651 |
) { |
| 652 |
continue 'a; |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
if left_prop_pre_lb9 == RuleBreakData::LINE_V3_PROPERTY_SP |
| 657 |
&& index != RuleBreakData::LINE_V3_PROPERTY_ZW |
| 658 |
&& prop == RuleBreakData::LINE_V3_PROPERTY_IS |
| 659 |
// Skip if the current state has sticky "× Any" semantics. |
| 660 |
&& !matches!( |
| 661 |
self.data.get_break_state_from_table( |
| 662 |
index, |
| 663 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 664 |
), |
| 665 |
BreakState::Keep |
| 666 |
) |
| 667 |
{ |
| 668 |
// LB15c or LB15d |
| 669 |
self.iter = intermediate_iter; |
| 670 |
self.current_pos_data = intermediate_pos_data; |
| 671 |
continue 'a; |
| 672 |
} |
| 673 |
|
| 674 |
if prop == RuleBreakData::LINE_V3_PROPERTY_QU_PF |
| 675 |
&& left_prop_pre_lb9 == RuleBreakData::LINE_V3_PROPERTY_SP |
| 676 |
&& index > self.data.last_codepoint_property |
| 677 |
{ |
| 678 |
// This might be combined property such OP SP* (LB14), but next is |
| 679 |
// QU_Pf, it might be LB18 and LB19a. |
| 680 |
// If the state has sticky "× Any" semantics (LB14 OP_SP / LB15a |
| 681 |
// QU_SP), the no-break before QU_PF is preserved by NOT reverting: |
| 682 |
// continue with current at QU_PF so the next iteration processes |
| 683 |
// QU_PF → next directly (no spurious break emitted by runtime |
| 684 |
// SP arm). For other states (B2_SP, CL_CP_SP, ...), revert so |
| 685 |
// LB18 / runtime SP arm emits the break before QU_PF. |
| 686 |
if matches!( |
| 687 |
self.data.get_break_state_from_table( |
| 688 |
index, |
| 689 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 690 |
), |
| 691 |
BreakState::Keep |
| 692 |
) { |
| 693 |
continue 'a; |
| 694 |
} |
| 695 |
self.iter = intermediate_iter; |
| 696 |
self.current_pos_data = intermediate_pos_data; |
| 697 |
continue 'a; |
| 698 |
} |
| 699 |
|
| 700 |
if left_prop_pre_lb9 == RuleBreakData::LINE_V3_PROPERTY_SP |
| 701 |
&& (prop == RuleBreakData::LINE_V3_PROPERTY_HH |
| 702 |
|| prop == RuleBreakData::LINE_V3_PROPERTY_HY) |
| 703 |
{ |
| 704 |
// LB20a - (BK | CR | LF | NL | SP | ZW | CB) / (HY | HH) x (AL | HL) |
| 705 |
// The leading SP context is preserved by intermediate states like |
| 706 |
// CL_CP_SP (LB16) and B2_SP (LB17). |
| 707 |
if let Some((_, next_char)) = self.peek_iter_until_no_combining_mark() { |
| 708 |
let next_prop = self.get_linebreak_property(next_char); |
| 709 |
if matches!( |
| 710 |
next_prop, |
| 711 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 712 |
| RuleBreakData::LINE_V3_PROPERTY_AL_EASTASIAN |
| 713 |
| RuleBreakData::LINE_V3_PROPERTY_AL_DOTTED_CIRCLE |
| 714 |
| RuleBreakData::LINE_V3_PROPERTY_HL |
| 715 |
| RuleBreakData::LINE_V3_PROPERTY_AI |
| 716 |
| RuleBreakData::LINE_V3_PROPERTY_AI_EASTASIAN |
| 717 |
| RuleBreakData::LINE_V3_PROPERTY_XX |
| 718 |
| RuleBreakData::LINE_V3_PROPERTY_XX_EXTPICT |
| 719 |
) { |
| 720 |
// If the current state has sticky "× Any" semantics for AL, |
| 721 |
// i.e., LB14 (OP_SP) or LB15a (QU_SP), the break before |
| 722 |
// HY/HH is already suppressed by that rule. LB20a still |
| 723 |
// forbids the break between HY/HH and the following AL/HL, |
| 724 |
// so advance past HY/HH (and any combining marks) and resume |
| 725 |
// with the AL/HL as the left context, emitting no break. |
| 726 |
if matches!( |
| 727 |
self.data.get_break_state_from_table( |
| 728 |
index, |
| 729 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 730 |
), |
| 731 |
BreakState::Keep |
| 732 |
) { |
| 733 |
self.advance_iter(); |
| 734 |
self.skip_combining_mark(); |
| 735 |
continue 'a; |
| 736 |
} |
| 737 |
// Otherwise emit the break before HY/HH and skip ahead so the |
| 738 |
// break before AL/HL is suppressed. |
| 739 |
let result = self.get_current_position(); |
| 740 |
self.advance_iter(); |
| 741 |
return result; |
| 742 |
} |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
match self.data.get_break_state_from_table(index, prop) { |
| 747 |
BreakState::Keep => continue 'a, |
| 748 |
BreakState::NoMatch => { |
| 749 |
self.iter = intermediate_iter; |
| 750 |
self.current_pos_data = intermediate_pos_data; |
| 751 |
if after_zwj { |
| 752 |
// Break [AK] ÷ [AS] [ZWJ] [XX], |
| 753 |
// but not [AK] [ZWJ] ÷ [AS] [ZWJ] [XX]. |
| 754 |
if is_intermediate_rule_no_match && !intermediate_is_after_zwj { |
| 755 |
return self.get_current_position(); |
| 756 |
} |
| 757 |
continue 'a; |
| 758 |
} else if intermediate_is_after_zwj { |
| 759 |
// Do not break [AK] [ZWJ] ÷ [AS] [XX]. |
| 760 |
continue 'a; |
| 761 |
} else { |
| 762 |
return self.get_current_position(); |
| 763 |
} |
| 764 |
} |
| 765 |
BreakState::Break => { |
| 766 |
if after_zwj { |
| 767 |
continue 'a; |
| 768 |
} else { |
| 769 |
return self.get_current_position(); |
| 770 |
} |
| 771 |
} |
| 772 |
BreakState::Intermediate(i) => { |
| 773 |
index = i; |
| 774 |
intermediate_iter = self.iter.clone(); |
| 775 |
intermediate_pos_data = self.current_pos_data; |
| 776 |
intermediate_is_after_zwj = after_zwj; |
| 777 |
} |
| 778 |
BreakState::Index(i) => { |
| 779 |
index = i; |
| 780 |
if previous_break_state_is_cp_prop { |
| 781 |
intermediate_iter = self.iter.clone(); |
| 782 |
intermediate_pos_data = self.current_pos_data; |
| 783 |
intermediate_is_after_zwj = after_zwj; |
| 784 |
} |
| 785 |
} |
| 786 |
} |
| 787 |
left_prop_pre_lb9 = prop; |
| 788 |
} |
| 789 |
} |
| 790 |
} |
| 791 |
} |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
enum StringBoundaryPosType { |
| 796 |
Start, |
| 797 |
Middle, |
| 798 |
End, |
| 799 |
} |
| 800 |
|
| 801 |
impl<Y: RuleBreakType> LineBreakIteratorV3<'_, '_, Y> { |
| 802 |
fn advance_iter(&mut self) { |
| 803 |
self.current_pos_data = self.iter.next(); |
| 804 |
} |
| 805 |
|
| 806 |
fn peek_iter(&self) -> Option<(usize, Y::CharType)> { |
| 807 |
self.iter.clone().next() |
| 808 |
} |
| 809 |
|
| 810 |
fn peek_iter_until_no_combining_mark(&self) -> Option<(usize, Y::CharType)> { |
| 811 |
let mut iter = self.iter.clone(); |
| 812 |
loop { |
| 813 |
let data = iter.next()?; |
| 814 |
let property = self.get_linebreak_property(data.1); |
| 815 |
if !matches!( |
| 816 |
property, |
| 817 |
RuleBreakData::LINE_V3_PROPERTY_CM |
| 818 |
| RuleBreakData::LINE_V3_PROPERTY_CM_EASTASIAN |
| 819 |
| RuleBreakData::LINE_V3_PROPERTY_ZWJ |
| 820 |
) { |
| 821 |
return Some(data); |
| 822 |
} |
| 823 |
} |
| 824 |
} |
| 825 |
|
| 826 |
fn is_eof(&self) -> bool { |
| 827 |
self.current_pos_data.is_none() |
| 828 |
} |
| 829 |
|
| 830 |
#[inline] |
| 831 |
fn check_eof(&mut self) -> StringBoundaryPosType { |
| 832 |
if self.is_eof() { |
| 833 |
self.advance_iter(); |
| 834 |
if self.is_eof() { |
| 835 |
if self.len == 0 { |
| 836 |
// Empty string. Since `self.current_pos_data` is always going to be empty, |
| 837 |
// we never read `self.len` except for here, so we can use it to mark that |
| 838 |
// we have already returned the single empty-string breakpoint. |
| 839 |
self.len = 1; |
| 840 |
StringBoundaryPosType::Start |
| 841 |
} else { |
| 842 |
StringBoundaryPosType::End |
| 843 |
} |
| 844 |
} else { |
| 845 |
StringBoundaryPosType::Start |
| 846 |
} |
| 847 |
} else { |
| 848 |
StringBoundaryPosType::Middle |
| 849 |
} |
| 850 |
} |
| 851 |
|
| 852 |
fn get_current_position(&self) -> Option<usize> { |
| 853 |
self.current_pos_data.map(|(pos, _)| pos) |
| 854 |
} |
| 855 |
|
| 856 |
fn get_current_codepoint(&self) -> Option<Y::CharType> { |
| 857 |
self.current_pos_data.map(|(_, codepoint)| codepoint) |
| 858 |
} |
| 859 |
|
| 860 |
// apply LB9 |
| 861 |
fn skip_combining_mark(&mut self) { |
| 862 |
if let Some(mut property) = self.get_current_linebreak_property() { |
| 863 |
while property == RuleBreakData::LINE_V3_PROPERTY_CM |
| 864 |
|| property == RuleBreakData::LINE_V3_PROPERTY_CM_EASTASIAN |
| 865 |
|| property == RuleBreakData::LINE_V3_PROPERTY_ZWJ |
| 866 |
{ |
| 867 |
if let Some((_, codepoint)) = self.peek_iter() { |
| 868 |
self.advance_iter(); |
| 869 |
property = self.get_linebreak_property(codepoint); |
| 870 |
continue; |
| 871 |
} |
| 872 |
return; |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
fn get_linebreak_property(&self, codepoint: Y::CharType) -> u8 { |
| 878 |
match ( |
| 879 |
(self.options.word_option, self.options.strictness), |
| 880 |
self.data.property_table.get32(codepoint.into()), |
| 881 |
) { |
| 882 |
// CJ is treated as NS by default, yielding strict line breaking. |
| 883 |
// https://www.unicode.org/reports/tr14/#CJ |
| 884 |
( |
| 885 |
(LineBreakWordOption::BreakAll, _) |
| 886 |
| (_, LineBreakStrictness::Loose | LineBreakStrictness::Normal), |
| 887 |
RuleBreakData::LINE_V3_PROPERTY_CJ, |
| 888 |
) => RuleBreakData::LINE_V3_PROPERTY_ID, // All CJ's General_Category is Other_Letter (Lo). |
| 889 |
((LineBreakWordOption::BreakAll, _), p) if p == self.data.complex_property => { |
| 890 |
RuleBreakData::LINE_V3_PROPERTY_ID |
| 891 |
} |
| 892 |
( |
| 893 |
(LineBreakWordOption::BreakAll, _), |
| 894 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 895 |
| RuleBreakData::LINE_V3_PROPERTY_AL_DOTTED_CIRCLE |
| 896 |
| RuleBreakData::LINE_V3_PROPERTY_AL_EASTASIAN |
| 897 |
| RuleBreakData::LINE_V3_PROPERTY_NU, |
| 898 |
) => RuleBreakData::LINE_V3_PROPERTY_ID, |
| 899 |
(_, prop) => prop, |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
fn get_current_linebreak_property(&self) -> Option<u8> { |
| 904 |
self.get_current_codepoint() |
| 905 |
.map(|c| self.get_linebreak_property(c)) |
| 906 |
} |
| 907 |
} |
| 908 |
|
| 909 |
pub(super) fn line_handle_complex_utf8<T>( |
| 910 |
iter: &mut LineBreakIteratorV3<'_, '_, T>, |
| 911 |
left_codepoint: char, |
| 912 |
) -> Option<usize> |
| 913 |
where |
| 914 |
T: RuleBreakType<CharType = char>, |
| 915 |
{ |
| 916 |
// word segmenter doesn't define break rules for some scripts such as Thai. |
| 917 |
let start_iter = iter.iter.clone(); |
| 918 |
let start_point = iter.current_pos_data; |
| 919 |
let mut s = String::new(); |
| 920 |
s.push(left_codepoint); |
| 921 |
loop { |
| 922 |
debug_assert!(!iter.is_eof()); |
| 923 |
s.push(iter.get_current_codepoint()?); |
| 924 |
iter.advance_iter(); |
| 925 |
if let Some(current_codepoint) = iter.get_current_codepoint() { |
| 926 |
if !is_complex_rule(iter.get_linebreak_property(current_codepoint)) { |
| 927 |
break; |
| 928 |
} |
| 929 |
} else { |
| 930 |
// EOF |
| 931 |
break; |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
// Restore iterator to move to head of complex string |
| 936 |
iter.iter = start_iter; |
| 937 |
iter.current_pos_data = start_point; |
| 938 |
let breaks = iter.complex.segment_str(&s); |
| 939 |
iter.result_cache = breaks; |
| 940 |
let first_pos = *iter.result_cache.first()?; |
| 941 |
let mut i = left_codepoint.len_utf8(); |
| 942 |
loop { |
| 943 |
if i == first_pos { |
| 944 |
// Re-calculate breaking offset |
| 945 |
iter.result_cache = iter.result_cache.iter().skip(1).map(|r| r - i).collect(); |
| 946 |
return iter.get_current_position(); |
| 947 |
} |
| 948 |
debug_assert!( |
| 949 |
i < first_pos, |
| 950 |
"we should always arrive at first_pos: near index {:?}", |
| 951 |
iter.get_current_position() |
| 952 |
); |
| 953 |
i += iter.get_current_codepoint().map_or(0, T::char_len); |
| 954 |
iter.advance_iter(); |
| 955 |
if iter.is_eof() { |
| 956 |
iter.result_cache.clear(); |
| 957 |
return Some(iter.len); |
| 958 |
} |
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
pub(super) fn line_handle_complex_utf16<T>( |
| 963 |
iterator: &mut LineBreakIteratorV3<'_, '_, T>, |
| 964 |
left_codepoint: T::CharType, |
| 965 |
) -> Option<usize> |
| 966 |
where |
| 967 |
T: RuleBreakType<CharType = u32>, |
| 968 |
{ |
| 969 |
// word segmenter doesn't define break rules for some scripts such as Thai. |
| 970 |
let start_iter = iterator.iter.clone(); |
| 971 |
let start_point = iterator.current_pos_data; |
| 972 |
let mut s = vec![left_codepoint as u16]; |
| 973 |
loop { |
| 974 |
debug_assert!(!iterator.is_eof()); |
| 975 |
s.push(iterator.get_current_codepoint()? as u16); |
| 976 |
iterator.advance_iter(); |
| 977 |
if let Some(current_codepoint) = iterator.get_current_codepoint() { |
| 978 |
if !is_complex_rule(iterator.get_linebreak_property(current_codepoint)) { |
| 979 |
break; |
| 980 |
} |
| 981 |
} else { |
| 982 |
// EOF |
| 983 |
break; |
| 984 |
} |
| 985 |
} |
| 986 |
|
| 987 |
// Restore iterator to move to head of complex string |
| 988 |
iterator.iter = start_iter; |
| 989 |
iterator.current_pos_data = start_point; |
| 990 |
let breaks = iterator.complex.segment_utf16(&s); |
| 991 |
iterator.result_cache = breaks; |
| 992 |
// result_cache vector is utf-16 index that is in BMP. |
| 993 |
let first_pos = *iterator.result_cache.first()?; |
| 994 |
let mut i = 1; |
| 995 |
loop { |
| 996 |
if i == first_pos { |
| 997 |
// Re-calculate breaking offset |
| 998 |
iterator.result_cache = iterator |
| 999 |
.result_cache |
| 1000 |
.iter() |
| 1001 |
.skip(1) |
| 1002 |
.map(|r| r - i) |
| 1003 |
.collect(); |
| 1004 |
return iterator.get_current_position(); |
| 1005 |
} |
| 1006 |
debug_assert!( |
| 1007 |
i < first_pos, |
| 1008 |
"we should always arrive at first_pos: near index {:?}", |
| 1009 |
iterator.get_current_position() |
| 1010 |
); |
| 1011 |
i += 1; |
| 1012 |
iterator.advance_iter(); |
| 1013 |
if iterator.is_eof() { |
| 1014 |
iterator.result_cache.clear(); |
| 1015 |
return Some(iterator.len); |
| 1016 |
} |
| 1017 |
} |
| 1018 |
} |
| 1019 |
|
| 1020 |
#[cfg(test)] |
| 1021 |
mod tests { |
| 1022 |
use super::*; |
| 1023 |
use crate::*; |
| 1024 |
use icu_provider::prelude::*; |
| 1025 |
|
| 1026 |
#[test] |
| 1027 |
fn linebreak_property() { |
| 1028 |
let super::super::LineBreakIteratorInner::V3(iterator) = |
| 1029 |
LineSegmenter::new_17_for_non_complex_scripts(Default::default()) |
| 1030 |
.segment_str("input") |
| 1031 |
.0 |
| 1032 |
else { |
| 1033 |
unreachable!() |
| 1034 |
}; |
| 1035 |
|
| 1036 |
assert_eq!( |
| 1037 |
iterator.get_linebreak_property('\u{0020}'), |
| 1038 |
RuleBreakData::LINE_V3_PROPERTY_SP |
| 1039 |
); |
| 1040 |
assert_eq!( |
| 1041 |
iterator.get_linebreak_property('\u{0022}'), |
| 1042 |
RuleBreakData::LINE_V3_PROPERTY_QU |
| 1043 |
); |
| 1044 |
assert_eq!( |
| 1045 |
iterator.get_linebreak_property('('), |
| 1046 |
RuleBreakData::LINE_V3_PROPERTY_OP |
| 1047 |
); |
| 1048 |
assert_eq!( |
| 1049 |
iterator.get_linebreak_property('\u{0030}'), |
| 1050 |
RuleBreakData::LINE_V3_PROPERTY_NU |
| 1051 |
); |
| 1052 |
assert_eq!( |
| 1053 |
iterator.get_linebreak_property('['), |
| 1054 |
RuleBreakData::LINE_V3_PROPERTY_OP |
| 1055 |
); |
| 1056 |
assert_eq!( |
| 1057 |
iterator.get_linebreak_property('\u{1f3fb}'), |
| 1058 |
RuleBreakData::LINE_V3_PROPERTY_EM |
| 1059 |
); |
| 1060 |
assert_eq!( |
| 1061 |
iterator.get_linebreak_property('\u{20000}'), |
| 1062 |
RuleBreakData::LINE_V3_PROPERTY_ID_EASTASIAN |
| 1063 |
); |
| 1064 |
assert_eq!( |
| 1065 |
iterator.get_linebreak_property('\u{e0020}'), |
| 1066 |
RuleBreakData::LINE_V3_PROPERTY_CM |
| 1067 |
); |
| 1068 |
assert_eq!( |
| 1069 |
iterator.get_linebreak_property('\u{3041}'), |
| 1070 |
RuleBreakData::LINE_V3_PROPERTY_CJ |
| 1071 |
); |
| 1072 |
assert_eq!( |
| 1073 |
iterator.get_linebreak_property('\u{0025}'), |
| 1074 |
RuleBreakData::LINE_V3_PROPERTY_PO |
| 1075 |
); |
| 1076 |
assert_eq!( |
| 1077 |
iterator.get_linebreak_property('\u{00A7}'), |
| 1078 |
RuleBreakData::LINE_V3_PROPERTY_AI |
| 1079 |
); |
| 1080 |
assert_eq!( |
| 1081 |
iterator.get_linebreak_property('\u{50005}'), |
| 1082 |
RuleBreakData::LINE_V3_PROPERTY_XX |
| 1083 |
); |
| 1084 |
assert_eq!( |
| 1085 |
iterator.get_linebreak_property('\u{17D6}'), |
| 1086 |
RuleBreakData::LINE_V3_PROPERTY_NS |
| 1087 |
); |
| 1088 |
assert_eq!( |
| 1089 |
iterator.get_linebreak_property('\u{2014}'), |
| 1090 |
RuleBreakData::LINE_V3_PROPERTY_B2 |
| 1091 |
); |
| 1092 |
} |
| 1093 |
|
| 1094 |
#[test] |
| 1095 |
fn break_rule() { |
| 1096 |
let payload = DataProvider::<SegmenterBreakLineV3>::load(&Baked, Default::default()) |
| 1097 |
.expect("Loading should succeed!") |
| 1098 |
.payload; |
| 1099 |
let lb_data: &RuleBreakData = payload.get(); |
| 1100 |
|
| 1101 |
let is_break = |left, right| { |
| 1102 |
matches!( |
| 1103 |
lb_data.get_break_state_from_table(left, right), |
| 1104 |
BreakState::Break | BreakState::NoMatch |
| 1105 |
) |
| 1106 |
}; |
| 1107 |
|
| 1108 |
// LB4 |
| 1109 |
assert_eq!( |
| 1110 |
is_break( |
| 1111 |
RuleBreakData::LINE_V3_PROPERTY_BK, |
| 1112 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1113 |
), |
| 1114 |
true |
| 1115 |
); |
| 1116 |
// LB5 |
| 1117 |
assert_eq!( |
| 1118 |
is_break( |
| 1119 |
RuleBreakData::LINE_V3_PROPERTY_CR, |
| 1120 |
RuleBreakData::LINE_V3_PROPERTY_LF |
| 1121 |
), |
| 1122 |
false |
| 1123 |
); |
| 1124 |
assert_eq!( |
| 1125 |
is_break( |
| 1126 |
RuleBreakData::LINE_V3_PROPERTY_CR, |
| 1127 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1128 |
), |
| 1129 |
true |
| 1130 |
); |
| 1131 |
assert_eq!( |
| 1132 |
is_break( |
| 1133 |
RuleBreakData::LINE_V3_PROPERTY_LF, |
| 1134 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1135 |
), |
| 1136 |
true |
| 1137 |
); |
| 1138 |
assert_eq!( |
| 1139 |
is_break( |
| 1140 |
RuleBreakData::LINE_V3_PROPERTY_NL, |
| 1141 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1142 |
), |
| 1143 |
true |
| 1144 |
); |
| 1145 |
// LB6 |
| 1146 |
assert_eq!( |
| 1147 |
is_break( |
| 1148 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1149 |
RuleBreakData::LINE_V3_PROPERTY_BK |
| 1150 |
), |
| 1151 |
false |
| 1152 |
); |
| 1153 |
assert_eq!( |
| 1154 |
is_break( |
| 1155 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1156 |
RuleBreakData::LINE_V3_PROPERTY_CR |
| 1157 |
), |
| 1158 |
false |
| 1159 |
); |
| 1160 |
assert_eq!( |
| 1161 |
is_break( |
| 1162 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1163 |
RuleBreakData::LINE_V3_PROPERTY_LF |
| 1164 |
), |
| 1165 |
false |
| 1166 |
); |
| 1167 |
assert_eq!( |
| 1168 |
is_break( |
| 1169 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1170 |
RuleBreakData::LINE_V3_PROPERTY_NL |
| 1171 |
), |
| 1172 |
false |
| 1173 |
); |
| 1174 |
// LB7 |
| 1175 |
assert_eq!( |
| 1176 |
is_break( |
| 1177 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1178 |
RuleBreakData::LINE_V3_PROPERTY_SP |
| 1179 |
), |
| 1180 |
false |
| 1181 |
); |
| 1182 |
assert_eq!( |
| 1183 |
is_break( |
| 1184 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1185 |
RuleBreakData::LINE_V3_PROPERTY_ZW |
| 1186 |
), |
| 1187 |
false |
| 1188 |
); |
| 1189 |
// LB8 |
| 1190 |
// LB8a and LB9 omitted: These are handled outside of the state table. |
| 1191 |
// LB10 |
| 1192 |
assert_eq!( |
| 1193 |
is_break( |
| 1194 |
RuleBreakData::LINE_V3_PROPERTY_ZWJ, |
| 1195 |
RuleBreakData::LINE_V3_PROPERTY_SP |
| 1196 |
), |
| 1197 |
false |
| 1198 |
); |
| 1199 |
assert_eq!( |
| 1200 |
is_break( |
| 1201 |
RuleBreakData::LINE_V3_PROPERTY_SP, |
| 1202 |
RuleBreakData::LINE_V3_PROPERTY_CM |
| 1203 |
), |
| 1204 |
true |
| 1205 |
); |
| 1206 |
// LB11 |
| 1207 |
assert_eq!( |
| 1208 |
is_break( |
| 1209 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1210 |
RuleBreakData::LINE_V3_PROPERTY_WJ |
| 1211 |
), |
| 1212 |
false |
| 1213 |
); |
| 1214 |
assert_eq!( |
| 1215 |
is_break( |
| 1216 |
RuleBreakData::LINE_V3_PROPERTY_WJ, |
| 1217 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1218 |
), |
| 1219 |
false |
| 1220 |
); |
| 1221 |
// LB12 |
| 1222 |
assert_eq!( |
| 1223 |
is_break( |
| 1224 |
RuleBreakData::LINE_V3_PROPERTY_GL, |
| 1225 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1226 |
), |
| 1227 |
false |
| 1228 |
); |
| 1229 |
// LB12a |
| 1230 |
assert_eq!( |
| 1231 |
is_break( |
| 1232 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1233 |
RuleBreakData::LINE_V3_PROPERTY_GL |
| 1234 |
), |
| 1235 |
false |
| 1236 |
); |
| 1237 |
assert_eq!( |
| 1238 |
is_break( |
| 1239 |
RuleBreakData::LINE_V3_PROPERTY_SP, |
| 1240 |
RuleBreakData::LINE_V3_PROPERTY_GL |
| 1241 |
), |
| 1242 |
true |
| 1243 |
); |
| 1244 |
// LB13 |
| 1245 |
assert_eq!( |
| 1246 |
is_break( |
| 1247 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1248 |
RuleBreakData::LINE_V3_PROPERTY_CL |
| 1249 |
), |
| 1250 |
false |
| 1251 |
); |
| 1252 |
assert_eq!( |
| 1253 |
is_break( |
| 1254 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1255 |
RuleBreakData::LINE_V3_PROPERTY_CP |
| 1256 |
), |
| 1257 |
false |
| 1258 |
); |
| 1259 |
assert_eq!( |
| 1260 |
is_break( |
| 1261 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1262 |
RuleBreakData::LINE_V3_PROPERTY_EX |
| 1263 |
), |
| 1264 |
false |
| 1265 |
); |
| 1266 |
assert_eq!( |
| 1267 |
is_break( |
| 1268 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1269 |
RuleBreakData::LINE_V3_PROPERTY_IS |
| 1270 |
), |
| 1271 |
false |
| 1272 |
); |
| 1273 |
assert_eq!( |
| 1274 |
is_break( |
| 1275 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1276 |
RuleBreakData::LINE_V3_PROPERTY_SY |
| 1277 |
), |
| 1278 |
false |
| 1279 |
); |
| 1280 |
// LB18 |
| 1281 |
assert_eq!( |
| 1282 |
is_break( |
| 1283 |
RuleBreakData::LINE_V3_PROPERTY_SP, |
| 1284 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1285 |
), |
| 1286 |
true |
| 1287 |
); |
| 1288 |
// LB19 |
| 1289 |
assert_eq!( |
| 1290 |
is_break( |
| 1291 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1292 |
RuleBreakData::LINE_V3_PROPERTY_QU |
| 1293 |
), |
| 1294 |
false |
| 1295 |
); |
| 1296 |
assert_eq!( |
| 1297 |
is_break( |
| 1298 |
RuleBreakData::LINE_V3_PROPERTY_QU, |
| 1299 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1300 |
), |
| 1301 |
false |
| 1302 |
); |
| 1303 |
// LB20 |
| 1304 |
assert_eq!( |
| 1305 |
is_break( |
| 1306 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1307 |
RuleBreakData::LINE_V3_PROPERTY_CB |
| 1308 |
), |
| 1309 |
true |
| 1310 |
); |
| 1311 |
assert_eq!( |
| 1312 |
is_break( |
| 1313 |
RuleBreakData::LINE_V3_PROPERTY_CB, |
| 1314 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1315 |
), |
| 1316 |
true |
| 1317 |
); |
| 1318 |
// LB20 |
| 1319 |
assert_eq!( |
| 1320 |
is_break( |
| 1321 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1322 |
RuleBreakData::LINE_V3_PROPERTY_BA |
| 1323 |
), |
| 1324 |
false |
| 1325 |
); |
| 1326 |
assert_eq!( |
| 1327 |
is_break( |
| 1328 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1329 |
RuleBreakData::LINE_V3_PROPERTY_HY |
| 1330 |
), |
| 1331 |
false |
| 1332 |
); |
| 1333 |
assert_eq!( |
| 1334 |
is_break( |
| 1335 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1336 |
RuleBreakData::LINE_V3_PROPERTY_NS |
| 1337 |
), |
| 1338 |
false |
| 1339 |
); |
| 1340 |
// LB21 |
| 1341 |
assert_eq!( |
| 1342 |
is_break( |
| 1343 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1344 |
RuleBreakData::LINE_V3_PROPERTY_BA |
| 1345 |
), |
| 1346 |
false |
| 1347 |
); |
| 1348 |
assert_eq!( |
| 1349 |
is_break( |
| 1350 |
RuleBreakData::LINE_V3_PROPERTY_BB, |
| 1351 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1352 |
), |
| 1353 |
false |
| 1354 |
); |
| 1355 |
assert_eq!( |
| 1356 |
is_break( |
| 1357 |
RuleBreakData::LINE_V3_PROPERTY_ID, |
| 1358 |
RuleBreakData::LINE_V3_PROPERTY_BA |
| 1359 |
), |
| 1360 |
false |
| 1361 |
); |
| 1362 |
assert_eq!( |
| 1363 |
is_break( |
| 1364 |
RuleBreakData::LINE_V3_PROPERTY_ID, |
| 1365 |
RuleBreakData::LINE_V3_PROPERTY_NS |
| 1366 |
), |
| 1367 |
false |
| 1368 |
); |
| 1369 |
// LB21a |
| 1370 |
// LB21b |
| 1371 |
assert_eq!( |
| 1372 |
is_break( |
| 1373 |
RuleBreakData::LINE_V3_PROPERTY_SY, |
| 1374 |
RuleBreakData::LINE_V3_PROPERTY_HL |
| 1375 |
), |
| 1376 |
false |
| 1377 |
); |
| 1378 |
// LB22 |
| 1379 |
assert_eq!( |
| 1380 |
is_break( |
| 1381 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1382 |
RuleBreakData::LINE_V3_PROPERTY_IN |
| 1383 |
), |
| 1384 |
false |
| 1385 |
); |
| 1386 |
// LB 23 |
| 1387 |
assert_eq!( |
| 1388 |
is_break( |
| 1389 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1390 |
RuleBreakData::LINE_V3_PROPERTY_NU |
| 1391 |
), |
| 1392 |
false |
| 1393 |
); |
| 1394 |
assert_eq!( |
| 1395 |
is_break( |
| 1396 |
RuleBreakData::LINE_V3_PROPERTY_HL, |
| 1397 |
RuleBreakData::LINE_V3_PROPERTY_NU |
| 1398 |
), |
| 1399 |
false |
| 1400 |
); |
| 1401 |
// LB 23a |
| 1402 |
assert_eq!( |
| 1403 |
is_break( |
| 1404 |
RuleBreakData::LINE_V3_PROPERTY_PR, |
| 1405 |
RuleBreakData::LINE_V3_PROPERTY_ID |
| 1406 |
), |
| 1407 |
false |
| 1408 |
); |
| 1409 |
assert_eq!( |
| 1410 |
is_break( |
| 1411 |
RuleBreakData::LINE_V3_PROPERTY_PR, |
| 1412 |
RuleBreakData::LINE_V3_PROPERTY_EB |
| 1413 |
), |
| 1414 |
false |
| 1415 |
); |
| 1416 |
assert_eq!( |
| 1417 |
is_break( |
| 1418 |
RuleBreakData::LINE_V3_PROPERTY_PR, |
| 1419 |
RuleBreakData::LINE_V3_PROPERTY_EM |
| 1420 |
), |
| 1421 |
false |
| 1422 |
); |
| 1423 |
assert_eq!( |
| 1424 |
is_break( |
| 1425 |
RuleBreakData::LINE_V3_PROPERTY_ID, |
| 1426 |
RuleBreakData::LINE_V3_PROPERTY_PO |
| 1427 |
), |
| 1428 |
false |
| 1429 |
); |
| 1430 |
assert_eq!( |
| 1431 |
is_break( |
| 1432 |
RuleBreakData::LINE_V3_PROPERTY_EB, |
| 1433 |
RuleBreakData::LINE_V3_PROPERTY_PO |
| 1434 |
), |
| 1435 |
false |
| 1436 |
); |
| 1437 |
assert_eq!( |
| 1438 |
is_break( |
| 1439 |
RuleBreakData::LINE_V3_PROPERTY_EM, |
| 1440 |
RuleBreakData::LINE_V3_PROPERTY_PO |
| 1441 |
), |
| 1442 |
false |
| 1443 |
); |
| 1444 |
// LB26 |
| 1445 |
assert_eq!( |
| 1446 |
is_break( |
| 1447 |
RuleBreakData::LINE_V3_PROPERTY_JL, |
| 1448 |
RuleBreakData::LINE_V3_PROPERTY_JL |
| 1449 |
), |
| 1450 |
false |
| 1451 |
); |
| 1452 |
assert_eq!( |
| 1453 |
is_break( |
| 1454 |
RuleBreakData::LINE_V3_PROPERTY_JL, |
| 1455 |
RuleBreakData::LINE_V3_PROPERTY_JV |
| 1456 |
), |
| 1457 |
false |
| 1458 |
); |
| 1459 |
assert_eq!( |
| 1460 |
is_break( |
| 1461 |
RuleBreakData::LINE_V3_PROPERTY_JL, |
| 1462 |
RuleBreakData::LINE_V3_PROPERTY_H2 |
| 1463 |
), |
| 1464 |
false |
| 1465 |
); |
| 1466 |
// LB27 |
| 1467 |
assert_eq!( |
| 1468 |
is_break( |
| 1469 |
RuleBreakData::LINE_V3_PROPERTY_JL, |
| 1470 |
RuleBreakData::LINE_V3_PROPERTY_IN |
| 1471 |
), |
| 1472 |
false |
| 1473 |
); |
| 1474 |
assert_eq!( |
| 1475 |
is_break( |
| 1476 |
RuleBreakData::LINE_V3_PROPERTY_JL, |
| 1477 |
RuleBreakData::LINE_V3_PROPERTY_PO |
| 1478 |
), |
| 1479 |
false |
| 1480 |
); |
| 1481 |
assert_eq!( |
| 1482 |
is_break( |
| 1483 |
RuleBreakData::LINE_V3_PROPERTY_PR, |
| 1484 |
RuleBreakData::LINE_V3_PROPERTY_JL |
| 1485 |
), |
| 1486 |
false |
| 1487 |
); |
| 1488 |
// LB28 |
| 1489 |
assert_eq!( |
| 1490 |
is_break( |
| 1491 |
RuleBreakData::LINE_V3_PROPERTY_AL, |
| 1492 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1493 |
), |
| 1494 |
false |
| 1495 |
); |
| 1496 |
assert_eq!( |
| 1497 |
is_break( |
| 1498 |
RuleBreakData::LINE_V3_PROPERTY_HL, |
| 1499 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1500 |
), |
| 1501 |
false |
| 1502 |
); |
| 1503 |
// LB29 |
| 1504 |
assert_eq!( |
| 1505 |
is_break( |
| 1506 |
RuleBreakData::LINE_V3_PROPERTY_IS, |
| 1507 |
RuleBreakData::LINE_V3_PROPERTY_AL |
| 1508 |
), |
| 1509 |
false |
| 1510 |
); |
| 1511 |
assert_eq!( |
| 1512 |
is_break( |
| 1513 |
RuleBreakData::LINE_V3_PROPERTY_IS, |
| 1514 |
RuleBreakData::LINE_V3_PROPERTY_HL |
| 1515 |
), |
| 1516 |
false |
| 1517 |
); |
| 1518 |
// LB30b |
| 1519 |
assert_eq!( |
| 1520 |
is_break( |
| 1521 |
RuleBreakData::LINE_V3_PROPERTY_EB, |
| 1522 |
RuleBreakData::LINE_V3_PROPERTY_EM |
| 1523 |
), |
| 1524 |
false |
| 1525 |
); |
| 1526 |
// LB31 |
| 1527 |
assert_eq!( |
| 1528 |
is_break( |
| 1529 |
RuleBreakData::LINE_V3_PROPERTY_ID, |
| 1530 |
RuleBreakData::LINE_V3_PROPERTY_ID |
| 1531 |
), |
| 1532 |
true |
| 1533 |
); |
| 1534 |
} |
| 1535 |
} |