Changeset 17613 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
r16643 r17613 973 973 974 974 /** 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 /** 975 1005 * Trim whitespaces from the string {@code s}. 976 1006 * @param s The source string -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/FunctionsTest.java
r17275 r17613 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertNull; 5 6 import static org.junit.jupiter.api.Assertions.assertTrue; 6 7 import static org.openstreetmap.josm.data.osm.OsmPrimitiveType.NODE; … … 54 55 return new Environment(osm); 55 56 } 57 } 58 59 /** 60 * Unit test of {@link Functions#title}. 61 */ 62 @Test 63 void testTitle() { 64 assertNull(Functions.title(null)); 65 assertEquals("", Functions.title("")); 66 assertEquals("I Am Fine", Functions.title("i am FINE")); 56 67 } 57 68
Note:
See TracChangeset
for help on using the changeset viewer.