sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1766138 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-utility/src/main/java/org/apache/sis/measure/ sis-utility/src/main/java/org/apache/sis/util/ sis-utility/src/test/java/org/apache/sis/util/
Date Fri, 21 Oct 2016 21:21:03 GMT
Author: desruisseaux
Date: Fri Oct 21 21:21:02 2016
New Revision: 1766138

URL: http://svn.apache.org/viewvc?rev=1766138&view=rev
Log:
Begin work on UnitFormat by first clarifying which Unicode characters we will use.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.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/AbstractParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java?rev=1766138&r1=1766137&r2=1766138&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
[UTF-8] Fri Oct 21 21:21:02 2016
@@ -340,6 +340,7 @@ abstract class AbstractParser implements
                 return Units.valueOf(text);             // Most common case.
             }
             unitFormat = UnitFormat.getInstance(locale);
+            unitFormat.setStyle(UnitFormat.Style.NAME);
         }
         return unitFormat.parse(text);
     }

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=1766138&r1=1766137&r2=1766138&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 Oct 21 21:21:02 2016
@@ -346,6 +346,10 @@ public class Formatter implements Locali
         this.dateFormat    = new StandardDateFormat(symbols.getLocale());
         this.unitFormat    = UnitFormat.getInstance(symbols.getLocale());
         this.buffer        = new StringBuffer();
+        unitFormat.setStyle(UnitFormat.Style.NAME);
+        if (convention.usesCommonUnits) {
+            unitFormat.setLocale(Locale.US);
+        }
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java?rev=1766138&r1=1766137&r2=1766138&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
[UTF-8] Fri Oct 21 21:21:02 2016
@@ -33,6 +33,7 @@ import org.apache.sis.internal.util.Defi
 import org.apache.sis.internal.util.XPaths;
 import org.apache.sis.math.Fraction;
 import org.apache.sis.util.ArraysExt;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Characters;
 import org.apache.sis.util.Exceptions;
@@ -87,26 +88,62 @@ public class UnitFormat extends Format i
      * The default instance used by {@link Units#valueOf(String)} for parsing units of measurement.
      */
     static final UnitFormat INSTANCE = new UnitFormat();
-    static {
-        INSTANCE.longName = false;
-    }
 
     /**
-     * The locale specified at construction time.
+     * The locale specified at construction time or modified by {@link #setLocale(Locale)}.
+     *
+     * @see #getLocale()
      */
     private Locale locale;
 
     /**
-     * {@code true} for formatting the unit names using US spelling.
-     * Example: "meter" instead of "metre".
+     * Whether this {@code UnitFormat} should format long names like "metre" or use unit
symbols.
+     *
+     * @see #getStyle()
      */
-    private boolean isLocaleUS;
+    private Style style;
 
     /**
-     * Whether this {@code UnitFormat} should format long names like "metre".
-     * If {@code false}, then this instance will format only unit symbols.
-     */
-    private boolean longName = true;
+     * Identify whether unit formatting uses ASCII symbols, Unicode symbols or full localized
names.
+     * For example the {@link Units#CUBIC_METRE} units can be formatted in the following
ways:
+     *
+     * <ul>
+     *   <li>As a symbol using Unicode characters: <b>m³</b></li>
+     *   <li>As a symbol restricted to the ASCII characters set: <b>m3</b></li>
+     *   <li>As a long name:<ul>
+     *     <li>in English: <cite>cubic metre</cite></li>
+     *     <li>in French: <cite>mètre cube</cite></li>
+     *   </ul></li>
+     * </ul>
+     *
+     * @author  Martin Desruisseaux (Geomatys)
+     * @since   0.8
+     * @version 0.8
+     * @module
+     */
+    public static enum Style {
+        /**
+         * Format unit symbols using Unicode characters. Units formatted in this style use
superscript digits
+         * for exponents (as in “m³”), the dot operator (“⋅”) for multiplications,
specialized characters when
+         * they exist (e.g. U+212A “K” for Kelvin sign), <i>etc.</i>
+         *
+         * <p>This is the default style of {@link UnitFormat}.</p>
+         */
+        SYMBOL,
+
+        /**
+         * Format unit symbols using the Unified Code for Units of Measure (UCUM) syntax.
+         * Those symbols are restricted to the ASCII character set.
+         *
+         * @see org.apache.sis.util.CharSequences#toASCII(CharSequence)
+         */
+        UCUM,
+
+        /**
+         * Format unit symbols as localized long names if known, or Unicode symbols otherwise.
+         */
+        NAME
+    }
 
     /**
      * Creates a new format for the given locale.
@@ -121,10 +158,14 @@ public class UnitFormat extends Format i
     }
 
     /**
-     * Creates a new format initialized to the {@link Locale#ROOT} locale.
+     * Creates a new format. This constructor is for subclasses only.
+     * Subclasses should {@linkplain #setLocale set the locale} to some default value.
+     *
+     * @see #getInstance(Locale)
      */
-    private UnitFormat() {
+    protected UnitFormat() {
         locale = Locale.ROOT;
+        style = Style.SYMBOL;
     }
 
     /**
@@ -138,29 +179,58 @@ public class UnitFormat extends Format i
     }
 
     /**
-     * Sets the locale used by this {@code UnitFormat}.
+     * Sets the locale that this {@code UnitFormat} will use for long names.
+     * For example a call to <code>setLocale({@linkplain Locale#US})</code>
+     * instructs this formatter to use the “meter” spelling instead of “metre”.
      *
-     * @param locale the new locale for this {@code UnitFormat}.
+     * @param  locale  the new locale for this {@code UnitFormat}.
      */
     public void setLocale(final Locale locale) {
-        isLocaleUS = locale.getCountry().equalsIgnoreCase("US");
+        ArgumentChecks.ensureNonNull("locale", locale);
         this.locale = locale;
     }
 
     /**
-     * Returns {@code true} since this {@code UnitFormat} depends on the {@link Locale}
-     * given at construction time for performing its tasks.
+     * Returns {@code true} if the locale is the US one.
+     */
+    private boolean isLocaleUS() {
+        return locale.getCountry().equalsIgnoreCase("US");
+    }
+
+    /**
+     * Returns whether this {@code UnitFormat} depends on the {@link Locale} given at construction
time
+     * for performing its tasks. This method returns {@code true} if formatting long names
(e.g. “metre”
+     * or “meter”} and {@code false} if formatting only the unit symbol (e.g. “m”).
      *
-     * @return {@code true}.
+     * @return {@code true} if formatting depends on the locale.
      */
     @Override
     public boolean isLocaleSensitive() {
-        return true;
+        return style == Style.NAME;
+    }
+
+    /**
+     * Returns whether unit formatting uses ASCII symbols, Unicode symbols or full localized
names.
+     *
+     * @return the style of units formatted by this {@code UnitFormat} instance.
+     */
+    public Style getStyle() {
+        return style;
+    }
+
+    /**
+     * Sets whether unit formatting should use ASCII symbols, Unicode symbols or full localized
names.
+     *
+     * @param  style  the desired style of units.
+     */
+    public void setStyle(final Style style) {
+        ArgumentChecks.ensureNonNull("style", style);
+        this.style = style;
     }
 
     /**
      * Attaches a label to the specified unit.
-     * If the specified label is already associated to another unit, then this method does
nothing.
+     * If the specified label is already associated to another unit, then the previous association
is discarded.
      *
      * @param  unit   the unit being labeled.
      * @param  label  the new label for the given unit.
@@ -184,7 +254,7 @@ public class UnitFormat extends Format i
         if (symbol != null) {
             return toAppendTo.append(symbol);
         }
-        if (longName) {
+        if (style == Style.NAME) {
             /*
              * Following are specific to the WKT format, which is currently the only user
of this method.
              * If we invoke this method for other purposes, then we would need to provide
more control on
@@ -195,7 +265,7 @@ public class UnitFormat extends Format i
             } else if (Units.DEGREE.equals(unit)) {
                 return toAppendTo.append("degree");
             } else if (Units.METRE.equals(unit)) {
-                return toAppendTo.append(isLocaleUS ? "meter" : "metre");
+                return toAppendTo.append(isLocaleUS() ? "meter" : "metre");
             } else if (Units.US_SURVEY_FOOT.equals(unit)) {
                 return toAppendTo.append("US survey foot");
             } else if (Units.PPM.equals(unit)) {

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java?rev=1766138&r1=1766137&r2=1766138&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8]
Fri Oct 21 21:21:02 2016
@@ -722,10 +722,12 @@ public final class Units extends Static
 
         UnitRegistry.alias(UNITY,       Short.valueOf((short) 9203));
         UnitRegistry.alias(DEGREE,      Short.valueOf(Constants.EPSG_AXIS_DEGREES));
+        UnitRegistry.alias(DEGREE,    "deg");
         UnitRegistry.alias(ARC_MINUTE,  "'");
         UnitRegistry.alias(ARC_SECOND, "\"");
         UnitRegistry.alias(KELVIN,      "K");       // Ordinary "K" letter (not the dedicated
Unicode character).
         UnitRegistry.alias(CELSIUS,    "°C");
+        UnitRegistry.alias(CELSIUS,   "Cel");
 
         initialized = true;
     }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java?rev=1766138&r1=1766137&r2=1766138&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
[UTF-8] Fri Oct 21 21:21:02 2016
@@ -921,10 +921,10 @@ search:     for (; fromIndex <= toIndex;
 
     /**
      * Replaces some Unicode characters by ASCII characters on a "best effort basis".
-     * For example the {@code 'é'} character is replaced by {@code 'e'} (without accent).
-     *
-     * <p>The current implementation replaces the characters in the range {@code 00C0}
-     * to {@code 00FF} (inclusive) and some space and punctuation characters.</p>
+     * For example the “ é ” character is replaced by  “ e ” (without accent),
+     * the  “ ″ ” symbol for minutes of angle is replaced by straight double quotes
“ " ”,
+     * and combined characters like ㎏, ㎎, ㎝, ㎞, ㎢, ㎦, ㎖, ㎧, ㎩, ㎐, <i>etc.</i>
are replaced
+     * by the corresponding sequences of characters.
      *
      * <div class="note"><b>Note:</b>
      * the replacement of Greek letters is a more complex task than what this method can
do,
@@ -938,6 +938,7 @@ search:     for (; fromIndex <= toIndex;
      *
      * @see StringBuilders#toASCII(StringBuilder)
      * @see org.apache.sis.io.wkt.Transliterator#filter(String)
+     * @see java.text.Normalizer
      */
     public static CharSequence toASCII(final CharSequence text) {
         return StringBuilders.toASCII(text, null);

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=1766138&r1=1766137&r2=1766138&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 Oct 21 21:21:02 2016
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.util;
 
+import java.text.Normalizer;
 import org.apache.sis.util.resources.Errors;
 
 import static java.lang.Character.*;
@@ -34,7 +35,7 @@ import static java.lang.Character.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  *
  * @see CharSequences
@@ -42,6 +43,7 @@ import static java.lang.Character.*;
 public final class StringBuilders extends Static {
     /**
      * Letters in the range 00C0 (192) to 00FF (255) inclusive with their accent removed,
when possible.
+     * This string partially duplicates the work done by {@link java.text.Normalizer}.
      */
     private static final String ASCII = "AAAAAAÆCEEEEIIIIDNOOOOO*OUUUUYÞsaaaaaaæceeeeiiiionooooo/ouuuuyþy";
     // Original letters (with accent) = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
@@ -55,10 +57,10 @@ public final class StringBuilders extend
     /**
      * Replaces every occurrences of the given character in the given buffer.
      *
-     * @param  buffer    The string in which to perform the replacements.
-     * @param  toSearch  The character to replace.
-     * @param  replaceBy The replacement for the searched character.
-     * @throws NullArgumentException If the {@code buffer} arguments is null.
+     * @param  buffer     the string in which to perform the replacements.
+     * @param  toSearch   the character to replace.
+     * @param  replaceBy  the replacement for the searched character.
+     * @throws NullArgumentException if the {@code buffer} arguments is null.
      *
      * @see String#replace(char, char)
      */
@@ -78,11 +80,11 @@ public final class StringBuilders extend
      * This method invokes {@link StringBuilder#replace(int, int, String)}
      * for each occurrence of {@code search} found in the buffer.
      *
-     * @param  buffer    The string in which to perform the replacements.
-     * @param  toSearch  The string to replace.
-     * @param  replaceBy The replacement for the searched string.
-     * @throws NullArgumentException If any of the arguments is null.
-     * @throws IllegalArgumentException If the {@code toSearch} argument is empty.
+     * @param  buffer     the string in which to perform the replacements.
+     * @param  toSearch   the string to replace.
+     * @param  replaceBy  the replacement for the searched string.
+     * @throws NullArgumentException if any of the arguments is null.
+     * @throws IllegalArgumentException if the {@code toSearch} argument is empty.
      *
      * @see String#replace(char, char)
      * @see CharSequences#replace(CharSequence, CharSequence, CharSequence)
@@ -107,10 +109,10 @@ public final class StringBuilders extend
      * The substring to be replaced begins at the specified {@code start} and extends to
the
      * character at index {@code end - 1}.
      *
-     * @param  buffer The buffer in which to perform the replacement.
-     * @param  start  The beginning index in the {@code buffer}, inclusive.
-     * @param  end    The ending index in the {@code buffer}, exclusive.
-     * @param  chars  The array that will replace previous contents.
+     * @param  buffer  the buffer in which to perform the replacement.
+     * @param  start   the beginning index in the {@code buffer}, inclusive.
+     * @param  end     the ending index in the {@code buffer}, exclusive.
+     * @param  chars   the array that will replace previous contents.
      * @throws NullArgumentException if the {@code buffer} or {@code chars} argument is null.
      *
      * @see StringBuilder#replace(int, int, String)
@@ -140,10 +142,10 @@ public final class StringBuilders extend
      * {@link StringBuilder#delete(int, int)} for each occurrence of {@code search} found
in
      * the buffer.
      *
-     * @param  buffer   The string in which to perform the removals.
-     * @param  toSearch The string to remove.
-     * @throws NullPointerException If any of the arguments is null.
-     * @throws IllegalArgumentException If the {@code toSearch} argument is empty.
+     * @param  buffer    the string in which to perform the removals.
+     * @param  toSearch  the string to remove.
+     * @throws NullPointerException if any of the arguments is null.
+     * @throws IllegalArgumentException if the {@code toSearch} argument is empty.
      *
      * @see StringBuilder#delete(int, int)
      */
@@ -170,8 +172,8 @@ public final class StringBuilders extend
      * This method is useful after a {@linkplain StringBuilder#append(double) double value
has
      * been appended to the buffer}, in order to make it appears like an integer when possible.
      *
-     * @param buffer The buffer to trim if possible.
-     * @throws NullArgumentException If the given {@code buffer} is null.
+     * @param  buffer  the buffer to trim if possible.
+     * @throws NullArgumentException if the given {@code buffer} is null.
      *
      * @see CharSequences#trimFractionalPart(CharSequence)
      */
@@ -191,15 +193,16 @@ public final class StringBuilders extend
 
     /**
      * Replaces some Unicode characters by ASCII characters on a "best effort basis".
-     * For example the {@code 'é'} character is replaced by {@code 'e'} (without accent).
+     * For example the “ é ” character is replaced by  “ e ” (without accent),
+     * the  “ ″ ” symbol for minutes of angle is replaced by straight double quotes
“ " ”,
+     * and combined characters like ㎏, ㎎, ㎝, ㎞, ㎢, ㎦, ㎖, ㎧, ㎩, ㎐, <i>etc.</i>
are replaced
+     * by the corresponding sequences of characters.
      *
-     * <p>The current implementation replaces the characters in the range {@code 00C0}
-     * to {@code 00FF} (inclusive) and some space and punctuation characters.</p>
-     *
-     * @param  buffer The text to scan for Unicode characters to replace by ASCII characters.
-     * @throws NullArgumentException If the given {@code buffer} is null.
+     * @param  buffer  the text to scan for Unicode characters to replace by ASCII characters.
+     * @throws NullArgumentException if the given {@code buffer} is null.
      *
      * @see CharSequences#toASCII(CharSequence)
+     * @see Normalizer#normalize(CharSequence, Normalizer.Form)
      */
     public static void toASCII(final StringBuilder buffer) {
         ArgumentChecks.ensureNonNull("buffer", buffer);
@@ -211,6 +214,7 @@ public final class StringBuilders extend
      */
     static CharSequence toASCII(CharSequence text, StringBuilder buffer) {
         if (text != null) {
+            boolean doneNFKD = false;
             /*
              * Scan the buffer in reverse order because we may suppress some characters.
              */
@@ -219,41 +223,68 @@ public final class StringBuilders extend
                 final int c = codePointBefore(text, i);
                 final int n = charCount(c);
                 final int r = c - 0xC0;
-                i -= n; // After this line, 'i' is the index of character 'c'.
+                i -= n;                                     // After this line, 'i' is the
index of character 'c'.
                 if (r >= 0) {
-                    final char cr; // The character replacement.
+                    final char cr;                          // The character replacement.
                     if (r < ASCII.length()) {
                         cr = ASCII.charAt(r);
                     } else {
                         switch (getType(c)) {
                             case FORMAT:
-                            case CONTROL: buffer.delete(i, i + n); continue;  // Character.isIdentifierIgnorable
+                            case CONTROL:                   // Character.isIdentifierIgnorable
+                            case NON_SPACING_MARK:          cr = 0; break;
                             case PARAGRAPH_SEPARATOR:       // Fall through
                             case LINE_SEPARATOR:            cr = '\n'; break;
                             case SPACE_SEPARATOR:           cr = ' '; break;
                             case INITIAL_QUOTE_PUNCTUATION: cr = (c == '‘') ? '\'' : '"';
break;
                             case FINAL_QUOTE_PUNCTUATION:   cr = (c == '’') ? '\'' : '"';
break;
-                            case OTHER_PUNCTUATION: {
+                            case OTHER_PUNCTUATION:
+                            case MATH_SYMBOL: {
                                 switch (c) {
+                                    case '⋅': cr = '*';  break;
+                                    case '∕': cr = '/';  break;
                                     case '′': cr = '\''; break;
                                     case '″': cr = '"';  break;
                                     default:  continue;
                                 }
                                 break;
                             }
-                            default: continue;
+                            default: {
+                                /*
+                                 * For any unknown character, try to decompose the string
in a sequence of simpler
+                                 * letters with their modifiers and restart the whole process
from the beginning.
+                                 * If the character is still unknown after decomposition,
leave it unchanged.
+                                 */
+                                if (!doneNFKD) {
+                                    doneNFKD = true;
+                                    final String decomposed = Normalizer.normalize(text,
Normalizer.Form.NFKD);
+                                    if (!decomposed.contentEquals(text)) {
+                                        if (buffer == null) {
+                                            text = buffer = new StringBuilder(decomposed.length());
+                                        } else {
+                                            buffer.setLength(0);
+                                        }
+                                        i = buffer.append(decomposed).length();
+                                    }
+                                }
+                                continue;
+                            }
                         }
                     }
                     if (buffer == null) {
                         buffer = new StringBuilder(text.length()).append(text);
                         text = buffer;
                     }
-                    if (n == 2) {
-                        buffer.deleteCharAt(i + 1); // Remove the low surrogate of a surrogate
pair.
+                    if (cr == 0) {
+                        buffer.delete(i, i + n);
+                    } else {
+                        if (n == 2) {
+                            buffer.deleteCharAt(i + 1);         // Remove the low surrogate
of a surrogate pair.
+                        }
+                        // Nothing special to do about codepoint here, since 'c' is in
+                        // the basic plane (verified by the r < ASCII.length() check).
+                        buffer.setCharAt(i, cr);
                     }
-                    // Nothing special to do about codepoint here, since 'c' is in
-                    // the basic plane (verified by the r < ASCII.length() check).
-                    buffer.setCharAt(i, cr);
                 }
             }
         }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1766138&r1=1766137&r2=1766138&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] Fri Oct 21 21:21:02 2016
@@ -34,7 +34,7 @@ import static org.apache.sis.util.CharSe
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Johann Sorel (Geomatys)
  * @since   0.3
- * @version 0.7
+ * @version 0.8
  * @module
  */
 @DependsOn({
@@ -233,6 +233,8 @@ public final strictfp class CharSequence
 
     /**
      * Tests the {@link CharSequences#toASCII(CharSequence)} method.
+     *
+     * @see StringBuildersTest#testToASCII()
      */
     @Test
     public void testToASCII() {
@@ -240,6 +242,8 @@ public final strictfp class CharSequence
         assertSame  (metre, toASCII(metre));
         assertEquals(metre, toASCII("mètre").toString());
         assertNull  (       toASCII(null));
+        assertEquals("kg, mg, cm, km, km2, km3, ml, m/s, Pa, Hz, mol, ms, μs, m3, rad",
+                toASCII("㎏, ㎎, ㎝, ㎞, ㎢, ㎦, ㎖, ㎧, ㎩, ㎐, ㏖, ㎳, ㎲,
㎥, ㎭").toString());
     }
 
     /**

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=1766138&r1=1766137&r2=1766138&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 Oct 21 21:21:02 2016
@@ -29,7 +29,7 @@ import static org.apache.sis.util.String
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Johann Sorel (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  */
 public final strictfp class StringBuildersTest extends TestCase {
@@ -87,13 +87,15 @@ public final strictfp class StringBuilde
         final StringBuilder buffer = new StringBuilder("4.10");
         trimFractionalPart(buffer);
         assertEquals("4.10", buffer.toString());
-        buffer.setCharAt(2, '0'); // Replace the '1' by '0'.
+        buffer.setCharAt(2, '0');                                   // Replace the '1' by
'0'.
         trimFractionalPart(buffer);
         assertEquals("4", buffer.toString());
     }
 
     /**
      * Tests the {@link StringBuilders#toASCII(StringBuilder)} method.
+     *
+     * @see CharSequencesTest#testToASCII()
      */
     @Test
     public void testToASCII() {
@@ -102,5 +104,20 @@ public final strictfp class StringBuilde
                 " ‘single’, “double”, \"ascii' 30°20′10″.");
         toASCII(s);
         assertEquals("metres\n 'single', \"double\", \"ascii' 30°20'10\".", s.toString());
+        /*
+         * Characters below are in the Unicode CJK compatibility block. They are not intended
for normal use.
+         * Note that in the decomposition form of ㎲, the first character is the Greek letter
μ (U+03BC) instead
+         * of the micro sign µ (U+0085).
+         */
+        s.setLength(0);
+        toASCII(s.append("㎏, ㎎, ㎝, ㎞, ㎢, ㎦, ㎖, ㎧, ㎩, ㎐, ㏖, ㎳, ㎲,
㎥, ㎭"));
+        assertEquals("kg, mg, cm, km, km2, km3, ml, m/s, Pa, Hz, mol, ms, μs, m3, rad",
s.toString());
+        /*
+         * Characters below are not from Unicode compatibility block, but nevertheless need
decomposition or
+         * replacement. Note that the first K is the Kelvin sign (U+212A), to be replaced
by the K letter.
+         */
+        s.setLength(0);
+        toASCII(s.append("℃, K, m⋅s"));
+        assertEquals("°C, K, m*s", s.toString());
     }
 }



Mime
View raw message