commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ep...@apache.org
Subject cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration BasePropertiesConfiguration.java AbstractConfiguration.java
Date Thu, 16 Sep 2004 22:35:35 GMT
epugh       2004/09/16 15:35:35

  Modified:    configuration/xdocs changes.xml
               configuration/src/test/org/apache/commons/configuration
                        TestPropertiesConfiguration.java
               configuration/src/java/org/apache/commons/configuration
                        BasePropertiesConfiguration.java
                        AbstractConfiguration.java
  Log:
  Bug 29714 [configuration] Alternative delimiter
  
  Revision  Changes    Path
  1.42      +4 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- changes.xml	16 Sep 2004 21:35:57 -0000	1.41
  +++ changes.xml	16 Sep 2004 22:35:34 -0000	1.42
  @@ -7,6 +7,10 @@
   
     <body>
       <release version="1.0-rc2" date="in CVS">
  +      <action dev="epugh" type="add" issue="29714">
  +        Allow configurations extending AbstractConfiguration to change the delimiter
  +        used from "," to something else.
  +      </action>         
         <action dev="epugh" type="fix">
           PropertiesConfiguration.save() method has issues with preserving the filename
         </action>         
  
  
  
  1.12      +13 -1     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
  
  Index: TestPropertiesConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestPropertiesConfiguration.java	16 Sep 2004 21:35:57 -0000	1.11
  +++ TestPropertiesConfiguration.java	16 Sep 2004 22:35:35 -0000	1.12
  @@ -156,5 +156,17 @@
   
           assertEquals("'test.multilines' property", property, conf.getString("test.multilines"));
       }
  +    
  +    public void testChangingDelimiter() throws Exception{
  +        PropertiesConfiguration pc = new PropertiesConfiguration(testProperties);
  +        assertEquals(4,pc.getList("test.mixed.array").size());
  +        
  +        char delimiter = PropertiesConfiguration.getDelimiter();
  +        PropertiesConfiguration.setDelimiter('^');
  +        pc = new PropertiesConfiguration(testProperties);
  +        assertEquals(2,pc.getList("test.mixed.array").size());
  +        PropertiesConfiguration.setDelimiter(delimiter);
  +        
  +    }
   
   }
  
  
  
  1.19      +38 -41    jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java
  
  Index: BasePropertiesConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- BasePropertiesConfiguration.java	16 Sep 2004 21:35:57 -0000	1.18
  +++ BasePropertiesConfiguration.java	16 Sep 2004 22:35:35 -0000	1.19
  @@ -52,7 +52,7 @@
    *  </li>
    *  <li>
    *   If <i>value</i> is a list of strings, each token is separated
  - *   by a comma ','.
  + *   by a comma ',' by default.
    *  </li>
    *  <li>
    *   Commas in each token are escaped placing a backslash right before
  @@ -549,46 +549,43 @@
               {
                   // handle an escaped value
                   hadSlash = false;
  -                switch (ch)
  -                {
  -                    case '\\':
  -                        out.append('\\');
  -                        break;
  -                    case '\'':
  -                        out.append('\'');
  -                        break;
  -                    case '\"':
  -                        out.append('"');
  -                        break;
  -                    case 'r':
  -                        out.append('\r');
  -                        break;
  -                    case 'f':
  -                        out.append('\f');
  -                        break;
  -                    case 't':
  -                        out.append('\t');
  -                        break;
  -                    case 'n':
  -                        out.append('\n');
  -                        break;
  -                    case 'b':
  -                        out.append('\b');
  -                        break;
  -                    case DELIMITER:
  -                        out.append("\\");
  -                        out.append(DELIMITER);
  -                        break;
  -                    case 'u':
  -                        {
  -                            // uh-oh, we're in unicode country....
  -                            inUnicode = true;
  -                            break;
  -                        }
  -                    default :
  -                        out.append(ch);
  -                        break;
  +                
  +                if(ch=='\\'){
  +                    out.append('\\');
  +                }
  +                else if (ch=='\''){
  +                    out.append('\'');
  +                }
  +                else if (ch=='\"'){
  +                    out.append('"');
  +                }
  +                else if (ch=='r'){
  +                    out.append('\r');
  +                }
  +                else if (ch=='f'){
  +                    out.append('\f');
  +                }
  +                else if (ch=='t'){
  +                    out.append('\t');
  +                }
  +                else if (ch=='n'){
  +                    out.append('\n');
  +                }
  +                else if (ch=='b'){
  +                    out.append('\b');
  +                }
  +                else if (ch==DELIMITER){
  +                    out.append('\\');
  +                    out.append(DELIMITER);
  +                }
  +                else if (ch=='u'){
  +//                  uh-oh, we're in unicode country....
  +                    inUnicode = true;
  +                }     
  +                else {
  +                    out.append(ch);
                   }
  +                                             
                   continue;
               }
               else if (ch == '\\')
  
  
  
  1.21      +18 -2     jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- AbstractConfiguration.java	16 Aug 2004 22:16:30 -0000	1.20
  +++ AbstractConfiguration.java	16 Sep 2004 22:35:35 -0000	1.21
  @@ -50,11 +50,27 @@
       protected static final String END_TOKEN = "}";
   
       /** The property delimiter used while parsing (a comma). */
  -    protected static final char DELIMITER = ',';
  +    protected static char DELIMITER = ',';
   
       /** how big the initial arraylist for splitting up name value pairs */
       private static final int INITIAL_LIST_SIZE = 2;
   
  +    /**
  +     * For configurations extending AbstractConfiguration, allow them to
  +     * change the delimiter from the default comma (",").
  +     * @param delimiter The new delimiter
  +     */
  +    public static void setDelimiter(char delimiter){
  +        AbstractConfiguration.DELIMITER = delimiter;
  +    }
  +    
  +    /**
  +     * Retrieve the current delimiter.  By default this is a comma (",").
  +     * @return The delimiter in use
  +     */
  +    public static char getDelimiter(){
  +        return AbstractConfiguration.DELIMITER;
  +    }
       /**
        * {@inheritDoc}
        */
  
  
  

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


Mime
View raw message