what-the-bank/sources/com/google/gson/FieldNamingPolicy.java

82 lines
3.0 KiB
Java

package com.google.gson;
import java.lang.reflect.Field;
import java.util.Locale;
/* loaded from: classes.dex */
public enum FieldNamingPolicy implements FieldNamingStrategy {
IDENTITY { // from class: com.google.gson.FieldNamingPolicy.1
@Override // com.google.gson.FieldNamingStrategy
public final String translateName(Field field) {
return field.getName();
}
},
UPPER_CAMEL_CASE { // from class: com.google.gson.FieldNamingPolicy.2
@Override // com.google.gson.FieldNamingStrategy
public final String translateName(Field field) {
return upperCaseFirstLetter(field.getName());
}
},
UPPER_CAMEL_CASE_WITH_SPACES { // from class: com.google.gson.FieldNamingPolicy.3
@Override // com.google.gson.FieldNamingStrategy
public final String translateName(Field field) {
return upperCaseFirstLetter(separateCamelCase(field.getName(), " "));
}
},
LOWER_CASE_WITH_UNDERSCORES { // from class: com.google.gson.FieldNamingPolicy.4
@Override // com.google.gson.FieldNamingStrategy
public final String translateName(Field field) {
return separateCamelCase(field.getName(), "_").toLowerCase(Locale.ENGLISH);
}
},
LOWER_CASE_WITH_DASHES { // from class: com.google.gson.FieldNamingPolicy.5
@Override // com.google.gson.FieldNamingStrategy
public final String translateName(Field field) {
return separateCamelCase(field.getName(), "-").toLowerCase(Locale.ENGLISH);
}
},
LOWER_CASE_WITH_DOTS { // from class: com.google.gson.FieldNamingPolicy.6
@Override // com.google.gson.FieldNamingStrategy
public final String translateName(Field field) {
return separateCamelCase(field.getName(), ".").toLowerCase(Locale.ENGLISH);
}
};
static String separateCamelCase(String str, String str2) {
StringBuilder sb = new StringBuilder();
int length = str.length();
for (int i = 0; i < length; i++) {
char charAt = str.charAt(i);
if (Character.isUpperCase(charAt) && sb.length() != 0) {
sb.append(str2);
}
sb.append(charAt);
}
return sb.toString();
}
static String upperCaseFirstLetter(String str) {
int length = str.length();
int i = 0;
while (!Character.isLetter(str.charAt(i)) && i < length - 1) {
i++;
}
char charAt = str.charAt(i);
if (Character.isUpperCase(charAt)) {
return str;
}
char upperCase = Character.toUpperCase(charAt);
if (i == 0) {
StringBuilder sb = new StringBuilder();
sb.append(upperCase);
sb.append(str.substring(1));
return sb.toString();
}
StringBuilder sb2 = new StringBuilder();
sb2.append(str.substring(0, i));
sb2.append(upperCase);
sb2.append(str.substring(i + 1));
return sb2.toString();
}
}