Description
#5565 Recently brings locale option to LineSegmenter, but it do not take effect in some situation.
In UAX#14 says:
Note: If language information is available, it can be used to determine which character is used as the opening quote and which as the closing quote. See the information in Section 6.2, General Punctuation, in [Unicode]. In such a case, the quotation marks could be tailored to either OP or CL depending on their actual usage.
In Chinese and Japanese, quotation mark U+201C and U+201D meets the above condition and should be classified to OP and CL respectively instead of QU. This is implemented in icu4c and mainstream browsers. In icu4c text like 你“好
will have break opportunity in 你|“好
if zh
locale is given. But in icu4x it doesn't:
use icu_segmenter::{LineBreakOptions, LineSegmenter};
fn main() {
let text = std::env::args()
.nth(1)
.unwrap_or_else(|| "你“好”啊".to_string());
let mut options = LineBreakOptions::default();
options.content_locale = Some("zh".parse().unwrap());
let segmenter = LineSegmenter::new_auto_with_options(options);
// Print the text with a '|' character at each line break.
let mut last_breakpoint = 0;
for breakpoint in segmenter.segment_str(&text) {
print!("{}", &text[last_breakpoint..breakpoint]);
print!("|");
last_breakpoint = breakpoint;
}
}
The above code gives 你“好”啊
instead of 你|“好”|啊
.