From 44e2e86f19bd9e7acddad50506dad0737fa032d9 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 9 Sep 2023 14:32:03 +0200 Subject: [PATCH] Capitalize the first letter of custom keys This is more useful than turning the entire string full caps. --- srcs/juloo.keyboard2/KeyModifier.java | 3 ++- srcs/juloo.keyboard2/StringUtils.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 srcs/juloo.keyboard2/StringUtils.java diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index 32ee570..6d0792f 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -122,7 +122,8 @@ class KeyModifier c = Character.toUpperCase(kc); return (kc == c) ? k : k.withChar(c); case String: - return KeyValue.makeStringKey(k.getString().toUpperCase(), k.getFlags()); + String s = Utils.capitalize_string(k.getString()); + return KeyValue.makeStringKey(s, k.getFlags()); default: return k; } } diff --git a/srcs/juloo.keyboard2/StringUtils.java b/srcs/juloo.keyboard2/StringUtils.java new file mode 100644 index 0000000..2994509 --- /dev/null +++ b/srcs/juloo.keyboard2/StringUtils.java @@ -0,0 +1,12 @@ +package juloo.keyboard2; + +final class Utils +{ + /** Turn the first letter of a string uppercase. */ + public static String capitalize_string(String s) + { + // Make sure not to cut a code point in half + int i = s.offsetByCodePoints(0, 1); + return s.substring(0, i).toUpperCase() + s.substring(i); + } +}