sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Minor documentation fixes.
Date Mon, 14 Oct 2019 18:35:20 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 692ba84  Minor documentation fixes.
692ba84 is described below

commit 692ba847725928f391ecdb74bfc203d2901fde1e
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Oct 14 20:35:07 2019 +0200

    Minor documentation fixes.
---
 .../sis/referencing/AbstractIdentifiedObject.java   |  4 ++--
 .../java/org/apache/sis/internal/util/Strings.java  | 21 ++++++++++++++++-----
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
index c658b21..fe03695 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
@@ -880,9 +880,9 @@ public class AbstractIdentifiedObject extends FormattableObject implements
Ident
     }
 
     /**
-     * Formats the name of identifier of this object using the provider formatter.
+     * Formats the name or identifier of this object using the provider formatter.
      * This method is invoked when an {@code IdentifiedObject} object is formatted
-     * using the {@code "%s"} conversion specifier of {@link Formatter}.
+     * using the {@code "%s"} conversion specifier of {@link java.util.Formatter}.
      * Users don't need to invoke this method explicitly.
      *
      * <p>If the alternate flags is present (as in {@code "%#s"}), then this method
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/Strings.java b/core/sis-utility/src/main/java/org/apache/sis/internal/util/Strings.java
index ed5d200..be132c9 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/Strings.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/Strings.java
@@ -277,14 +277,20 @@ public final class Strings extends Static {
      * @param value      the text to format.
      */
     public static void formatTo(final Formatter formatter, final int flags, int width, int
precision, String value) {
-        final String format;
-        final Object[] args;
+        /*
+         * Converting to upper cases may change the string length in some locales.
+         * So we need to perform this conversion before to check the length.
+         */
         boolean isUpperCase = (flags & FormattableFlags.UPPERCASE) != 0;
-        if (isUpperCase && width > 0) {
-            // May change the string length in some locales.
+        if (isUpperCase && (width > 0 || precision >= 0)) {
             value = value.toUpperCase(formatter.locale());
             isUpperCase = false;                            // Because conversion has already
been done.
         }
+        /*
+         * If the string is longer than the specified "precision", truncate
+         * and add "…" for letting user know that there is missing characters.
+         * This loop counts the number of Unicode code points rather than characters.
+         */
         int length = value.length();
         if (precision >= 0) {
             for (int i=0,n=0; i<length; i += n) {
@@ -305,7 +311,12 @@ public final class Strings extends Static {
                 n = Character.charCount(value.codePointAt(i));
             }
         }
-        // Double check since length() is faster than codePointCount(…).
+        /*
+         * If the string is shorter than the minimal width, add spaces on the left or right
side.
+         * We double check with `width > length` since it is faster than codePointCount(…).
+         */
+        final String format;
+        final Object[] args;
         if (width > length && (width -= value.codePointCount(0, length)) >
0) {
             format = "%s%s";
             args = new Object[] {value, value};


Mime
View raw message