-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from DEPthes/feacture/alarm
[FEAT] μλ μ‘°ν μ μΉ΄ν κ³ λ¦¬ μμ΄λͺ μΆκ°
- Loading branch information
Showing
4 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/depth/mvp/thinkerbell/global/converter/CaseConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package depth.mvp.thinkerbell.global.converter; | ||
|
||
public class CaseConverter { | ||
|
||
/** | ||
* PascalCase λ¬Έμμ΄μ snake_case λ¬Έμμ΄λ‘ λ³νν©λλ€. | ||
* | ||
* @param pascalCaseString λ³νν PascalCase λ¬Έμμ΄ | ||
* @return λ³νλ snake_case λ¬Έμμ΄ | ||
*/ | ||
public static String pascalToSnake(String pascalCaseString) { | ||
StringBuilder snakeCaseString = new StringBuilder(); | ||
|
||
for (char c : pascalCaseString.toCharArray()) { | ||
if (Character.isUpperCase(c)) { | ||
if (snakeCaseString.length() > 0) { | ||
snakeCaseString.append('_'); | ||
} | ||
snakeCaseString.append(Character.toLowerCase(c)); | ||
} else { | ||
snakeCaseString.append(c); | ||
} | ||
} | ||
|
||
return snakeCaseString.toString(); | ||
} | ||
|
||
/** | ||
* snake_case λ¬Έμμ΄μ PascalCase λ¬Έμμ΄λ‘ λ³νν©λλ€. | ||
* | ||
* @param snakeCaseString λ³νν snake_case λ¬Έμμ΄ | ||
* @return λ³νλ PascalCase λ¬Έμμ΄ | ||
*/ | ||
public static String snakeToPascal(String snakeCaseString) { | ||
StringBuilder pascalCaseString = new StringBuilder(); | ||
boolean toUpperCase = true; // 첫 λ¬Έμλ₯Ό λλ¬Έμλ‘ λ³ννκΈ° μν΄ trueλ‘ μ€μ | ||
|
||
for (char c : snakeCaseString.toCharArray()) { | ||
if (c == '_') { | ||
// μΈλμ€μ½μ΄ λ€μ λ¬Έμλ₯Ό λλ¬Έμλ‘ λ³ννλλ‘ μ€μ ν©λλ€. | ||
toUpperCase = true; | ||
} else { | ||
if (toUpperCase) { | ||
// λλ¬Έμλ‘ λ³ν ν μ€μ μ μ΄κΈ°νν©λλ€. | ||
pascalCaseString.append(Character.toUpperCase(c)); | ||
toUpperCase = false; | ||
} else { | ||
// μλ¬Έμλ‘ μΆκ°ν©λλ€. | ||
pascalCaseString.append(c); | ||
} | ||
} | ||
} | ||
|
||
return pascalCaseString.toString(); | ||
} | ||
|
||
} |