Merge pull request #3941 from wing328/swfit_fix_num_enum

[Swift] support number value for enum
This commit is contained in:
wing328
2016-10-07 11:27:55 +08:00
committed by GitHub

View File

@@ -384,10 +384,18 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
@SuppressWarnings("static-method")
public String toSwiftyEnumName(String value) {
if (value.matches("^-?\\d*\\.{0,1}\\d+.*")) { // starts with number
value = "Number" + value;
value = value.replaceAll("-", "Minus");
value = value.replaceAll("\\+", "Plus");
value = value.replaceAll("\\.", "Dot");
}
// Prevent from breaking properly cased identifier
if (value.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
return value;
}
char[] separators = {'-', '_', ' ', ':'};
return WordUtils.capitalizeFully(StringUtils.lowerCase(value), separators).replaceAll("[-_ :]", "");
}