This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new ecf0862 CAMEL-17499: Renaming inconsistent data format names in model ecf0862 is described below commit ecf0862c5a7aa2c2d3970d4afc73477ec3a1a94d Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Jan 18 15:47:59 2022 +0100 CAMEL-17499: Renaming inconsistent data format names in model --- .../org/apache/camel/tooling/util/Strings.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java index d853a2b..8bec20b 100644 --- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java +++ b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java @@ -17,6 +17,7 @@ package org.apache.camel.tooling.util; import java.util.Collection; +import java.util.Locale; /** * Some String helper methods @@ -190,4 +191,47 @@ public final class Strings { return sb.toString(); } + /** + * Converts the string from camel case into dash format (helloGreatWorld -> hello-great-world) + * + * @param text the string + * @return the string camel cased + */ + public static String camelCaseToDash(String text) { + if (text == null || text.isEmpty()) { + return text; + } + StringBuilder answer = new StringBuilder(); + + Character prev = null; + Character next = null; + char[] arr = text.toCharArray(); + for (int i = 0; i < arr.length; i++) { + char ch = arr[i]; + if (i < arr.length - 1) { + next = arr[i + 1]; + } else { + next = null; + } + if (ch == '-' || ch == '_') { + answer.append("-"); + } else if (Character.isUpperCase(ch) && prev != null && !Character.isUpperCase(prev)) { + if (prev != '-' && prev != '_') { + answer.append("-"); + } + answer.append(ch); + } else if (Character.isUpperCase(ch) && prev != null && next != null && Character.isLowerCase(next)) { + if (prev != '-' && prev != '_') { + answer.append("-"); + } + answer.append(ch); + } else { + answer.append(ch); + } + prev = ch; + } + + return answer.toString().toLowerCase(Locale.ENGLISH); + } + }