mirror of
https://github.com/google/nomulus
synced 2026-08-18 13:16:20 +00:00
Replace to(Upper|Lower)Case with Ascii.to$1Case
The presubmits are warning that toUpperCase() and toLowerCase() are locale-specific, and advise using Ascii.toUpperCase() and Ascii.toLowerCase() as a local-invariant alternative. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=127583677
This commit is contained in:
@@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
@@ -30,6 +31,7 @@ import com.google.common.collect.Range;
|
||||
import com.google.re2j.Pattern;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Detainted;
|
||||
@@ -560,7 +562,7 @@ public final class FormField<I, O> {
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable String input) {
|
||||
return input != null ? input.toUpperCase() : null;
|
||||
return input != null ? input.toUpperCase(Locale.ENGLISH) : null;
|
||||
}};
|
||||
|
||||
private static final Function<String, String> LOWERCASE_FUNCTION =
|
||||
@@ -568,7 +570,7 @@ public final class FormField<I, O> {
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable String input) {
|
||||
return input != null ? input.toLowerCase() : null;
|
||||
return input != null ? input.toLowerCase(Locale.ENGLISH) : null;
|
||||
}};
|
||||
|
||||
private static final Function<Object, Object> REQUIRED_FUNCTION =
|
||||
@@ -587,8 +589,8 @@ public final class FormField<I, O> {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object apply(@Nullable Object input) {
|
||||
return input instanceof CharSequence && ((CharSequence) input).length() == 0
|
||||
|| input instanceof Collection && ((Collection<?>) input).isEmpty()
|
||||
return ((input instanceof CharSequence) && (((CharSequence) input).length() == 0))
|
||||
|| ((input instanceof Collection) && ((Collection<?>) input).isEmpty())
|
||||
? null : input;
|
||||
}};
|
||||
|
||||
@@ -709,7 +711,7 @@ public final class FormField<I, O> {
|
||||
@Override
|
||||
public C apply(@Nullable O input) {
|
||||
try {
|
||||
return input != null ? Enum.valueOf(enumClass, ((String) input).toUpperCase()) : null;
|
||||
return input != null ? Enum.valueOf(enumClass, Ascii.toUpperCase((String) input)) : null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new FormFieldException(
|
||||
String.format("Enum %s does not contain '%s'", enumClass.getSimpleName(), input));
|
||||
|
||||
@@ -19,6 +19,7 @@ import static com.google.common.collect.Range.atMost;
|
||||
import static com.google.common.collect.Range.closed;
|
||||
import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -354,7 +355,7 @@ public final class RegistrarFormFields {
|
||||
}
|
||||
for (String state : stateField.extractUntyped(args).asSet()) {
|
||||
if ("US".equals(countryCode)) {
|
||||
state = state.toUpperCase();
|
||||
state = Ascii.toUpperCase(state);
|
||||
if (!StateCode.US_MAP.containsKey(state)) {
|
||||
throw new FormFieldException(stateField, "Unknown US state code.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user