1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
50
50
* @author Rick Evans
51
51
* @author Arjen Poutsma
52
52
* @since 16 April 2001
53
- * @see org.apache.commons.lang.StringUtils
54
53
*/
55
54
public abstract class StringUtils {
56
55
@@ -87,7 +86,7 @@ public static boolean isEmpty(Object str) {
87
86
/**
88
87
* Check that the given CharSequence is neither {@code null} nor of length 0.
89
88
* Note: Will return {@code true} for a CharSequence that purely consists of whitespace.
90
- * <p><pre>
89
+ * <p><pre class="code" >
91
90
* StringUtils.hasLength(null) = false
92
91
* StringUtils.hasLength("") = false
93
92
* StringUtils.hasLength(" ") = true
@@ -116,7 +115,7 @@ public static boolean hasLength(String str) {
116
115
* Check whether the given CharSequence has actual text.
117
116
* More specifically, returns {@code true} if the string not {@code null},
118
117
* its length is greater than 0, and it contains at least one non-whitespace character.
119
- * <p><pre>
118
+ * <p><pre class="code" >
120
119
* StringUtils.hasText(null) = false
121
120
* StringUtils.hasText("") = false
122
121
* StringUtils.hasText(" ") = false
@@ -207,7 +206,7 @@ public static String trimWhitespace(String str) {
207
206
208
207
/**
209
208
* Trim <i>all</i> whitespace from the given String:
210
- * leading, trailing, and inbetween characters.
209
+ * leading, trailing, and in between characters.
211
210
* @param str the String to check
212
211
* @return the trimmed String
213
212
* @see java.lang.Character#isWhitespace
@@ -264,7 +263,7 @@ public static String trimTrailingWhitespace(String str) {
264
263
}
265
264
266
265
/**
267
- * Trim all occurences of the supplied leading character from the given String.
266
+ * Trim all occurrences of the supplied leading character from the given String.
268
267
* @param str the String to check
269
268
* @param leadingCharacter the leading character to be trimmed
270
269
* @return the trimmed String
@@ -281,7 +280,7 @@ public static String trimLeadingCharacter(String str, char leadingCharacter) {
281
280
}
282
281
283
282
/**
284
- * Trim all occurences of the supplied trailing character from the given String.
283
+ * Trim all occurrences of the supplied trailing character from the given String.
285
284
* @param str the String to check
286
285
* @param trailingCharacter the trailing character to be trimmed
287
286
* @return the trimmed String
@@ -380,7 +379,7 @@ public static int countOccurrencesOf(String str, String sub) {
380
379
}
381
380
382
381
/**
383
- * Replace all occurences of a substring within a string with
382
+ * Replace all occurrences of a substring within a string with
384
383
* another string.
385
384
* @param inString String to examine
386
385
* @param oldPattern String to replace
@@ -679,10 +678,11 @@ public static boolean pathEquals(String path1, String path2) {
679
678
/**
680
679
* Parse the given {@code localeString} value into a {@link Locale}.
681
680
* <p>This is the inverse operation of {@link Locale#toString Locale's toString}.
682
- * @param localeString the locale string , following {@code Locale's}
681
+ * @param localeString the locale String , following {@code Locale's}
683
682
* {@code toString()} format ("en", "en_UK", etc);
684
683
* also accepts spaces as separators, as an alternative to underscores
685
684
* @return a corresponding {@code Locale} instance
685
+ * @throws IllegalArgumentException in case of an invalid locale specification
686
686
*/
687
687
public static Locale parseLocaleString (String localeString ) {
688
688
String [] parts = tokenizeToStringArray (localeString , "_ " , false , false );
@@ -691,10 +691,10 @@ public static Locale parseLocaleString(String localeString) {
691
691
validateLocalePart (language );
692
692
validateLocalePart (country );
693
693
String variant = "" ;
694
- if (parts .length >= 2 ) {
694
+ if (parts .length > 2 ) {
695
695
// There is definitely a variant, and it is everything after the country
696
696
// code sans the separator between the country code and the variant.
697
- int endIndexOfCountryCode = localeString .lastIndexOf (country ) + country .length ();
697
+ int endIndexOfCountryCode = localeString .indexOf (country , language . length () ) + country .length ();
698
698
// Strip off any leading '_' and whitespace, what's left is the variant.
699
699
variant = trimLeadingWhitespace (localeString .substring (endIndexOfCountryCode ));
700
700
if (variant .startsWith ("_" )) {
0 commit comments