icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

Add methods to iterate exemplar characters

Open lionel-rowe opened this issue 9 months ago • 2 comments

Adds public code_point_ranges and strings methods to ExemplarCharacters to allow iterating through the single- and multi-character entries, respectively:

  • code_point_ranges returns a CodePointRangeIterator (existing struct)
  • strings returns a StringIterator, a new struct that iterates via passing a DiplomatWrite buffer to its next method, writing a null-char-terminated string for Some(string) and an empty string for None (thus differentiating Some("") -> "\0" from None -> "", though in practice Some("") should never occur for exemplar chars). Not sure if there's a better way of iterating strings across the FFI boundary.

Thus for hu locale and Main set:

# `code_point_ranges`
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'z', 'á', 'é', 'í', 'ó', 'ö', 'ú', 'ü', 'ő', 'ű'
# `strings`
"ccs", "cs", "ddz", "ddzs", "dz", "dzs", "ggy", "gy", "lly", "ly", "nny", "ny", "ssz", "sz", "tty", "ty", "zs", "zzs"

I also added a tab to the WASM demo to illustrate how these can be used from JS/TS.

lionel-rowe avatar Feb 07 '25 11:02 lionel-rowe

Hi @lionel-rowe, do you plan to address @Manishearth's feedback?

sffc avatar May 06 '25 20:05 sffc

@sffc Sorry for delayed reply, I had a go at fixing the issues but TBH my Rust knowledge is lacking. I might have another crack at it later but not sure when I'll have time.

lionel-rowe avatar May 08 '25 08:05 lionel-rowe

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 29 '25 17:09 CLAassistant

Ignore the CLA assistant if you already signed it. It's buggy right now, we'll let you know when you can sign if you haven't signed already

Manishearth avatar Sep 29 '25 18:09 Manishearth

Ignore the CLA assistant if you already signed it. It's buggy right now, we'll let you know when you can sign if you haven't signed already

Fixed

sffc avatar Sep 29 '25 20:09 sffc