Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow line segmenter break around quotation mark for CJ #5595

Open
peng1999 opened this issue Sep 25, 2024 · 0 comments
Open

Allow line segmenter break around quotation mark for CJ #5595

peng1999 opened this issue Sep 25, 2024 · 0 comments
Labels
C-segmentation Component: Segmentation

Comments

@peng1999
Copy link

#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 你|“好”|啊.

@makotokato makotokato added the C-segmentation Component: Segmentation label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-segmentation Component: Segmentation
Projects
None yet
Development

No branches or pull requests

2 participants