diff options
author | Artur Signell <artur@vaadin.com> | 2015-05-27 22:03:26 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-05-29 13:33:47 +0000 |
commit | ed5ad86b114ccb4d6ab08e19a734bdb8b3342399 (patch) | |
tree | fa6bfdda2d616589acc2205ad3da84e9f513a691 /shared/src/com | |
parent | 4a79c3c5c5cf14dde6f696a0fe924227d00a0ec5 (diff) | |
download | vaadin-framework-ed5ad86b114ccb4d6ab08e19a734bdb8b3342399.tar.gz vaadin-framework-ed5ad86b114ccb4d6ab08e19a734bdb8b3342399.zip |
Ensure method and property names are capitalized using English locale (#13389)
Change-Id: Idde4fc54950f2bb83e0bb8d36a84a5bf075eb8de
Diffstat (limited to 'shared/src/com')
-rw-r--r-- | shared/src/com/vaadin/shared/util/SharedUtil.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/shared/src/com/vaadin/shared/util/SharedUtil.java b/shared/src/com/vaadin/shared/util/SharedUtil.java index bc5d87b9f5..d363d767be 100644 --- a/shared/src/com/vaadin/shared/util/SharedUtil.java +++ b/shared/src/com/vaadin/shared/util/SharedUtil.java @@ -149,11 +149,12 @@ public class SharedUtil implements Serializable { sb.append(parts[i]); sb.append(separator); } - return sb.substring(0, sb.length() - 1); + return sb.substring(0, sb.length() - separator.length()); } /** - * Capitalizes the first character in the given string + * Capitalizes the first character in the given string in a way suitable for + * use in code (methods, properties etc) * * @since 7.4 * @param string @@ -239,4 +240,29 @@ public class SharedUtil implements Serializable { return uri; } + /** + * Converts a dash ("-") separated string into camelCase. + * <p> + * Examples: + * <p> + * {@literal foo} becomes {@literal foo} {@literal foo-bar} becomes + * {@literal fooBar} {@literal foo--bar} becomes {@literal fooBar} + * + * @since + * @param dashSeparated + * The dash separated string to convert + * @return a camelCase version of the input string + */ + public static String dashSeparatedToCamelCase(String dashSeparated) { + if (dashSeparated == null) { + return null; + } + String[] parts = dashSeparated.split("-"); + for (int i = 1; i < parts.length; i++) { + parts[i] = capitalize(parts[i]); + } + + return join(parts, ""); + } + } |