You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2007/04/23 13:18:33 UTC
svn commit: r531435 - in /jakarta/commons/proper/configuration/trunk/src:
java/org/apache/commons/configuration/INIConfiguration.java
test/org/apache/commons/configuration/TestINIConfiguration.java
Author: ebourg
Date: Mon Apr 23 04:18:22 2007
New Revision: 531435
URL: http://svn.apache.org/viewvc?view=rev&rev=531435
Log:
INIConfiguration now supports values surrounded with single quotes
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java?view=diff&rev=531435&r1=531434&r2=531435
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/INIConfiguration.java Mon Apr 23 04:18:22 2007
@@ -157,7 +157,7 @@
* <code>getSections</code> method.
* </p>
*
- * @author trevor.miller
+ * @author Trevor Miller
* @version $Id$
* @since 1.4
*/
@@ -299,7 +299,7 @@
key = section + line;
}
}
- this.addProperty(key.trim(), value);
+ addProperty(key.trim(), value);
}
}
line = bufferedReader.readLine();
@@ -315,7 +315,9 @@
* Parse the value to remove the quotes and ignoring the comment.
* Example:
*
- * <code>"value" ; comment -> value</code>
+ * <pre>"value" ; comment -> value</pre>
+ *
+ * <pre>'value' ; comment -> value</pre>
*
* @param value
*/
@@ -323,10 +325,12 @@
{
value = value.trim();
- boolean quoted = value.startsWith("\"");
+ boolean quoted = value.startsWith("\"") || value.startsWith("'");
boolean stop = false;
boolean escape = false;
+ char quote = quoted ? value.charAt(0) : 0;
+
int i = quoted ? 1 : 0;
StringBuffer result = new StringBuffer();
@@ -340,11 +344,11 @@
{
escape = true;
}
- else if (!escape && '"' == c)
+ else if (!escape && quote == c)
{
stop = true;
}
- else if (escape && '"' == c)
+ else if (escape && quote == c)
{
escape = false;
result.append(c);
@@ -407,33 +411,33 @@
/**
* Determine if the given line is a comment line.
*
- * @param s The line to check.
+ * @param line The line to check.
* @return true if the line is empty or starts with one of the comment
* characters
*/
- protected boolean isCommentLine(String s)
+ protected boolean isCommentLine(String line)
{
- if (s == null)
+ if (line == null)
{
return false;
}
// blank lines are also treated as comment lines
- return s.length() < 1 || COMMENT_CHARS.indexOf(s.charAt(0)) >= 0;
+ return line.length() < 1 || COMMENT_CHARS.indexOf(line.charAt(0)) >= 0;
}
/**
* Determine if the given line is a section.
*
- * @param s The line to check.
+ * @param line The line to check.
* @return true if the line contains a secion
*/
- protected boolean isSectionLine(String s)
+ protected boolean isSectionLine(String line)
{
- if (s == null)
+ if (line == null)
{
return false;
}
- return s.startsWith("[") && s.endsWith("]");
+ return line.startsWith("[") && line.endsWith("]");
}
/**
@@ -445,16 +449,18 @@
public Set getSections()
{
Set sections = new TreeSet();
- Iterator iter = this.getKeys();
- while (iter.hasNext())
+
+ Iterator keys = getKeys();
+ while (keys.hasNext())
{
- String key = (String) iter.next();
+ String key = (String) keys.next();
int index = key.indexOf(".");
if (index >= 0)
{
sections.add(key.substring(0, index));
}
}
+
return sections;
}
}
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java?view=diff&rev=531435&r1=531434&r2=531435
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestINIConfiguration.java Mon Apr 23 04:18:22 2007
@@ -55,7 +55,8 @@
+ "var1 = \"quoted value\"\r\n"
+ "var2 = \"quoted value\\nwith \\\"quotes\\\"\"\r\n"
+ "var3 = 123 ; comment\r\n"
- + "var4 = \"1;2;3\" ; comment\r\n";
+ + "var4 = \"1;2;3\" ; comment\r\n"
+ + "var5 = '\\'quoted\\' \"value\"' ; comment\r\n";
/**
* Test of save method, of class {@link INIConfiguration}.
@@ -178,6 +179,14 @@
config.load(new StringReader(INI_DATA2));
assertEquals("value", "1;2;3", config.getString("section4.var4"));
+ }
+
+ public void testQuotedValueWithSingleQuotes() throws Exception
+ {
+ INIConfiguration config = new INIConfiguration();
+ config.load(new StringReader(INI_DATA2));
+
+ assertEquals("value", "'quoted' \"value\"", config.getString("section4.var5"));
}
public void testWriteValueWithCommentChar() throws Exception
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org