sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1688991 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-metadata/src/test/java/org/apache/sis/io/wkt/ sis-utility/src/main/java/org/apache/sis/util/ sis-utility/src/main/java/org/apache/sis/util/resource...
Date Fri, 03 Jul 2015 10:17:15 GMT
Author: desruisseaux
Date: Fri Jul  3 10:17:14 2015
New Revision: 1688991

URL: http://svn.apache.org/r1688991
Log:
WKT 2: add check of character validity.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Warnings.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/TransliteratorTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharactersTest.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -20,7 +20,6 @@ import java.io.Console;
 import java.io.PrintWriter;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.xml.bind.annotation.XmlTransient;
-import org.opengis.util.InternationalString;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.internal.util.X364;
@@ -181,9 +180,14 @@ public abstract class FormattableObject
         try {
             formatter.append(this);
             if (strict) {
-                final InternationalString message = formatter.getErrorMessage();
-                if (message != null) {
-                    throw new UnformattableObjectException(message.toString(), formatter.getErrorCause());
+                /*
+                 * If a warning occurred, consider the object as non-formattable.
+                 * We take the last message since it is more likely to be about the enclosing
element.
+                 */
+                final Warnings warnings = formatter.getWarnings();
+                if (warnings != null) {
+                    final int n = warnings.getNumMessages() - 1;
+                    throw new UnformattableObjectException(warnings.getMessage(n), warnings.getException(n));
                 }
             }
             wkt = formatter.toWKT();

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -60,6 +60,7 @@ import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.Localized;
+import org.apache.sis.util.Characters;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
@@ -297,20 +298,12 @@ public class Formatter implements Locali
     private boolean highlightError;
 
     /**
-     * Non-null if the WKT is invalid. If non-null, then this field contains a keyword that
identify the
-     * problematic part.
+     * The warnings that occurred during WKT formatting, or {@code null} if none.
      *
      * @see #isInvalidWKT()
-     * @see #getErrorMessage()
+     * @see #getWarnings()
      */
-    private String invalidElement;
-
-    /**
-     * Error that occurred during WKT formatting, or {@code null} if none.
-     *
-     * @see #getErrorCause()
-     */
-    private Exception errorCause;
+    private Warnings warnings;
 
     /**
      * Creates a new formatter instance with the default configuration.
@@ -626,11 +619,10 @@ public class Formatter implements Locali
         if (keyword == null) {
             if (info != null) {
                 setInvalidWKT(info, null);
-                keyword = getName(info.getClass());
             } else {
                 setInvalidWKT(object.getClass(), null);
-                keyword = invalidElement;
             }
+            keyword = getName(object.getClass());
         } else if (toUpperCase != 0) {
             final Locale locale = symbols.getLocale();
             keyword = (toUpperCase >= 0) ? keyword.toUpperCase(locale) : keyword.toLowerCase(locale);
@@ -976,14 +968,24 @@ public class Formatter implements Locali
      * that character will be doubled (WKT 2) or deleted (WKT 1). We check for the closing
quote only because
      * it is the character that the parser will look for determining the text end.
      */
-    private void quote(final String text, final ElementKind type) {
+    private void quote(String text, final ElementKind type) {
         setColor(type);
         final int base = buffer.appendCodePoint(symbols.getOpeningQuote(0)).length();
-        if (type == ElementKind.REMARKS) {
-            buffer.append(text);
-        } else {
-            buffer.append(transliterator.filter(text));
+        if (type != ElementKind.REMARKS) {
+            text = transliterator.filter(text);
+            final int length = text.length();
+            for (int i = 0; i < length;) {
+                final int c = text.codePointAt(i);
+                final int n = Character.charCount(c);
+                if (!Characters.isValidWKT(c)) {
+                    warnings().add(Errors.formatInternational(Errors.Keys.IllegalCharacterForFormat_3,
+                            "Well-Known Text", text, text.substring(i, i+n)), null, null);
+                    break;
+                }
+                i += n;
+            }
         }
+        buffer.append(text);
         closeQuote(base);
         resetColor();
     }
@@ -1451,7 +1453,7 @@ public class Formatter implements Locali
      * @return {@code true} if the WKT is invalid.
      */
     public boolean isInvalidWKT() {
-        return (invalidElement != null) || (buffer != null && buffer.length() ==
0);
+        return (warnings != null) || (buffer != null && buffer.length() == 0);
         /*
          * Note: we really use a "and" condition (not an other "or") for the buffer test
because
          *       the buffer is reset to 'null' by WKTFormat after a successfull formatting.
@@ -1459,15 +1461,21 @@ public class Formatter implements Locali
     }
 
     /**
+     * Returns the object where to store warnings.
+     */
+    private Warnings warnings() {
+        if (warnings == null) {
+            warnings = new Warnings(locale, (byte) 0, Collections.emptyMap());
+        }
+        return warnings;
+    }
+
+    /**
      * Marks the current WKT representation of the given object as not strictly compliant
with the WKT specification.
      * This method can be invoked by implementations of {@link FormattableObject#formatTo(Formatter)}
when the object
      * to format is more complex than what the WKT specification allows.
      * Applications can test {@link #isInvalidWKT()} later for checking WKT validity.
      *
-     * <p>If any {@code setInvalidWKT(…)} method is invoked more than once during
formatting,
-     * then only information about the last failure will be retained. The reason is that
the
-     * last failure is typically the enclosing element.</p>
-     *
      * @param unformattable The object that can not be formatted,
      * @param cause The cause for the failure to format, or {@code null} if the cause is
not an exception.
      */
@@ -1478,9 +1486,7 @@ public class Formatter implements Locali
         if (id == null || (name = id.getCode()) == null) {
             name = getName(unformattable.getClass());
         }
-        invalidElement = name;
-        errorCause     = cause;
-        highlightError = true;
+        setInvalidWKT(name, cause);
     }
 
     /**
@@ -1488,18 +1494,22 @@ public class Formatter implements Locali
      * This method can be used as an alternative to {@link #setInvalidWKT(IdentifiedObject,
Exception)} when the
      * problematic object is not an instance of {@code IdentifiedObject}.
      *
-     * <p>If any {@code setInvalidWKT(…)} method is invoked more than once during
formatting,
-     * then only information about the first failure will be retained.</p>
-     *
      * @param unformattable The class of the object that can not be formatted,
      * @param cause The cause for the failure to format, or {@code null} if the cause is
not an exception.
      */
     public void setInvalidWKT(final Class<?> unformattable, final Exception cause)
{
         ArgumentChecks.ensureNonNull("unformattable", unformattable);
-        if (invalidElement == null) {
-            invalidElement = getName(unformattable);
-            errorCause     = cause;
-        }
+        setInvalidWKT(getName(unformattable), cause);
+    }
+
+    /**
+     * Implementation of public {@code setInvalidWKT(…)} methods.
+     *
+     * <div class="note"><b>Note:</b> the message is stored as an {@link
InternationalString}
+     * in order to defer the actual message formatting until needed.</div>
+     */
+    private void setInvalidWKT(final String invalidElement, final Exception cause) {
+        warnings().add(Errors.formatInternational(Errors.Keys.CanNotRepresentInFormat_2,
"WKT", invalidElement), cause, null);
         highlightError = true;
     }
 
@@ -1520,24 +1530,10 @@ public class Formatter implements Locali
     }
 
     /**
-     * Returns the error message {@link #isInvalidWKT()} is set, or {@code null} otherwise.
-     * If non-null, a cause may be available in the {@link #getErrorCause()} method.
-     *
-     * <div class="note"><b>Note:</b> the message is returned as an {@link
InternationalString}
-     * in order to defer the actual message formatting until needed.</div>
-     */
-    final InternationalString getErrorMessage() {
-        if (!isInvalidWKT()) {
-            return null;
-        }
-        return Errors.formatInternational(Errors.Keys.CanNotRepresentInFormat_2, "WKT", invalidElement);
-    }
-
-    /**
-     * Returns the cause of the error, or {@code null} if the cause is not an exception.
+     * Returns the warnings, or {@code null} if none.
      */
-    final Exception getErrorCause() {
-        return errorCause;
+    final Warnings getWarnings() {
+        return warnings;
     }
 
     /**
@@ -1588,7 +1584,6 @@ public class Formatter implements Locali
         requestNewLine    = false;
         isComplement      = false;
         highlightError    = false;
-        invalidElement    = null;
-        errorCause        = null;
+        warnings          = null;
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -92,6 +92,7 @@ import org.apache.sis.util.Characters;
  * @version 0.6
  * @module
  *
+ * @see org.apache.sis.util.Characters#isValidWKT(int)
  * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#39">WKT 2
specification §7.5.3</a>
  */
 public abstract class Transliterator implements Serializable {
@@ -101,6 +102,11 @@ public abstract class Transliterator imp
     private static final long serialVersionUID = 7115456393795045932L;
 
     /**
+     * A bitmask of control characters that are considered as spaces according {@link Character#isWhitespace(char)}.
+     */
+    static final int SPACES = 0xF0003E00;
+
+    /**
      * Default names to associate to axis directions in a Cartesian coordinate system.
      * Those names do not apply to other kind of coordinate systems.
      *
@@ -146,13 +152,38 @@ public abstract class Transliterator imp
      * {@linkplain Symbols#getClosingQuote(int) closing quotes}. The quotes will be doubled
by the
      * caller if needed after this method has been invoked.</p>
      *
-     * <p>The default implementation invokes {@link CharSequences#toASCII(CharSequence)}.</p>
+     * <p>The default implementation invokes {@link CharSequences#toASCII(CharSequence)},
+     * replaces line feed and tabulations by single spaces, then remove control characters.</p>
      *
      * @param  text The text to format without non-ASCII characters.
      * @return The text to write in <cite>Well Known Text</cite>.
+     *
+     * @see org.apache.sis.util.Characters#isValidWKT(int)
      */
     public String filter(final String text) {
-        return CharSequences.toASCII(text).toString();
+        CharSequence s = CharSequences.toASCII(text);
+        StringBuilder buffer = null;
+        for (int i=s.length(); --i >= 0;) {
+            final char c = s.charAt(i);
+            if (c < 32) {
+                if (buffer == null) {
+                    if (s == text) {
+                        s = buffer = new StringBuilder(text);
+                    } else {
+                        buffer = (StringBuilder) s;
+                    }
+                }
+                if ((SPACES & (1 << c)) != 0) {
+                    buffer.setCharAt(i, ' ');
+                    if (i != 0 && c == '\n' && s.charAt(i-1) == '\r') {
+                        buffer.deleteCharAt(--i);
+                    }
+                } else {
+                    buffer.deleteCharAt(i);
+                }
+            }
+        }
+        return s.toString();
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -21,7 +21,6 @@ import java.util.Locale;
 import java.util.TimeZone;
 import java.util.Map;
 import java.util.HashMap;
-import java.util.Collections;
 import java.io.IOException;
 import java.text.Format;
 import java.text.NumberFormat;
@@ -574,18 +573,15 @@ public class WKTFormat extends CompoundF
             this.formatter = formatter;
         }
         final boolean valid;
-        final InternationalString warning;
         try {
             formatter.setBuffer(buffer);
             valid = formatter.appendElement(object) || formatter.appendValue(object);
         } finally {
-            warning = formatter.getErrorMessage();  // Must be saved before formatter.clear()
is invoked.
+            warnings = formatter.getWarnings();  // Must be saved before formatter.clear()
is invoked.
             formatter.setBuffer(null);
             formatter.clear();
         }
-        if (warning != null) {
-            warnings = new Warnings(getLocale(), (byte) 0, Collections.emptyMap());
-            warnings.add(warning, formatter.getErrorCause(), null);
+        if (warnings != null) {
             warnings.setRoot(object);
         }
         if (!valid) {

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Warnings.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Warnings.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Warnings.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Warnings.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -32,6 +32,7 @@ import org.opengis.util.InternationalStr
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.Localized;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.resources.Vocabulary;
@@ -232,6 +233,49 @@ public final class Warnings implements L
     }
 
     /**
+     * Returns the number of warning messages.
+     *
+     * @return The number of warning messages.
+     */
+    public final int getNumMessages() {
+        return (messages != null) ? messages.size() / 2 : 0;
+    }
+
+    /**
+     * Returns a warning message.
+     *
+     * @param  index 0 for the first warning, 1 for the second warning, <i>etc.</i>
until {@link #getNumMessages()} - 1.
+     * @return The <var>i</var>-th warning message.
+     */
+    public String getMessage(int index) {
+        ArgumentChecks.ensureValidIndex(getNumMessages(), index);
+        index *= 2;
+        final InternationalString i18n = (InternationalString) messages.get(index);
+        if (i18n != null) {
+            return i18n.toString(errorLocale);
+        } else {
+            final Exception cause = (Exception) messages.get(index + 1);
+            final String[] sources = exceptionSources.get(cause);   // See comment in 'toString(Locale)'.
+            if (sources != null) {
+                return Errors.getResources(errorLocale).getString(Errors.Keys.UnparsableStringInElement_2,
sources);
+            } else {
+                return cause.toString();
+            }
+        }
+    }
+
+    /**
+     * Returns the exception which was the cause of the message at the given index, or {@code
null} if none.
+     *
+     * @param  index The value given to {@link #getMessage(int)}.
+     * @return The exception which was the cause of the warning message, or {@code null}
if none.
+     */
+    public Exception getException(final int index) {
+        ArgumentChecks.ensureValidIndex(getNumMessages(), index);
+        return (Exception) messages.get(index*2 + 1);
+    }
+
+    /**
      * Returns the non-fatal exceptions that occurred during the parsing or formatting.
      * If no exception occurred, returns an empty set.
      *
@@ -308,7 +352,7 @@ public final class Warnings implements L
               .append(lineSeparator);
         if (messages != null) {
             for (final Iterator<?> it = messages.iterator(); it.hasNext();) {
-                InternationalString i18n = (InternationalString) it.next();
+                final InternationalString i18n = (InternationalString) it.next();
                 Exception cause = (Exception) it.next();
                 final String message;
                 if (i18n != null) {

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/TransliteratorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/TransliteratorTest.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/TransliteratorTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/TransliteratorTest.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -22,6 +22,7 @@ import org.opengis.referencing.cs.Ellips
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.apache.sis.internal.metadata.AxisNames;
 import org.apache.sis.test.mock.CoordinateSystemAxisMock;
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -38,6 +39,31 @@ import static org.junit.Assert.*;
  */
 public final strictfp class TransliteratorTest extends TestCase {
     /**
+     * Verify the value of the {@link Transliterator#SPACES} constant.
+     */
+    @Test
+    public void testSpacesConstant() {
+        int code = 0;
+        for (char c=0; c<32; c++) {
+            if (Character.isWhitespace(c)) {
+                code |= (1 << c);
+            }
+        }
+        assertEquals(Transliterator.SPACES, code);
+    }
+
+    /**
+     * Tests {@link Transliterator#filter(String)}.
+     */
+    @Test
+    @DependsOnMethod("testSpacesConstant")
+    public void testFilter() {
+        final Transliterator t = Transliterator.DEFAULT;
+        assertEquals("Nouvelle triangulation francaise", t.filter("Nouvelle\r\ntriangulation\nfrançaise"));
+        assertEquals("ABC D E", t.filter("AB\bC\rD\tE"));
+    }
+
+    /**
      * Tests {@link Transliterator#toLongAxisName(String, AxisDirection, String)}.
      */
     @Test

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Characters.java [UTF-8]
Fri Jul  3 10:17:14 2015
@@ -28,7 +28,7 @@ import org.apache.sis.util.resources.Err
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public final class Characters extends Static {
@@ -78,6 +78,34 @@ public final class Characters extends St
     }
 
     /**
+     * Returns {@code true} if the given code point is a valid character for <cite>Well
Known Text</cite> (WKT).
+     * This method returns {@code true} for the following characters:
+     *
+     * <blockquote><pre>{@literal A-Z a-z 0-9 _ [ ] ( ) { } < = > . , :
; + - (space) % & ' " * ^ / \ ? | °}</pre></blockquote>
+     *
+     * They are ASCII codes 32 to 125 inclusive except ! (33), # (35), $ (36), @ (64) and
` (96),
+     * plus the addition of ° (176) despite being formally outside the ASCII character set.
+     *
+     * @param  c The code point to test.
+     * @return {@code true} if the given code point is a valid WKT character.
+     *
+     * @see org.apache.sis.io.wkt.Transliterator
+     *
+     * @since 0.6
+     */
+    public static boolean isValidWKT(final int c) {
+        switch (c) {
+            case '!':
+            case '#':
+            case '$':
+            case '@':
+            case '`': return false;
+            case '°': return true;
+            default : return (c >= ' ') && (c <= '}');
+        }
+    }
+
+    /**
      * Returns {@code true} if the given code point is a {@linkplain Character#LINE_SEPARATOR
      * line separator}, a {@linkplain Character#PARAGRAPH_SEPARATOR paragraph separator}
or one
      * of the {@code '\r'} or {@code '\n'} control characters.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -227,6 +227,8 @@ public final class StringBuilders extend
                         cr = ASCII.charAt(r);
                     } else {
                         switch (getType(c)) {
+                            case FORMAT:
+                            case CONTROL: buffer.delete(i, i + n); continue;  // Character.isIdentifierIgnorable
                             case PARAGRAPH_SEPARATOR:       // Fall through
                             case LINE_SEPARATOR:            cr = '\n'; break;
                             case SPACE_SEPARATOR:           cr = ' '; break;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -328,6 +328,11 @@ public final class Errors extends Indexe
         public static final short IllegalCRSType_1 = 194;
 
         /**
+         * The “{2}” character in “{1}” is not permitted by the “{0}” format.
+         */
+        public static final short IllegalCharacterForFormat_3 = 195;
+
+        /**
          * Class ‘{1}’ is illegal. It must be ‘{0}’ or a derived class.
          */
         public static final short IllegalClass_2 = 34;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Fri Jul  3 10:17:14 2015
@@ -74,6 +74,7 @@ IllegalArgumentField_4            = Argu
 IllegalArgumentValue_2            = Argument \u2018{0}\u2019 can not take the \u201c{1}\u201d
value.
 IllegalAxisDirection_2            = Coordinate system of class \u2018{0}\u2019 can not have
axis in the {1} direction.
 IllegalBitsPattern_1              = Illegal bits pattern: {0}.
+IllegalCharacterForFormat_3       = The \u201c{2}\u201d character in \u201c{1}\u201d is not
permitted by the \u201c{0}\u201d format.
 IllegalClass_2                    = Class \u2018{1}\u2019 is illegal. It must be \u2018{0}\u2019
or a derived class.
 IllegalCoordinateSystem_1         = Coordinate system can not be \u201c{0}\u201d.
 IllegalCRSType_1                  = Coordinate reference system can not be of type \u2018{0}\u2019.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Fri Jul  3 10:17:14 2015
@@ -72,6 +72,7 @@ IllegalArgumentValue_2            = L\u2
 IllegalAxisDirection_2            = Les syst\u00e8mes de coordonn\u00e9es de classe \u2018{0}\u2019
ne peuvent pas avoir d\u2019axe dans la direction \u00ab\u202f{1}\u202f\u00bb.
 IllegalBitsPattern_1              = Pattern de bits invalide: {0}.
 IllegalClass_2                    = La classe \u2018{1}\u2019 est ill\u00e9gale. Il doit
s\u2019agir d\u2019une classe \u2018{0}\u2019 ou d\u00e9riv\u00e9e.
+IllegalCharacterForFormat_3       = Le caract\u00e8re \u00ab\u202f{2}\u202f\u00bb dans \u00ab\u202f{1}\u202f\u00bb
n\u2019est pas permis par le format \u00ab\u202f{0}\u202f\u00bb.
 IllegalCoordinateSystem_1         = Le syst\u00e8me de coordonn\u00e9es ne peut pas \u00eatre
\u00ab\u202f{0}\u202f\u00bb.
 IllegalCRSType_1                  = Le syst\u00e8me de r\u00e9f\u00e9rence des coordonn\u00e9es
ne peut pas \u00eatre de type \u2018{0}\u2019.
 IllegalFormatPatternForClass_2    = Le mod\u00e8le \u00ab\u202f{1}\u202f\u00bb ne peut pas
\u00eatre appliqu\u00e9 au formatage d\u2019objets de type \u2018{0}\u2019.

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharactersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharactersTest.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharactersTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharactersTest.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -29,7 +29,7 @@ import static org.apache.sis.util.Charac
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public final strictfp class CharactersTest extends TestCase {
@@ -44,6 +44,21 @@ public final strictfp class CharactersTe
     }
 
     /**
+     * Tests the {@link Characters#isValidWKT(int)} method.
+     */
+    @Test
+    public void testIsValidWKT() {
+        final String valids = "_[](){}<=>.,:;+- %&'\"*^/\\?|°";
+        for (char c=0; c<256; c++) {
+            final boolean valid = (c >= 'A' && c <= 'Z')
+                               || (c >= 'a' && c <= 'z')
+                               || (c >= '0' && c <= '9')
+                               || valids.indexOf(c) >= 0;
+            assertEquals(valid, isValidWKT(c));
+        }
+    }
+
+    /**
      * Tests the {@link Characters#isLineOrParagraphSeparator(int)} method.
      */
     @Test

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java?rev=1688991&r1=1688990&r2=1688991&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java
[UTF-8] Fri Jul  3 10:17:14 2015
@@ -97,10 +97,10 @@ public final strictfp class StringBuilde
      */
     @Test
     public void testToASCII() {
-        final StringBuilder metre = new StringBuilder(
+        final StringBuilder s = new StringBuilder(
                 "mètres" + Characters.PARAGRAPH_SEPARATOR +
                 " ‘single’, “double”, \"ascii' 30°20′10″.");
-        toASCII(metre);
-        assertEquals("metres\n 'single', \"double\", \"ascii' 30°20'10\".", metre.toString());
+        toASCII(s);
+        assertEquals("metres\n 'single', \"double\", \"ascii' 30°20'10\".", s.toString());
     }
 }



Mime
View raw message