Skip to content

Commit 6789471

Browse files
committed
minor cleanup
1 parent 3a8db38 commit 6789471

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -400,28 +400,26 @@ private Locale _deserializeLocale(String value, DeserializationContext ctxt)
400400
return new Locale(first, value);
401401
}
402402
String second = value.substring(0, ix);
403-
if(!_isScriptOrExtensionPresent(value)) {
403+
// [databind#3259]: Support for BCP 47 java.util.Locale ser/deser
404+
int extMarkerIx = value.indexOf(LOCALE_EXT_MARKER);
405+
if (extMarkerIx < 0) {
404406
return new Locale(first, second, value.substring(ix+1));
405407
}
406-
// Issue #3259: Support for BCP 47 java.util.Locale Serialization / De-serialization
407-
return _deSerializeBCP47Locale(value, ix, first, second);
408+
return _deSerializeBCP47Locale(value, ix, first, second, extMarkerIx);
408409
}
409410

410-
private boolean _isScriptOrExtensionPresent(String value) {
411-
return value.contains(LOCALE_EXT_MARKER);
412-
}
413-
414-
private Locale _deSerializeBCP47Locale(String value, int ix, String first, String second) {
411+
private Locale _deSerializeBCP47Locale(String value, int ix, String first, String second,
412+
int extMarkerIx)
413+
{
415414
String third = "";
416415
try {
417-
int scriptExpIx = value.indexOf("_#");
418416
// Below condition checks if variant value is present to handle empty variant values such as
419417
// en__#Latn_x-ext
420418
// _US_#Latn
421-
if (scriptExpIx > 0 && scriptExpIx > ix) {
422-
third = value.substring(ix + 1, scriptExpIx);
419+
if (extMarkerIx > 0 && extMarkerIx > ix) {
420+
third = value.substring(ix + 1, extMarkerIx);
423421
}
424-
value = value.substring(scriptExpIx + 2);
422+
value = value.substring(extMarkerIx + 2);
425423

426424
if (value.indexOf('_') < 0 && value.indexOf('-') < 0) {
427425
return new Locale.Builder().setLanguage(first)
@@ -440,7 +438,8 @@ private Locale _deSerializeBCP47Locale(String value, int ix, String first, Strin
440438
.setScript(value.substring(0, ix))
441439
.setExtension(value.charAt(ix + 1), value.substring(ix + 3))
442440
.build();
443-
} catch(IllformedLocaleException ex) {
441+
} catch (IllformedLocaleException ex) {
442+
// should we really just swallow the exception?
444443
return new Locale(first, second, third);
445444
}
446445
}

0 commit comments

Comments
 (0)