Gets country from the specified locale string.

@param localeString the specified locale string
@return country, if the length of specified locale string less than 5, returns ""
327318
public static String getCountry(final String localeString) {
        if (localeString.length() >= COUNTRY_END) {
            return localeString.substring(COUNTRY_START, COUNTRY_END);
        }

        return "";
    }
744381
public static final Function<Float,String> toCurrencyStr(Locale locale) {
        return (Function<Float,String>)((Function)FnNumber.toCurrencyStr(locale));
    }
1276375
public String getDescription(final String locale) {
        if (this.uiInfo != null) {
            val description = getLocalizedValues(locale, this.uiInfo.getDescriptions());
            return description != null ? description : super.getDescription();
        }
        return super.getDescription();
    }
1158919
public String getLatLng() {
        final GeocodeApiResponse.Location location = getLocation();
        if(location == null) {
            return null;
        }
        return location.getLat() + "," + location.getLng();
    }
1274469
public String getDisplayCountry(Locale locale) {
        String countryCode = baseLocale.getRegion();
        if (countryCode.isEmpty()) {
            return "";
        }

        final String normalizedRegion = normalizeAndValidateRegion(
                countryCode, false /* strict */);
        if (normalizedRegion.isEmpty()) {
            return countryCode;
        }

        String result = ICU.getDisplayCountry(this, locale);
        if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
            result = ICU.getDisplayCountry(this, Locale.getDefault());
        }
        return result;
    }
120470
public Locale parseLocale(String localeString) {
        String language = null;
        String country = null;
        String variant = null;

        // Sometimes people specify "en-US" instead of "en_US", so
        // we'll try to clean that up.
        localeString = localeString.replaceAll("-", "_");

        StringTokenizer st = new StringTokenizer(localeString, "_");

        if (st.hasMoreTokens()) {
            language = st.nextToken();
        }
        if (st.hasMoreTokens()) {
            country = st.nextToken();
        }
        if (st.hasMoreTokens()) {
            variant = st.nextToken();
        }

        Locale locale = null;

        if (variant != null) {
            locale = new Locale(language, country, variant);
        } else if (country != null) {
            locale = new Locale(language, country);
        } else if (language != null) {
            locale = new Locale(language);
        }

        return locale;
    }
867640
public static Locale getLocale(String country)
    {
        if(country == null || country.length() == 0)
            country = Locale.getDefault().getCountry();
        List<Locale> locales = LocaleUtils.languagesByCountry(country);
        Locale locale = Locale.getDefault();
        if(locales.size() > 0)
            locale = locales.get(0); // Use the first locale that matches the country
        return locale;
    }
180350
public static String toLanguageTag(Locale locale) {
        return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : EMPTY);
    }
932841
@SuppressWarnings({"squid:SwitchLastCaseIsDefaultCheck", "squid:S1301"})
    public Locale getLand() {
        String country = this.getUnformatted().substring(0, 2);
        String language = country.toLowerCase();
        switch (country) {
            case "AT":
            case "CH":
                language = "de";
                break;
        }
        return new Locale(language, country);
    }
798006
public static final String getLocaleExtendedName(String lookup, String locale) {

        StringBuffer result = new StringBuffer(32);
        result.append(lookup);
        result.append('_');
        result.append(locale);
        return result.toString();
    }
159460
public static Locale getLocale(final String str) {
        
        if(isEmpty(str)) {
            return Locale.getDefault();
        }
        
        if(!str.contains("_")) {
            return new Locale(str);
        }
        
        final String[] split = str.split("_");
        if(split.length == 2) {
            return new Locale(split[0], split[1]);
            
        } else {
            return new Locale(split[0], split[1], split[2]);
        }
        
    }
1049121
private static int parseCountryCode(String countryCode) {

    String normalized = countryCode;
    if (normalized.startsWith(InternationalCallPrefix.PREFIX_PLUS)) {
      normalized = normalized.substring(1);
    } else if (normalized.startsWith(InternationalCallPrefix.PREFIX_00)) {
      normalized = normalized.substring(2);
    } else if (normalized.startsWith(InternationalCallPrefix.PREFIX_011)) {
      normalized = normalized.substring(3);
    }
    if (normalized.startsWith("0")) {
      throw new IllegalArgumentException(countryCode);
    }
    try {
      int cc = Integer.parseInt(normalized);
      return cc;
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException(countryCode, e);
    }
  }
672592
private static String toLanguageTag(Locale locale) {
        if (locale == null) {
            return null;
        }
        StringBuilder tag = new StringBuilder();

        tag.append(locale.getLanguage().toLowerCase());

        if (!locale.getCountry().isEmpty()) {
            tag.append("-");
            tag.append(locale.getCountry().toUpperCase());
        }

        return tag.toString();
    }
643086
protected Locale getBestLocale(HttpServletRequest request, Map<String,Locale> supportedLocales) throws ServletException {
		@SuppressWarnings("unchecked")
		Enumeration<String> acceptLanguages = request.getHeaders("accept-language");
		if(acceptLanguages == null) {
			// No header, use default
			return getDefaultLocale(request, supportedLocales);
		}
		// Select the best locale from the Accept-Language header(s).
		Locale bestExact = null;
		float bestExactQ = Float.NaN;
		Locale bestApprox = null;
		float bestApproxQ = Float.NaN;
		while(acceptLanguages.hasMoreElements()) {
			for(String pair : StringUtility.splitString(acceptLanguages.nextElement(), ',')) {
				String acceptLanguage;
				float q;
				int semiPos = pair.indexOf(';');
				if(semiPos == -1) {
					acceptLanguage = pair.trim();
					q = 1;
				} else {
					acceptLanguage = pair.substring(0, semiPos).trim();
					try {
						q = Float.parseFloat(pair.substring(semiPos + 1).trim());
					} catch(NumberFormatException e) {
						// Invalid value, use q=0 to ignore the language
						q = 0;
					}
				}
				if(
					q > 0
					&& (Float.isNaN(bestExactQ) || q > bestExactQ)
					&& (Float.isNaN(bestApproxQ) || q > bestApproxQ)
				) {
					MatchedLocale match = getBestMatch(supportedLocales, acceptLanguage);
					if(match != null) {
						if(match.exact) {
							if(Float.isNaN(bestExactQ) || q > bestExactQ) {
								bestExact = match.locale;
								bestExactQ = q;
							}
						} else {
							if(Float.isNaN(bestApproxQ) || q > bestApproxQ) {
								bestApprox = match.locale;
								bestApproxQ = q;
							}
						}
					}
				}
			}
		}
		// Select best exact, best approximate, then default
		Locale selected;
		if(bestExact != null) {
			selected = bestExact;
		} else if(bestApprox != null) {
			selected = bestApprox;
		} else {
			selected = getDefaultLocale(request, supportedLocales);
		}
		return selected;
	}
1196477
public Locale getLocale()
    {
        final Locale ret;
        if (this.attrValues.get(Person.AttrName.LOCALE) != null) {
            final String localeStr = this.attrValues.get(Person.AttrName.LOCALE);
            final String[] countries = localeStr.split("_");
            if (countries.length == 2) {
                ret = new Locale(countries[0], countries[1]);
            } else if (countries.length == 3) {
                ret = new Locale(countries[0], countries[1], countries[2]);
            } else {
                ret = new Locale(localeStr);
            }
        } else {
            ret = Locale.ENGLISH;
        }
        return ret;
    }
101052
public String getFormatString(Locale locale, String key) {
        String[] suffixes = toStrings(locale);

        while(true) {
            for (int i=0; i<suffixes.length; i++) {
                String suffix = suffixes[i];
                String msg = get(suffix).getProperty(key);
                if(msg!=null && msg.length()>0)
                    // ignore a definition without value, because stapler:i18n generates
                    // value-less definitions
                    return msg;

                int idx = suffix.lastIndexOf('_');
                if(idx<0)   // failed to find
                    return null;
                suffixes[i] = suffix.substring(0,idx);
            }
        }
    }
563166
private Locale extractLocale() {

        Locale loc = null;
        int underscore = m_name.lastIndexOf("_");
        if (underscore > -1) {
            String localeName = m_name.substring(underscore + 1);
            if (localeName.lastIndexOf(".") > -1) {
                localeName = localeName.substring(0, localeName.lastIndexOf("."));
            }
            loc = CmsLocaleManager.getLocale(localeName);
        }

        return loc;
    }