From e0ae77a7093feb56e142d6aa0e6fa1a264f94dd8 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Wed, 24 Jul 2019 17:23:00 -0300 Subject: Fix up case printing a bit --- clformat/readme.md | 8 ++++++++ .../java/bjc/utils/ioutils/format/directives/CaseDirective.java | 9 ++++----- .../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 @@ -117,6 +117,14 @@ public class CLFormatterTest { assertFormat(" foobar", "~#mincol;8,#colinc;2,#minpad;1,#padchar;' @A", "foobar"); } + @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 -- cgit v1.2.3