Skip to content

StringUtils#parseLocaleString(String) with Variant when no Country [SPR-7598] #12254

Closed
@spring-projects-issues

Description

@spring-projects-issues

Antonio Mota opened SPR-7598 and commented

This issue is related to, but supersedes, #11228. Given the bugs described in that Jira, I propose the following code:

 
        public static Locale parseLocaleString(String localeString) {
		String[] parts = localeString.split("[_ ]",3);
		String language = (parts.length > 0 ? parts[0] : "");
		String country = (parts.length > 1 ? parts[1] : "");
		String variant = (parts.length > 2 ? parts[2] : "");
		return new Locale(language, country, variant);
	}

Some notes:

It throws a NullPointerException if localeString is null wich conforms with the Locale constructors (??thrown if any argument is null??).

Also, it does no validations, as per the Class description "??Because a Locale object is just an identifier for a region, no validity check is performed when you construct a Locale.??"


Issue Links:

Referenced from: commits cab35aa, 55563c1

1 votes, 3 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions