Skip to content

Improve Character emulation #10113

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion user/super/com/google/gwt/emul/java/lang/CaseMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,23 @@ public static char charToLowerCase(char c) {
}

public static char charToUpperCase(char c) {
return String.valueOf(c).toUpperCase().charAt(0);
String upper = String.valueOf(c).toUpperCase();
return hasExtraCodePoints(upper) ? c : upper.charAt(0);
}

public static int intToLowerCase(int codePoint) {
return String.NativeString.fromCodePoint(codePoint).toLowerCase().codePointAt(0);
}

public static int intToUpperCase(int codePoint) {
String upper = String.NativeString.fromCodePoint(codePoint).toUpperCase();
return hasExtraCodePoints(upper) ? codePoint : upper.codePointAt(0);
}

// If String.toUpperCase produces more than 1 codepoint, Character.toUpperCase should
// act either as identity or title-case conversion (not supported in GWT).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a failing test and mark it ignored so we can see about restoring it when it works?

private static boolean hasExtraCodePoints(String str) {
return str.asNativeString().codePointAt(1) > 0;
}

private CaseMapper() {}
Expand Down
Loading