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

caseFold.equals doesn't implement full case folding #1

Open
babolivier opened this issue Sep 19, 2019 · 2 comments
Open

caseFold.equals doesn't implement full case folding #1

babolivier opened this issue Sep 19, 2019 · 2 comments

Comments

@babolivier
Copy link

babolivier commented Sep 19, 2019

The unicode spec on case folding specifies that ß and (its uppercase version) should equal to ss when doing a full case folding, as shown by the Python implementation:

>>> 'ẞ'.casefold()
'ss'
>>> 'ß'.casefold()
'ss'

However, when trying to compare those two characters to their casefolded version using caseFold.equals, this happens:

> casefold.caseFold.equals("ẞ", "ss")
false
> casefold.caseFold.equals("ß", "ss")
false
@babolivier babolivier changed the title caseFold.equals doesn't always return the right result caseFold.equals doesn't implement full case folding Sep 19, 2019
@JoBrad
Copy link
Owner

JoBrad commented Sep 20, 2019

Hey, thanks for the feedback! I am in the middle of converting this to make better use of ES6 modules, and updating the string comparison was also on my list.

If you have an improvement for it, feel free to submit a PR.

@joshxyzhimself
Copy link

Hi, @babolivier, if you are looking for full case folding I tried implementing the following according to the spec:

#  A. To do a simple case folding, use the mappings with status C + S.
#  B. To do a full case folding, use the mappings with status C + F.
import { simple_casefold, full_casefold, special_casefold } from './casefold.mjs';

console.log(simple_casefold('\u0041 \u00DF \u0130'));
console.log(full_casefold('\u0041 \u00DF \u0130'));
console.log(special_casefold('\u0041 \u00DF \u0130'));
console.log(`MASSE === Maße: ${full_casefold('MASSE') === full_casefold('Maße')}`);
user@device:~/modules$ node ./casefold.test.mjs 
a ß İ
a ss i̇
a ss i
MASSE === Maße: true

I used Unicode 14.0.0 because 15.0.0 is still in Draft for this year until it's release on September. It is in ECMAScript Modules (.mjs) format but can easily be converted to CommonJS (.js/.cjs) format. Also requesting for comments on possible improvements. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants