[Android] Get name from folder path with trailing '/'
Geoffrey Métais
git at videolan.org
Thu Apr 6 11:59:22 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 6 10:10:40 2017 +0200| [cffbc8dd31540c3364952cb9d7127ba958a73dec] | committer: Geoffrey Métais
Get name from folder path with trailing '/'
> https://code.videolan.org/videolan/vlc-android/commit/cffbc8dd31540c3364952cb9d7127ba958a73dec
---
vlc-android/src/org/videolan/vlc/util/FileUtils.java | 6 +++++-
vlc-android/test/org/videolan/vlc/util/StringsTest.java | 2 ++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index e00a8b1..fb4b7e4 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -70,7 +70,11 @@ public class FileUtils {
if (path == null)
return "";
int index = path.lastIndexOf('/');
- if (index> -1)
+ if (index == path.length()-1) {
+ path = path.substring(0, index);
+ index = path.lastIndexOf('/');
+ }
+ if (index > -1)
return path.substring(index+1);
else
return path;
diff --git a/vlc-android/test/org/videolan/vlc/util/StringsTest.java b/vlc-android/test/org/videolan/vlc/util/StringsTest.java
index 1d585ef..442ce31 100644
--- a/vlc-android/test/org/videolan/vlc/util/StringsTest.java
+++ b/vlc-android/test/org/videolan/vlc/util/StringsTest.java
@@ -12,6 +12,8 @@ public class StringsTest {
assertEquals("", FileUtils.getFileNameFromPath(null));
assertEquals("", FileUtils.getFileNameFromPath("/"));
assertEquals("file.txt", FileUtils.getFileNameFromPath(path));
+ path = "/home/folder/subfolder/";
+ assertEquals("subfolder", FileUtils.getFileNameFromPath(path));
}
//TextUtils mock is not ready :/
More information about the Android
mailing list