Switched to use StringUtils for un/captitalize

This commit is contained in:
Erik C. Thauvin 2023-03-24 09:22:30 -07:00
parent 79cbf76761
commit 538a8d35ae
4 changed files with 11 additions and 47 deletions

View file

@ -19,6 +19,7 @@ package rife.render;
import rife.template.Template;
import rife.template.ValueRenderer;
import rife.tools.StringUtils;
/**
* <p>Capitalizes a template value.</p>
@ -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));
}
}

View file

@ -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);
}
/**
* <p>Returns the formatted server uptime.</p>
*
@ -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 {

View file

@ -19,6 +19,7 @@ package rife.render;
import rife.template.Template;
import rife.template.ValueRenderer;
import rife.tools.StringUtils;
/**
* <p>Un-capitalizes a template value.</p>
@ -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));
}
}

View file

@ -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();