You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ro...@apache.org on 2004/12/27 15:51:38 UTC

cvs commit: jakarta-commons/cli/src/java/org/apache/commons/cli HelpFormatter.java

roxspring    2004/12/27 06:51:38

  Modified:    cli/src/test/org/apache/commons/cli BugsTest.java
               cli/src/java/org/apache/commons/cli HelpFormatter.java
  Log:
  Line separator as first char for helpformatter footer and header no longer throws exception
  
  BR: 21215
  
  Revision  Changes    Path
  1.22      +17 -0     jakarta-commons/cli/src/test/org/apache/commons/cli/BugsTest.java
  
  Index: BugsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/BugsTest.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- BugsTest.java	27 Dec 2004 14:35:36 -0000	1.21
  +++ BugsTest.java	27 Dec 2004 14:51:37 -0000	1.22
  @@ -497,5 +497,22 @@
           assertTrue(cl.hasOption('o'));
           assertEquals("ovalue",cl.getOptionValue('o'));
       }
  +    
  +    public void test21215() {
  +        Options options = new Options();
  +        HelpFormatter formatter = new HelpFormatter();
  +        String SEP = System.getProperty("line.separator");
  +        String header = SEP+"Header";
  +        String footer = "Footer";
  +        StringWriter out = new StringWriter();
  +        formatter.printHelp(new PrintWriter(out),80, "foobar", header, options, 2, 2, footer, true);
  +        assertEquals(
  +                "usage: foobar"+SEP+
  +                ""+SEP+
  +                "Header"+SEP+
  +                ""+SEP+
  +                "Footer"+SEP
  +                ,out.toString());
  +    }
   
   }
  
  
  
  1.17      +2 -2      jakarta-commons/cli/src/java/org/apache/commons/cli/HelpFormatter.java
  
  Index: HelpFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/HelpFormatter.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- HelpFormatter.java	22 Apr 2004 23:00:09 -0000	1.16
  +++ HelpFormatter.java	27 Dec 2004 14:51:38 -0000	1.17
  @@ -797,7 +797,7 @@
           if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
               || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
           {
  -            return pos;
  +            return pos+1;
           }
           else if ((startPos + width) >= text.length())
           {
  @@ -872,7 +872,7 @@
   
           int pos = s.length();
   
  -        while ((pos >= 0) && Character.isWhitespace(s.charAt(pos - 1)))
  +        while ((pos > 0) && Character.isWhitespace(s.charAt(pos - 1)))
           {
               --pos;
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org