[Android] LINT: specify Locale when using toLowerCase/toUpperCase

Sébastien Toque git at videolan.org
Sat May 25 16:33:45 CEST 2013


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sat May 25 13:27:35 2013 +0200| [1ec9b41409960c4a9fedc945420463583403aba1] | committer: Sébastien Toque

LINT: specify Locale when using toLowerCase/toUpperCase

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=1ec9b41409960c4a9fedc945420463583403aba1
---

 vlc-android/src/org/videolan/vlc/Media.java                    |    7 ++++---
 vlc-android/src/org/videolan/vlc/MediaLibrary.java             |    5 +++--
 vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java      |    3 ++-
 vlc-android/src/org/videolan/vlc/gui/SearchActivity.java       |    8 +++++---
 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java       |    5 +++--
 5 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/Media.java b/vlc-android/src/org/videolan/vlc/Media.java
index 108c39d..60aaf3d 100644
--- a/vlc-android/src/org/videolan/vlc/Media.java
+++ b/vlc-android/src/org/videolan/vlc/Media.java
@@ -21,6 +21,7 @@
 package org.videolan.vlc;
 
 import java.util.HashSet;
+import java.util.Locale;
 
 import org.videolan.libvlc.LibVLC;
 import org.videolan.libvlc.LibVlcException;
@@ -235,8 +236,8 @@ public class Media implements Comparable<Media> {
      */
     @Override
     public int compareTo(Media another) {
-        return mTitle.toUpperCase().compareTo(
-                another.getTitle().toUpperCase());
+        return mTitle.toUpperCase(Locale.getDefault()).compareTo(
+                another.getTitle().toUpperCase(Locale.getDefault()));
     }
 
     public String getLocation() {
@@ -360,7 +361,7 @@ public class Media implements Comparable<Media> {
         if(mGenre == VLCApplication.getAppContext().getString(R.string.unknown_genre))
             return mGenre;
         else if( mGenre.length() > 1)/* Make genres case insensitive via normalisation */
-            return Character.toUpperCase(mGenre.charAt(0)) + mGenre.substring(1).toLowerCase();
+            return Character.toUpperCase(mGenre.charAt(0)) + mGenre.substring(1).toLowerCase(Locale.getDefault());
         else
             return mGenre;
     }
diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 0bcdef2..5e28455 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -28,6 +28,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Stack;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -379,10 +380,10 @@ public class MediaLibrary {
         public boolean accept(File f) {
             boolean accepted = false;
             if (!f.isHidden()) {
-                if (f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase())) {
+                if (f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH))) {
                     accepted = true;
                 } else {
-                    String fileName = f.getName().toLowerCase();
+                    String fileName = f.getName().toLowerCase(Locale.ENGLISH);
                     int dotIndex = fileName.lastIndexOf(".");
                     if (dotIndex != -1) {
                         String fileExt = fileName.substring(dotIndex);
diff --git a/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java b/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
index 33e4043..bf3aa36 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
@@ -24,6 +24,7 @@ import java.io.File;
 import java.io.FileFilter;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Locale;
 import java.util.Stack;
 
 import org.videolan.vlc.MediaDatabase;
@@ -273,7 +274,7 @@ public class BrowserActivity extends ListActivity {
 
         @Override
         public boolean accept(File f) {
-            return f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase());
+            return f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH));
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
index c7bae60..be81309 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
@@ -21,6 +21,7 @@
 package org.videolan.vlc.gui;
 
 import java.util.ArrayList;
+import java.util.Locale;
 
 import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.MediaDatabase;
@@ -118,10 +119,11 @@ public class SearchActivity extends ListActivity {
             if (type != Media.TYPE_ALL && type != item.getType())
                 continue;
             boolean add = true;
-            String name = item.getTitle().toLowerCase();
-            String MRL = item.getLocation().toLowerCase();
+            String name = item.getTitle().toLowerCase(Locale.getDefault());
+            String MRL = item.getLocation().toLowerCase(Locale.getDefault());
             for (int k = 0; k < keys.length; k++) {
-                if (!(name.contains(keys[k].toLowerCase()) || MRL.contains(keys[k].toLowerCase()))) {
+                String s = keys[k].toLowerCase(Locale.getDefault());
+                if (!(name.contains(s) || MRL.contains(s))) {
                     add = false;
                     break;
                 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 03ba310..299761c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -22,6 +22,7 @@ package org.videolan.vlc.gui.video;
 
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.Locale;
 
 import org.videolan.vlc.BitmapCache;
 import org.videolan.vlc.Media;
@@ -111,8 +112,8 @@ public class VideoListAdapter extends ArrayAdapter<Media>
         int compare = 0;
         switch (mSortBy) {
             case SORT_BY_TITLE:
-                compare = item1.getTitle().toUpperCase().compareTo(
-                        item2.getTitle().toUpperCase());
+                compare = item1.getTitle().toUpperCase(Locale.ENGLISH).compareTo(
+                        item2.getTitle().toUpperCase(Locale.ENGLISH));
                 break;
             case SORT_BY_LENGTH:
                 compare = ((Long) item1.getLength()).compareTo(item2.getLength());



More information about the Android mailing list