Skip to content

Add TitleCase Implementation#7473

Open
Rosander0 wants to merge 2 commits into
TheAlgorithms:masterfrom
Rosander0:add-title-case-v3
Open

Add TitleCase Implementation#7473
Rosander0 wants to merge 2 commits into
TheAlgorithms:masterfrom
Rosander0:add-title-case-v3

Conversation

@Rosander0

Copy link
Copy Markdown
Contributor
  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter

codecov-commenter commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.84%. Comparing base (bf8f3bd) to head (addb081).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rosander0

Copy link
Copy Markdown
Contributor Author

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!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TitleCaseTest covering 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.

Comment on lines +28 to +40
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));
}
}
Comment on lines +18 to +22
assertEquals("Hello", TitleCase.toTitleCase("hello"));
assertEquals("Hello", TitleCase.toTitleCase("HELLO"));
assertEquals("A", TitleCase.toTitleCase("a"));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants