diff options
author | Winson Chung <winsonc@google.com> | 2015-05-08 17:00:10 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2015-05-08 22:22:39 -0700 |
commit | 82b016cb56540fe26213e817dd0dd668099c8e20 (patch) | |
tree | 528066331689070902b505306abaecbbfbf648d0 /src/com/android/launcher3/Utilities.java | |
parent | 99d96ba6c8e3258f7d99a33d49da2aeb0da5d862 (diff) | |
download | android_packages_apps_Trebuchet-82b016cb56540fe26213e817dd0dd668099c8e20.tar.gz android_packages_apps_Trebuchet-82b016cb56540fe26213e817dd0dd668099c8e20.tar.bz2 android_packages_apps_Trebuchet-82b016cb56540fe26213e817dd0dd668099c8e20.zip |
Trim all whitespace from titles and labels.
Bug: 20953160
Change-Id: I1610df5e445a4139522226f68fa6439926bc70c6
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 2dbf078a4..298174768 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -54,6 +54,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Comparator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Various utilities shared amongst the Launcher's classes. @@ -67,6 +69,9 @@ public final class Utilities { private static final Rect sOldBounds = new Rect(); private static final Canvas sCanvas = new Canvas(); + private static final Pattern sTrimPattern = + Pattern.compile("^[\\s|\\p{javaSpaceChar}]*(.*)[\\s|\\p{javaSpaceChar}]*$"); + static { sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, Paint.FILTER_BITMAP_FLAG)); @@ -616,4 +621,14 @@ public final class Utilities { return false; } + + /** + * Trims the string, removing all whitespace at the beginning and end of the string. + * Non-breaking whitespaces are also removed. + */ + public static String trim(CharSequence s) { + // Just strip any sequence of whitespace or java space characters from the beginning and end + Matcher m = sTrimPattern.matcher(s); + return m.replaceAll("$1"); + } } |