Skip to content

GraphemeCursor::next_boundary() returns incorrect boundaryย #115

Open
@noib3

Description

@noib3

The grapheme boundaries of "๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡ฎ๐Ÿ‡ด" should be 8 and 16, but by feeding GraphemeCursor the individual RIS codepoints I get 8 and 12. Am I using the API incorrectly or is this a bug?

use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};

fn main() {
    let s = "๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡ฎ๐Ÿ‡ด";

    let mut cursor = GraphemeCursor::new(0, s.len(), true);

    // ๐Ÿ‡ท๐Ÿ‡ธ

    match cursor.next_boundary("๐Ÿ‡ท", 0) {
        Err(GraphemeIncomplete::NextChunk) => {}
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ธ", 4) {
        Err(GraphemeIncomplete::PreContext(4)) => {
            cursor.provide_context("๐Ÿ‡ท", 0);
        }
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ธ", 4) {
        Err(GraphemeIncomplete::NextChunk) => {}
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ฎ", 8) {
        Err(GraphemeIncomplete::PreContext(8)) => {
            cursor.provide_context("๐Ÿ‡ธ", 4);
        }
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ฎ", 8) {
        Err(GraphemeIncomplete::PreContext(4)) => {
            cursor.provide_context("๐Ÿ‡ท", 0);
        }
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ฎ", 8) {
        Ok(Some(8)) => {}
        _ => unreachable!(),
    }

    // ๐Ÿ‡ฎ๐Ÿ‡ด

    match cursor.next_boundary("๐Ÿ‡ฎ", 8) {
        Err(GraphemeIncomplete::NextChunk) => {}
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ด", 12) {
        Err(GraphemeIncomplete::PreContext(12)) => {
            cursor.provide_context("๐Ÿ‡ฎ", 8);
        }
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ด", 12) {
        Err(GraphemeIncomplete::PreContext(8)) => {
            cursor.provide_context("๐Ÿ‡ธ", 4);
        }
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ด", 12) {
        Err(GraphemeIncomplete::PreContext(4)) => {
            cursor.provide_context("๐Ÿ‡ท", 0);
        }
        _ => unreachable!(),
    }

    match cursor.next_boundary("๐Ÿ‡ด", 12) {
        Ok(Some(16)) => {}
        Ok(Some(12)) => panic!("this should be 16"),
        _ => unreachable!(),
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy