Changeset 17613 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2021-03-21T09:23:34+01:00 (4 years ago)
Author:
simon04
Message:

fix #14124 - Add MapCSS function title

Returns a title-cased version of the string where words start with an uppercase character and the remaining characters are lowercase.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

    r16643 r17613  
    973973
    974974    /**
     975     * Returns a title-cased version of the string where words start with an uppercase character and the remaining characters are lowercase
     976     *
     977     * Also known as "capitalize".
     978     * @param str The source string
     979     * @return The resulting string
     980     * @since 17613
     981     * @see Character#toTitleCase(char)
     982     */
     983    public static String title(String str) {
     984        // adapted from org.apache.commons.lang3.text.WordUtils.capitalize
     985        if (str == null) {
     986            return null;
     987        }
     988        final char[] buffer = str.toCharArray();
     989        boolean capitalizeNext = true;
     990        for (int i = 0; i < buffer.length; i++) {
     991            final char ch = buffer[i];
     992            if (Character.isWhitespace(ch)) {
     993                capitalizeNext = true;
     994            } else if (capitalizeNext) {
     995                buffer[i] = Character.toTitleCase(ch);
     996                capitalizeNext = false;
     997            } else {
     998                buffer[i] = Character.toLowerCase(ch);
     999            }
     1000        }
     1001        return new String(buffer);
     1002    }
     1003
     1004    /**
    9751005     * Trim whitespaces from the string {@code s}.
    9761006     * @param s The source string
Note: See TracChangeset for help on using the changeset viewer.