Switched to use StringUtils for un/captitalize
This commit is contained in:
parent
79cbf76761
commit
538a8d35ae
4 changed files with 11 additions and 47 deletions
|
@ -19,6 +19,7 @@ package rife.render;
|
||||||
|
|
||||||
import rife.template.Template;
|
import rife.template.Template;
|
||||||
import rife.template.ValueRenderer;
|
import rife.template.ValueRenderer;
|
||||||
|
import rife.tools.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Capitalizes a template value.</p>
|
* <p>Capitalizes a template value.</p>
|
||||||
|
@ -40,6 +41,6 @@ public class Capitalize implements ValueRenderer {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String render(Template template, String valueId, String differentiator) {
|
public String render(Template template, String valueId, String differentiator) {
|
||||||
return RenderUtils.capitalize(template.getValueOrAttribute(differentiator));
|
return StringUtils.capitalize(template.getValueOrAttribute(differentiator));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ public final class RenderUtils {
|
||||||
/**
|
/**
|
||||||
* Returns the Swatch Internet (.beat) Time for the give date-time.
|
* 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})
|
* @return the .beat time. (eg.: {@code @248})
|
||||||
*/
|
*/
|
||||||
public static String beatTime(ZonedDateTime zonedDateTime) {
|
public static String beatTime(ZonedDateTime zonedDateTime) {
|
||||||
|
@ -116,19 +116,6 @@ public final class RenderUtils {
|
||||||
return String.format("@%03d", beats);
|
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.
|
* Encodes a String to JavaScript/ECMAScript.
|
||||||
*
|
*
|
||||||
|
@ -161,8 +148,8 @@ public final class RenderUtils {
|
||||||
* Fetches the content (body) of a URL.
|
* Fetches the content (body) of a URL.
|
||||||
*
|
*
|
||||||
* @param url the URL sSng.
|
* @param url the URL sSng.
|
||||||
* @param defaultContent the default content to return if none fetched.
|
* @param defaultContent the default content to return if none fetched
|
||||||
* @return the url content, or empty.
|
* @return the url content, or empty
|
||||||
*/
|
*/
|
||||||
public static String fetchUrl(String url, String defaultContent) {
|
public static String fetchUrl(String url, String defaultContent) {
|
||||||
try {
|
try {
|
||||||
|
@ -232,7 +219,7 @@ public final class RenderUtils {
|
||||||
/**
|
/**
|
||||||
* Masks characters in a String.
|
* Masks characters in a String.
|
||||||
*
|
*
|
||||||
* @param src the source String.
|
* @param src the source String
|
||||||
* @param mask the String to mask characters with
|
* @param mask the String to mask characters with
|
||||||
* @param unmasked the number of characters to leave unmasked
|
* @param unmasked the number of characters to leave unmasked
|
||||||
* @param fromStart to unmask characters from the start of the String
|
* @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.
|
* Normalizes a String for inclusion in a URL path.
|
||||||
*
|
*
|
||||||
* @param src The source String
|
* @param src the source String
|
||||||
* @return the normalized String
|
* @return the normalized String
|
||||||
*/
|
*/
|
||||||
public static String normalize(String src) {
|
public static String normalize(String src) {
|
||||||
|
@ -413,19 +400,6 @@ public final class RenderUtils {
|
||||||
return new String(buff, 0, offset);
|
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>
|
* <p>Returns the formatted server uptime.</p>
|
||||||
*
|
*
|
||||||
|
@ -448,7 +422,7 @@ public final class RenderUtils {
|
||||||
*
|
*
|
||||||
* @param uptime the uptime in milliseconds
|
* @param uptime the uptime in milliseconds
|
||||||
* @param properties the format properties
|
* @param properties the format properties
|
||||||
* @return the formatted uptime.
|
* @return the formatted uptime
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnnecessaryUnicodeEscape")
|
@SuppressWarnings("UnnecessaryUnicodeEscape")
|
||||||
public static String uptime(long uptime, Properties properties) {
|
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.
|
* Validates a credit card number using the Luhn algorithm.
|
||||||
*
|
*
|
||||||
* @param cc the credit card number
|
* @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) {
|
public static boolean validateCreditCard(String cc) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -19,6 +19,7 @@ package rife.render;
|
||||||
|
|
||||||
import rife.template.Template;
|
import rife.template.Template;
|
||||||
import rife.template.ValueRenderer;
|
import rife.template.ValueRenderer;
|
||||||
|
import rife.tools.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Un-capitalizes a template value.</p>
|
* <p>Un-capitalizes a template value.</p>
|
||||||
|
@ -40,6 +41,6 @@ public class Uncapitalize implements ValueRenderer {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String render(Template template, String valueId, String differentiator) {
|
public String render(Template template, String valueId, String differentiator) {
|
||||||
return RenderUtils.uncapitalize(template.getValueOrAttribute(differentiator));
|
return StringUtils.uncapitalize(template.getValueOrAttribute(differentiator));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,12 +35,6 @@ class TestRenderUtils {
|
||||||
.isEqualTo(TestCase.SAMPLE_TEXT);
|
.isEqualTo(TestCase.SAMPLE_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCapitalize() {
|
|
||||||
assertThat(RenderUtils.capitalize("a")).isEqualTo("A");
|
|
||||||
assertThat(RenderUtils.capitalize("")).as("empty").isEqualTo("");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testHtmlEntities() {
|
void testHtmlEntities() {
|
||||||
assertThat(RenderUtils.htmlEntities(SAMPLE_GERMAN))
|
assertThat(RenderUtils.htmlEntities(SAMPLE_GERMAN))
|
||||||
|
@ -78,12 +72,6 @@ class TestRenderUtils {
|
||||||
assertThat(RenderUtils.swapCase(SAMPLE_GERMAN)).isEqualTo("mÖCHTEN sIE EIN PAAR äPFEL?");
|
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
|
@Test
|
||||||
void testValidateCreditCard() {
|
void testValidateCreditCard() {
|
||||||
assertThat(RenderUtils.validateCreditCard("4505 4672 3366 6430")).as("visa").isTrue();
|
assertThat(RenderUtils.validateCreditCard("4505 4672 3366 6430")).as("visa").isTrue();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue