Enum StringHelpers
- All Implemented Interfaces:
Helper<Object>
,Serializable
,Comparable<StringHelpers>
,java.lang.constant.Constable
Commons string function helpers.
- Since:
- 0.2.2
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionTruncates a string if it is longer than the specified number of characters.Capitalizes all the whitespace separated words in a String.Capitalizes the first character of the value.Centers the value in a field of a given width.Removes all values of arg from the given string.Usage:If value evaluates to False, uses the given default.Joins an array, iterator or an iterable with a string.Left-aligns the value in a field of a given width.Converts a string into all lowercase.Usage:Usage:Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.Right-aligns the value in a field of a given width.Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens.Formats the variable according to the argument, a string formatting specifier.Strips all [X]HTML tags.Returns a newCharSequence
that is a subsequence of this sequence.Converts a string into all uppercase.Wraps words at specified line length.Maps values for true, false and (optionally) null, to the strings "yes", "no", "maybe". -
Method Summary
Modifier and TypeMethodDescriptionApply the helper to the context.static void
register
(Handlebars handlebars) Register all the text helpers.void
registerHelper
(Handlebars handlebars) Register the helper in a handlebars instance.static StringHelpers
Returns the enum constant of this type with the specified name.static StringHelpers[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.Methods inherited from class java.lang.Enum
compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Enum Constant Details
-
capitalizeFirst
Capitalizes the first character of the value. For example:{{capitalizeFirst value}}
If value is "handlebars.java", the output will be "Handlebars.java". -
center
Centers the value in a field of a given width. For example:{{center value size=19 [pad="char"] }}
If value is "Handlebars.java", the output will be " Handlebars.java ". -
cut
Removes all values of arg from the given string. For example:{{cut value [" "]}}
If value is "String with spaces", the output will be "Stringwithspaces". -
defaultIfEmpty
If value evaluates to False, uses the given default. Otherwise, uses the value. For example:{{defaultIfEmpty value ["nothing"] }} If value is "" (the empty string), the output will be nothing.
-
join
Joins an array, iterator or an iterable with a string. For example:{{join value " // " [prefix=""] [suffix=""]}}
If value is the list ['a', 'b', 'c'], the output will be the string "a // b // c".
Or:{{join "a" "b" "c" " // " [prefix=""] [suffix=""]}} Join the "a", "b", "c", the output will be the string "a // b // c".
-
ljust
Left-aligns the value in a field of a given width. Argument: field size For example:{{ljust value 20 [pad=" "] }}
If value is Handlebars.java, the output will be "Handlebars.java ". -
rjust
Right-aligns the value in a field of a given width. Argument: field size For example:{{rjust value 20 [pad=" "] }}
If value is Handlebars.java, the output will be " Handlebars.java". -
substring
Returns a newCharSequence
that is a subsequence of this sequence. The subsequence starts with thechar
value at the specified index and ends with thechar
value at index end - 1 Argument: start offset end offset For example:{{substring value 11 }}
If value is Handlebars.java, the output will be "java". or{{substring value 0 10 }}
If value is Handlebars.java, the output will be "Handlebars". -
lower
Converts a string into all lowercase. For example:{{lower value}}
If value is 'Still MAD At Yoko', the output will be 'still mad at yoko'. -
upper
Converts a string into all uppercase. For example:{{upper value}}
If value is 'Hello', the output will be 'HELLO'. -
slugify
Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace. For example:{{slugify value}}
If value is "Joel is a slug", the output will be "joel-is-a-slug". -
stringFormat
Formats the variable according to the argument, a string formatting specifier. For example:{{stringFormat string param0 param1 ... paramN}}
If value is "Hello %s" "handlebars.java", the output will be "Hello handlebars.java".- See Also:
-
stripTags
Strips all [X]HTML tags. For example:{{stripTags value}}
-
capitalize
Capitalizes all the whitespace separated words in a String. For example:{{ capitalize value [fully=false]}}
If value is "my first post", the output will be "My First Post". -
abbreviate
Truncates a string if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence ("..."). Argument: Number of characters to truncate to For example:{{abbreviate value 13 }}
If value is "Handlebars rocks", the output will be "Handlebars...". -
wordWrap
Wraps words at specified line length. Argument: number of characters at which to wrap the text For example:{{ wordWrap value 5 }}
If value is Joel is a slug, the output would be:Joel is a slug
-
replace
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. For example:{{ replace value "..." "rocks" }}
If value is "Handlebars ...", the output will be "Handlebars rocks". -
yesno
Maps values for true, false and (optionally) null, to the strings "yes", "no", "maybe". For example:{{yesno value [yes="yes"] [no="no"] maybe=["maybe"] }}
-
dateFormat
Usage:
{{dateFormat date ["format"] [format="format"][locale="locale"][tz=timeZone|timeZoneId] [time="format"]}}
Format parameters is one of:- "full": full date format. For example: Tuesday, June 19, 2012
- "long": long date format. For example: June 19, 2012
- "medium": medium date format. For example: Jun 19, 2012
- "short": short date format. For example: 6/19/12
- "pattern": a
DateTimeFormatter
pattern.
- The "locale" parameter can be use to select a locale, e.g. "de" or "en_GB". It defaults to the system locale.
- The "tz" parameter is the time zone to use, e.g. "Europe/Berlin" or "GMT-8:00". It defaults to the system time zone.
- The "time" parameter specifies the format of the time part, it can be "full", "long", "medium" or "short". If you do not specify it only the date part will appear in the output string.
-
numberFormat
Usage:
{{numberFormat number ["format"] [locale=default]}}
Format parameters is one of:- "integer": the integer number format
- "percent": the percent number format
- "currency": the decimal number format
- "pattern": a decimal pattern.
More options:
- groupingUsed: Set whether or not grouping will be used in this format.
- maximumFractionDigits: Sets the maximum number of digits allowed in the fraction portion of a number.
- maximumIntegerDigits: Sets the maximum number of digits allowed in the integer portion of a number
- minimumFractionDigits: Sets the minimum number of digits allowed in the fraction portion of a number
- minimumIntegerDigits: Sets the minimum number of digits allowed in the integer portion of a number.
- parseIntegerOnly: Sets whether or not numbers should be parsed as integers only.
- roundingMode: Sets the
RoundingMode
used in this NumberFormat.
- See Also:
-
now
Usage:
{{now ["format"] [tz=timeZone|timeZoneId]}}
Format parameters is one of:- "full": full date format. For example: Tuesday, June 19, 2012
- "long": long date format. For example: June 19, 2012
- "medium": medium date format. For example: Jun 19, 2012
- "short": short date format. For example: 6/19/12
- "pattern": a date pattern.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
apply
Description copied from interface:Helper
Apply the helper to the context.- Specified by:
apply
in interfaceHelper<Object>
- Parameters:
context
- The context object.options
- The options object.- Returns:
- A string result.
- Throws:
IOException
- If a template cannot be loaded.
-
registerHelper
Register the helper in a handlebars instance.- Parameters:
handlebars
- A handlebars object. Required.
-
register
Register all the text helpers.- Parameters:
handlebars
- The helper's owner. Required.
-