diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2019-07-24 17:23:00 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2019-07-24 17:23:00 -0300 |
| commit | e0ae77a7093feb56e142d6aa0e6fa1a264f94dd8 (patch) | |
| tree | 70cc32fa45b6a9f69f832dae0e45c38110c6c9fb | |
| parent | 5a15fd15334d5e2a0e3a047c2dfff87bd3822a32 (diff) | |
Fix up case printing a bit
| -rw-r--r-- | clformat/readme.md | 8 | ||||
| -rw-r--r-- | clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java | 9 | ||||
| -rw-r--r-- | clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java | 8 |
3 files changed, 20 insertions, 5 deletions
diff --git a/clformat/readme.md b/clformat/readme.md index 2271af8..da0e085 100644 --- a/clformat/readme.md +++ b/clformat/readme.md @@ -146,3 +146,11 @@ It takes zero, one or four parameters (described by the table below), as well as Padding will be inserted after the string, unless the `@` modifier has been specified, in which case it will go before the string. + +## ( Directive +The ( directive is used for performing simple case-mappings on a string. It +encloses a string that contains other directives, terminated by the ~) +directive. + +It takes no parameters, but takes one format argument; its behavior is +influenced by the modifiers provided to the ( directive, but not much else. diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java index a7e2b08..7943fb9 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java @@ -71,14 +71,13 @@ public class CaseDirective implements Directive { Matcher mat = wordPattern.matcher(strang); StringBuffer sb = new StringBuffer(); - while(!mat.find()) { + while(mat.find()) { mat.appendReplacement(sb, ""); String word = mat.group(1); - - word = word.substring(0, 1).toUpperCase() + word.substring(1); + String ward = word.substring(0, 1).toUpperCase() + word.substring(1); - sb.append(word); + sb.append(ward); sb.append(mat.group(2)); } @@ -90,7 +89,7 @@ public class CaseDirective implements Directive { StringBuffer sb = new StringBuffer(); boolean doCap = true; - while(!mat.find()) { + while(mat.find()) { mat.appendReplacement(sb, ""); String word = mat.group(1); diff --git a/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java b/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java index d3d7075..8b03172 100644 --- a/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java +++ b/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java @@ -118,6 +118,14 @@ public class CLFormatterTest { } @Test + public void testCasePrinting() { + assertFormat("abc", "~(~A~)", "AbC", "aBc", "aBc bCD", "abc Cad dAC"); + assertFormat("ABC", "~@:(~A~)", "aBc"); + assertFormat("ABc BCD", "~:(~A ~A~)", "aBc", "bCD"); + assertFormat("Abc Cad dAC", "~@(~A~)", "abc Cad dAC"); + } + + @Test public void testRandomCases() { // Random test cases assertEquals("3 dogs are here", format("~D dog~:[s are~; is~] here", 3, 3 == 1)); |
