code: public static Locale parseLocaleString(String localeString) {
          String[] parts = tokenize(localeString, "_ ", false);
          String language = (parts.length > 0 ? parts[0] : EMPTY);
          String country = (parts.length > 1 ? parts[1] : EMPTY);
          validateLocalePart(language);
          validateLocalePart(country);
          String variant = EMPTY;
          if (parts.length > 2) {
              // There is definitely a variant, and it is everything after the country
              // code sans the separator between the country code and the variant.
              int endIndexOfCountryCode = localeString.indexOf(country, language.length()) + country.length();
              // Strip off any leading '_' and whitespace, what's left is the variant.
              variant = trimLeadingWhitespace(localeString.substring(endIndexOfCountryCode));
              if (variant.startsWith("_")) {
                  variant = trimLeadingCharacter(variant, '_');
              }
          }
          return (language.length() > 0 ? new Locale(language, country, variant) : null);
      }
docs: Parse the given {@code localeString} value into a {@link Locale}.
  <p>This is the inverse operation of {@link Locale#toString Locale's toString}.
  
  @param localeString the locale {@code String}, following {@code Locale's}
  {@code toString()} format ("en", "en_UK", etc);
  also accepts spaces as separators, as an alternative to underscores
  @return a corresponding {@code Locale} instance
  @throws IllegalArgumentException in case of an invalid locale specification