sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1781500 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/geometry/ sis-referencing/src/test/java/org/apache/sis/geometry/ sis-utility/src/main/java/org/apache/sis/io/
Date Fri, 03 Feb 2017 07:15:22 GMT
Author: desruisseaux
Date: Fri Feb  3 07:15:21 2017
New Revision: 1781500

URL: http://svn.apache.org/viewvc?rev=1781500&view=rev
Log:
CoordinateFormat should ignore spaces around the separator at parsing time.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java?rev=1781500&r1=1781499&r2=1781500&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java
[UTF-8] Fri Feb  3 07:15:21 2017
@@ -112,6 +112,11 @@ public class CoordinateFormat extends Co
     private String separator;
 
     /**
+     * The separator without spaces, used at parsing time.
+     */
+    private String parseSeparator;
+
+    /**
      * The coordinate reference system to assume if no CRS is attached to the position to
format.
      * May be {@code null}.
      */
@@ -198,7 +203,7 @@ public class CoordinateFormat extends Co
      */
     public CoordinateFormat(final Locale locale, final TimeZone timezone) {
         super(locale, timezone);
-        separator = " ";
+        parseSeparator = separator = " ";
     }
 
     /**
@@ -218,8 +223,12 @@ public class CoordinateFormat extends Co
      * @param  separator  the new coordinate separator.
      */
     public void setSeparator(final String separator) {
-        ArgumentChecks.ensureNonNull("separator", separator);
+        ArgumentChecks.ensureNonEmpty("separator", separator);
         this.separator = separator;
+        parseSeparator = CharSequences.trimWhitespaces(separator);
+        if (parseSeparator.isEmpty()) {
+            parseSeparator = separator;
+        }
     }
 
     /**
@@ -626,7 +635,7 @@ public class CoordinateFormat extends Co
             if (i != 0) {
                 final int end = subPos.getIndex();
                 int index = offset + end;
-                while (!CharSequences.regionMatches(text, index, separator)) {
+                while (!CharSequences.regionMatches(text, index, parseSeparator)) {
                     if (index < length) {
                         final int c = Character.codePointAt(text, index);
                         if (Character.isSpaceChar(c)) {
@@ -643,7 +652,7 @@ public class CoordinateFormat extends Co
                     throw new LocalizedParseException(getLocale(), Errors.Keys.UnexpectedCharactersAfter_2,
                             new CharSequence[] {text.subSequence(start, end), CharSequences.token(text,
index)}, index);
                 }
-                subPos.setIndex(index + separator.length() - offset);
+                subPos.setIndex(index + parseSeparator.length() - offset);
             }
             /*
              * At this point 'subPos' is set to the beginning of the next ordinate to parse
in 'asString'.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java?rev=1781500&r1=1781499&r2=1781500&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java
[UTF-8] Fri Feb  3 07:15:21 2017
@@ -89,14 +89,15 @@ public final strictfp class CoordinateFo
         assertEquals("ParsePosition.getErrorIndex()", -1, index.getErrorIndex());
         assertEquals("ParsePosition.getIndex()",      16, index.getIndex());
         /*
-         * Try again with a different separator.
+         * Try again with a different separator. Also put or remove some spaces
+         * around the separator for testing UnitFormat capabilities to ignore them.
          */
         format.setSeparator("; ");
         index.setIndex(0);
-        position = format.parse("4.64; 10.25; -3.12", index);
+        position = format.parse("4.64;10.25 ;  -3.12", index);
         assertArrayEquals(new double[] {4.64, 10.25, -3.12}, position.getCoordinate(), STRICT);
         assertEquals("ParsePosition.getErrorIndex()", -1, index.getErrorIndex());
-        assertEquals("ParsePosition.getIndex()",      18, index.getIndex());
+        assertEquals("ParsePosition.getIndex()",      19, index.getIndex());
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java?rev=1781500&r1=1781499&r2=1781500&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
[UTF-8] Fri Feb  3 07:15:21 2017
@@ -125,6 +125,7 @@ final class DefaultFormat extends Format
      */
     @Override
     public Object parseObject(String source, final ParsePosition pos) {
+        boolean exponent = false;
         final int index = CharSequences.skipLeadingWhitespaces(source, pos.getIndex(), source.length());
         int end;
         for (end = index; end < source.length(); end++) {
@@ -139,7 +140,11 @@ final class DefaultFormat extends Format
                      */
                 }
                 case ',': case '/': break;
-                case 'E': case 'e': continue;
+                case 'E': case 'e': {
+                    if (exponent) break;
+                    exponent = true;
+                    continue;
+                }
             }
             break;
         }



Mime
View raw message