Add TitleCase Implementation#7473
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7473 +/- ##
============================================
+ Coverage 79.82% 79.84% +0.01%
- Complexity 7317 7325 +8
============================================
Files 805 806 +1
Lines 23785 23798 +13
Branches 4680 4683 +3
============================================
+ Hits 18987 19002 +15
Misses 4036 4036
+ Partials 762 760 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hey folks, just checking in on this PR — it's been a few days. Happy to make any changes if something needs to be adjusted. Let me know! |
There was a problem hiding this comment.
Pull request overview
This PR introduces a new string utility for converting input text into title case within com.thealgorithms.strings, along with a JUnit test suite to validate the behavior.
Changes:
- Added
TitleCase.toTitleCase(String)utility to capitalize the first letter of each word and lowercase the remaining letters. - Added
TitleCaseTestcovering null/empty input, single/multiple words, and whitespace preservation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/java/com/thealgorithms/strings/TitleCase.java | Adds the TitleCase utility implementation for title-casing strings. |
| src/test/java/com/thealgorithms/strings/TitleCaseTest.java | Adds unit tests validating TitleCase.toTitleCase behavior across common input shapes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| StringBuilder result = new StringBuilder(); | ||
| boolean capitalizeNext = true; | ||
| for (char c : input.toCharArray()) { | ||
| if (Character.isWhitespace(c)) { | ||
| capitalizeNext = true; | ||
| result.append(c); | ||
| } else if (capitalizeNext) { | ||
| result.append(Character.toUpperCase(c)); | ||
| capitalizeNext = false; | ||
| } else { | ||
| result.append(Character.toLowerCase(c)); | ||
| } | ||
| } |
| assertEquals("Hello", TitleCase.toTitleCase("hello")); | ||
| assertEquals("Hello", TitleCase.toTitleCase("HELLO")); | ||
| assertEquals("A", TitleCase.toTitleCase("a")); | ||
| } | ||
|
|
clang-format -i --style=file path/to/your/file.java