public static Locale parseLocale ( String localeString ) { if ( localeString == null ) { return Locale . US ; } String [ ] groups = localeString . split ( "[-_]" ) ; switch ( groups . length ) { case 1 : return new Locale ( groups [ 0 ] ) ; case 2 : return new Locale ( groups [ 0 ] , Ascii . toUpperCase ( groups [ 1 ] ) ) ; case 3 : return new Locale ( groups [ 0 ] , Ascii . toUpperCase ( groups [ 1 ] ) , groups [ 2 ] ) ; default : throw new IllegalArgumentException ( "Malformed localeString: " + localeString ) ; } }
Given a string representing a Locale returns the Locale object for that string .