From 538a8d35aed57bbc2204c472d7188a9ea0401971 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 24 Mar 2023 09:22:30 -0700 Subject: [PATCH] Switched to use StringUtils for un/captitalize --- lib/src/main/java/rife/render/Capitalize.java | 3 +- .../main/java/rife/render/RenderUtils.java | 40 ++++--------------- .../main/java/rife/render/Uncapitalize.java | 3 +- .../java/rife/render/TestRenderUtils.java | 12 ------ 4 files changed, 11 insertions(+), 47 deletions(-) diff --git a/lib/src/main/java/rife/render/Capitalize.java b/lib/src/main/java/rife/render/Capitalize.java index 9e9bd91..edce803 100644 --- a/lib/src/main/java/rife/render/Capitalize.java +++ b/lib/src/main/java/rife/render/Capitalize.java @@ -19,6 +19,7 @@ package rife.render; import rife.template.Template; import rife.template.ValueRenderer; +import rife.tools.StringUtils; /** *

Capitalizes a template value.

@@ -40,6 +41,6 @@ public class Capitalize implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return RenderUtils.capitalize(template.getValueOrAttribute(differentiator)); + return StringUtils.capitalize(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/RenderUtils.java b/lib/src/main/java/rife/render/RenderUtils.java index e9fbe3c..f46f1a2 100644 --- a/lib/src/main/java/rife/render/RenderUtils.java +++ b/lib/src/main/java/rife/render/RenderUtils.java @@ -106,7 +106,7 @@ public final class RenderUtils { /** * Returns the Swatch Internet (.beat) Time for the give date-time. * - * @param zonedDateTime the date and time. + * @param zonedDateTime the date and time * @return the .beat time. (eg.: {@code @248}) */ public static String beatTime(ZonedDateTime zonedDateTime) { @@ -116,19 +116,6 @@ public final class RenderUtils { return String.format("@%03d", beats); } - /** - * Capitalizes a String. - * - * @param src the source String - * @return the capitalized String - */ - public static String capitalize(String src) { - if (src == null || src.isBlank()) { - return src; - } - return src.substring(0, 1).toUpperCase(Localization.getLocale()) + src.substring(1); - } - /** * Encodes a String to JavaScript/ECMAScript. * @@ -161,8 +148,8 @@ public final class RenderUtils { * Fetches the content (body) of a URL. * * @param url the URL sSng. - * @param defaultContent the default content to return if none fetched. - * @return the url content, or empty. + * @param defaultContent the default content to return if none fetched + * @return the url content, or empty */ public static String fetchUrl(String url, String defaultContent) { try { @@ -232,7 +219,7 @@ public final class RenderUtils { /** * Masks characters in a String. * - * @param src the source String. + * @param src the source String * @param mask the String to mask characters with * @param unmasked the number of characters to leave unmasked * @param fromStart to unmask characters from the start of the String @@ -262,7 +249,7 @@ public final class RenderUtils { /** * Normalizes a String for inclusion in a URL path. * - * @param src The source String + * @param src the source String * @return the normalized String */ public static String normalize(String src) { @@ -413,19 +400,6 @@ public final class RenderUtils { return new String(buff, 0, offset); } - /** - * Uncapitalizes a String. - * - * @param src the source String - * @return the uncapitalized String - */ - public static String uncapitalize(String src) { - if (src == null || src.isBlank()) { - return src; - } - return src.substring(0, 1).toLowerCase(Localization.getLocale()) + src.substring(1); - } - /** *

Returns the formatted server uptime.

* @@ -448,7 +422,7 @@ public final class RenderUtils { * * @param uptime the uptime in milliseconds * @param properties the format properties - * @return the formatted uptime. + * @return the formatted uptime */ @SuppressWarnings("UnnecessaryUnicodeEscape") public static String uptime(long uptime, Properties properties) { @@ -500,7 +474,7 @@ public final class RenderUtils { * Validates a credit card number using the Luhn algorithm. * * @param cc the credit card number - * @return {@code trude} if the credit card number is valid + * @return {@code true} if the credit card number is valid */ public static boolean validateCreditCard(String cc) { try { diff --git a/lib/src/main/java/rife/render/Uncapitalize.java b/lib/src/main/java/rife/render/Uncapitalize.java index 1e670a7..a4ecd24 100644 --- a/lib/src/main/java/rife/render/Uncapitalize.java +++ b/lib/src/main/java/rife/render/Uncapitalize.java @@ -19,6 +19,7 @@ package rife.render; import rife.template.Template; import rife.template.ValueRenderer; +import rife.tools.StringUtils; /** *

Un-capitalizes a template value.

@@ -40,6 +41,6 @@ public class Uncapitalize implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return RenderUtils.uncapitalize(template.getValueOrAttribute(differentiator)); + return StringUtils.uncapitalize(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/test/java/rife/render/TestRenderUtils.java b/lib/src/test/java/rife/render/TestRenderUtils.java index f0f55c5..bed7b86 100644 --- a/lib/src/test/java/rife/render/TestRenderUtils.java +++ b/lib/src/test/java/rife/render/TestRenderUtils.java @@ -35,12 +35,6 @@ class TestRenderUtils { .isEqualTo(TestCase.SAMPLE_TEXT); } - @Test - void testCapitalize() { - assertThat(RenderUtils.capitalize("a")).isEqualTo("A"); - assertThat(RenderUtils.capitalize("")).as("empty").isEqualTo(""); - } - @Test void testHtmlEntities() { assertThat(RenderUtils.htmlEntities(SAMPLE_GERMAN)) @@ -78,12 +72,6 @@ class TestRenderUtils { assertThat(RenderUtils.swapCase(SAMPLE_GERMAN)).isEqualTo("mÖCHTEN sIE EIN PAAR äPFEL?"); } - @Test - void testUcapitalize() { - assertThat(RenderUtils.uncapitalize("A")).isEqualTo("a"); - assertThat(RenderUtils.uncapitalize("")).as("empty").isEqualTo(""); - } - @Test void testValidateCreditCard() { assertThat(RenderUtils.validateCreditCard("4505 4672 3366 6430")).as("visa").isTrue();