MCPcopy
hub / github.com/google/guava / CaseFormat

Enum CaseFormat

guava/src/com/google/common/base/CaseFormat.java:33–221  ·  view source on GitHub ↗

Utility class for converting between various ASCII case formats. Behavior is undefined for non-ASCII input. @author Mike Bostock @since 1.0

Source from the content-addressed store, hash-verified

31 * @since 1.0
32 */
33@GwtCompatible
34public enum CaseFormat {
35 /**
36 * Hyphenated variable naming convention, e.g., "lower-hyphen". This format is also colloquially
37 * known as "kebab case".
38 */
39 LOWER_HYPHEN(CharMatcher.is('-'), "-") {
40 @Override
41 String normalizeWord(String word) {
42 return Ascii.toLowerCase(word);
43 }
44
45 @Override
46 String convert(CaseFormat format, String s) {
47 if (format == LOWER_UNDERSCORE) {
48 return s.replace('-', '_');
49 }
50 if (format == UPPER_UNDERSCORE) {
51 return Ascii.toUpperCase(s.replace('-', '_'));
52 }
53 return super.convert(format, s);
54 }
55 },
56
57 /** C++ variable naming convention, e.g., "lower_underscore". */
58 LOWER_UNDERSCORE(CharMatcher.is('_'), "_") {
59 @Override
60 String normalizeWord(String word) {
61 return Ascii.toLowerCase(word);
62 }
63
64 @Override
65 String convert(CaseFormat format, String s) {
66 if (format == LOWER_HYPHEN) {
67 return s.replace('_', '-');
68 }
69 if (format == UPPER_UNDERSCORE) {
70 return Ascii.toUpperCase(s);
71 }
72 return super.convert(format, s);
73 }
74 },
75
76 /** Java variable naming convention, e.g., "lowerCamel". */
77 LOWER_CAMEL(CharMatcher.inRange('A', 'Z'), "") {
78 @Override
79 String normalizeWord(String word) {
80 return firstCharOnlyToUpper(word);
81 }
82
83 @Override
84 String normalizeFirstWord(String word) {
85 return Ascii.toLowerCase(word);
86 }
87 },
88
89 /** Java and C++ class naming convention, e.g., "UpperCamel". */
90 UPPER_CAMEL(CharMatcher.inRange('A', 'Z'), "") {

Callers

nothing calls this directly

Calls 2

isMethod · 0.95
inRangeMethod · 0.95

Tested by

no test coverage detected