You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2017/04/17 10:52:06 UTC

[6/6] [lang] Introduce some more local variables to make the code better readable

Introduce some more local variables to make the code better readable


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/dfecbe97
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/dfecbe97
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/dfecbe97

Branch: refs/heads/master
Commit: dfecbe970917754511a081f8b86efac211e624f6
Parents: f059e5f
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Apr 17 12:40:58 2017 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Apr 17 12:40:58 2017 +0200

----------------------------------------------------------------------
 .../org/apache/commons/lang3/LocaleUtils.java   | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/dfecbe97/src/main/java/org/apache/commons/lang3/LocaleUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/LocaleUtils.java b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
index 861b25d..57f5079 100644
--- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java
+++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
@@ -139,18 +139,20 @@ public class LocaleUtils {
         }
 
         final String[] segments = str.split("_", -1);
-        final int segmentCount = segments.length -1;
         final String language = segments[0];
-        if (segmentCount == 1) {
-            if (isISO639LanguageCode(language) && isISO3166CountryCode(segments[1]) ||
-                    isNumericAreaCode(segments[1])) {
-                return new Locale(language, segments[1]);
+        if (segments.length == 2) {
+            final String country = segments[1];
+            if (isISO639LanguageCode(language) && isISO3166CountryCode(country) ||
+                    isNumericAreaCode(country)) {
+                return new Locale(language, country);
             }
-        } else if (segmentCount == 2) {
+        } else if (segments.length == 3) {
+            final String country = segments[1];
+            final String variant = segments[2];
             if (isISO639LanguageCode(language) &&
-                    (segments[1].length() == 0 || isISO3166CountryCode(segments[1])) &&
-                    segments[2].length() > 0) {
-                return new Locale(language, segments[1], segments[2]);
+                    (country.length() == 0 || isISO3166CountryCode(country)) &&
+                    variant.length() > 0) {
+                return new Locale(language, country, variant);
             }
         }
         throw new IllegalArgumentException("Invalid locale format: " + str);