google guava ์ฌ์ฉ
- google CaseFormat import
- import com.google.common.base.CaseFormat;
- ์ํ๋ ํฌ๋งท์ผ๋ก ๋ณ๊ฒฝ
String upperCamelVndr = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, "text_test"); //TextTest - ํฌ๋งท ์ข
๋ฅ
//CaseFormat enum ๊ฐ๋ณด๋ฉด ์์ธํ๊ฒ ํ์ธ ๊ฐ๋ฅ LOWER_HYPHEN(CharMatcher.is('-'), "-") { String normalizeWord(String word) { return Ascii.toLowerCase(word); } String convert(CaseFormat format, String s) { if (format == LOWER_UNDERSCORE) { return s.replace('-', '_'); } else { return format == UPPER_UNDERSCORE ? Ascii.toUpperCase(s.replace('-', '_')) : super.convert(format, s); } } }, LOWER_UNDERSCORE(CharMatcher.is('_'), "_") { String normalizeWord(String word) { return Ascii.toLowerCase(word); } String convert(CaseFormat format, String s) { if (format == LOWER_HYPHEN) { return s.replace('_', '-'); } else { return format == UPPER_UNDERSCORE ? Ascii.toUpperCase(s) : super.convert(format, s); } } }, LOWER_CAMEL(CharMatcher.inRange('A', 'Z'), "") { String normalizeWord(String word) { return CaseFormat.firstCharOnlyToUpper(word); } String normalizeFirstWord(String word) { return Ascii.toLowerCase(word); } }, UPPER_CAMEL(CharMatcher.inRange('A', 'Z'), "") { String normalizeWord(String word) { return CaseFormat.firstCharOnlyToUpper(word); } }, UPPER_UNDERSCORE(CharMatcher.is('_'), "_") { String normalizeWord(String word) { return Ascii.toUpperCase(word); } String convert(CaseFormat format, String s) { if (format == LOWER_HYPHEN) { return Ascii.toLowerCase(s.replace('_', '-')); } else { return format == LOWER_UNDERSCORE ? Ascii.toLowerCase(s) : super.convert(format, s); } } };
'๊ฐ๋ฐ์ํ > Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] Null String Casting (0) | 2022.04.29 |
---|---|
[Java] Map ์ ๊ณต ๋ฉ์๋๋ค ์ ๋ฆฌ (0) | 2022.04.26 |
[JAVA] String ์ค๋ณต์ ๊ฑฐ Stream (0) | 2022.03.22 |
[JAVA] ๋๋ฌธ์ ์์ ๊ณต๋ฐฑ ์ถ๊ฐ (0) | 2022.03.22 |
[JAVA] char ์ ๋ฆฌ (0) | 2022.03.01 |