You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/02/27 07:58:29 UTC
[camel] branch master updated (48302cb -> a80ff68)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.
from 48302cb Polished
new c5d327f CAMEL-16250 - support more edge cases of dashToCamelCase conversion
new a80ff68 CAMEL-16250 - support more edge cases of dashToCamelCase conversion
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/org/apache/camel/util/StringHelper.java | 17 ++++----
.../org/apache/camel/util/StringHelperTest.java | 48 +++++++++++++++++++++-
2 files changed, 57 insertions(+), 8 deletions(-)
[camel] 01/02: CAMEL-16250 - support more edge cases of
dashToCamelCase conversion
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit c5d327f8dd530b3219c0cab695cfe34411f314ba
Author: Aurélien Pupier <ap...@redhat.com>
AuthorDate: Tue Feb 23 15:13:35 2021 +0100
CAMEL-16250 - support more edge cases of dashToCamelCase conversion
Signed-off-by: Aurélien Pupier <ap...@redhat.com>
---
.../java/org/apache/camel/util/StringHelper.java | 16 ++++----
.../org/apache/camel/util/StringHelperTest.java | 48 +++++++++++++++++++++-
2 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
index 34607c5..686af48 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
@@ -470,14 +470,14 @@ public final class StringHelper {
}
StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < text.length(); i++) {
- char c = text.charAt(i);
- if (c == '-') {
- i++;
- sb.append(Character.toUpperCase(text.charAt(i)));
- } else {
- sb.append(c);
+ String[] splittedString = text.split("\\-");
+ for (int i = 0; i < splittedString.length; i++) {
+ String currentToken = splittedString[i];
+ if (i == 0) {
+ sb.append(currentToken);
+ } else if (!currentToken.isEmpty()) {
+ sb.append(Character.toUpperCase(currentToken.charAt(0)));
+ sb.append(currentToken.substring(1));
}
}
return sb.toString();
diff --git a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
index a75e476..ec122ec 100644
--- a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
+++ b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
@@ -16,10 +16,12 @@
*/
package org.apache.camel.util;
+import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import static org.apache.camel.util.StringHelper.*;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.assertj.core.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.*;
public class StringHelperTest {
@@ -54,6 +56,50 @@ public class StringHelperTest {
assertEquals("available-phone-number-country", camelCaseToDash("availablePhoneNumberCountry"));
assertEquals("available-phone-number-country", camelCaseToDash("AvailablePhoneNumberCountry"));
}
+
+ @Nested
+ class DashToCamelCase {
+
+ @Test
+ void testDashToCamelCaseWithNull() throws Exception {
+ assertThat(dashToCamelCase(null)).isNull();
+ }
+
+ @Test
+ void testDashToCamelCaseWithEmptyValue() throws Exception {
+ assertThat(dashToCamelCase("")).isEmpty();
+ }
+
+ @Test
+ void testDashToCamelCaseWithNoDash() throws Exception {
+ assertThat(dashToCamelCase("a")).isEqualTo("a");
+ }
+
+ @Test
+ void testDashToCamelCaseWithOneDash() throws Exception {
+ assertThat(dashToCamelCase("a-b")).isEqualTo("aB");
+ }
+
+ @Test
+ void testDashToCamelCaseWithSeveralDashes() throws Exception {
+ assertThat(dashToCamelCase("a-bb-cc-dd")).isEqualTo("aBbCcDd");
+ }
+
+ @Test
+ void testDashToCamelCaseWithEndDash() throws Exception {
+ assertThat(dashToCamelCase("a-")).isEqualTo("a");
+ }
+
+ @Test
+ void testDashToCamelCaseWithEndDashes() throws Exception {
+ assertThat(dashToCamelCase("a----")).isEqualTo("a");
+ }
+
+ @Test
+ void testDashToCamelCaseWithSeceralDashesGrouped() throws Exception {
+ assertThat(dashToCamelCase("a--b")).isEqualTo("aB");
+ }
+ }
@Test
public void testSplitWords() throws Exception {
[camel] 02/02: CAMEL-16250 - support more edge cases of
dashToCamelCase conversion
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit a80ff680e445e2b9af0b365b1ee418504c6285c5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 27 08:57:59 2021 +0100
CAMEL-16250 - support more edge cases of dashToCamelCase conversion
---
.../java/org/apache/camel/util/StringHelper.java | 25 ++++++++++++----------
.../org/apache/camel/util/StringHelperTest.java | 18 ++++++++--------
2 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
index 686af48..fa0c827 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
@@ -46,8 +46,7 @@ public final class StringHelper {
* @throws NullPointerException if <code>s</code> is <code>null</code>.
*/
public static String sanitize(String s) {
- return s
- .replace(':', '-')
+ return s.replace(':', '-')
.replace('_', '-')
.replace('.', '-')
.replace('/', '-')
@@ -469,15 +468,19 @@ public final class StringHelper {
return text;
}
- StringBuilder sb = new StringBuilder();
- String[] splittedString = text.split("\\-");
- for (int i = 0; i < splittedString.length; i++) {
- String currentToken = splittedString[i];
- if (i == 0) {
- sb.append(currentToken);
- } else if (!currentToken.isEmpty()) {
- sb.append(Character.toUpperCase(currentToken.charAt(0)));
- sb.append(currentToken.substring(1));
+ // there is at least 1 dash so the capacity can be shorter
+ StringBuilder sb = new StringBuilder(length - 1);
+ boolean upper = false;
+ for (int i = 0; i < length; i++) {
+ char c = text.charAt(i);
+ if (c == '-') {
+ upper = true;
+ } else {
+ if (upper) {
+ c = Character.toUpperCase(c);
+ }
+ sb.append(c);
+ upper = false;
}
}
return sb.toString();
diff --git a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
index ec122ec..3c89c24 100644
--- a/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
+++ b/core/camel-util/src/test/java/org/apache/camel/util/StringHelperTest.java
@@ -56,45 +56,45 @@ public class StringHelperTest {
assertEquals("available-phone-number-country", camelCaseToDash("availablePhoneNumberCountry"));
assertEquals("available-phone-number-country", camelCaseToDash("AvailablePhoneNumberCountry"));
}
-
+
@Nested
class DashToCamelCase {
-
+
@Test
void testDashToCamelCaseWithNull() throws Exception {
assertThat(dashToCamelCase(null)).isNull();
}
-
+
@Test
void testDashToCamelCaseWithEmptyValue() throws Exception {
assertThat(dashToCamelCase("")).isEmpty();
}
-
+
@Test
void testDashToCamelCaseWithNoDash() throws Exception {
assertThat(dashToCamelCase("a")).isEqualTo("a");
}
-
+
@Test
void testDashToCamelCaseWithOneDash() throws Exception {
assertThat(dashToCamelCase("a-b")).isEqualTo("aB");
}
-
+
@Test
void testDashToCamelCaseWithSeveralDashes() throws Exception {
assertThat(dashToCamelCase("a-bb-cc-dd")).isEqualTo("aBbCcDd");
}
-
+
@Test
void testDashToCamelCaseWithEndDash() throws Exception {
assertThat(dashToCamelCase("a-")).isEqualTo("a");
}
-
+
@Test
void testDashToCamelCaseWithEndDashes() throws Exception {
assertThat(dashToCamelCase("a----")).isEqualTo("a");
}
-
+
@Test
void testDashToCamelCaseWithSeceralDashesGrouped() throws Exception {
assertThat(dashToCamelCase("a--b")).isEqualTo("aB");