[Android] getParent util method for path string
Geoffrey Métais
git at videolan.org
Tue May 12 14:40:50 CEST 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 11 14:54:35 2015 +0200| [be75a2f12c2c5fd90a9afaf6f8b3523d0543d9c9] | committer: Geoffrey Métais
getParent util method for path string
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=be75a2f12c2c5fd90a9afaf6f8b3523d0543d9c9
---
vlc-android/src/org/videolan/vlc/util/Strings.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/vlc-android/src/org/videolan/vlc/util/Strings.java b/vlc-android/src/org/videolan/vlc/util/Strings.java
index ccee272..dfaa1f1 100644
--- a/vlc-android/src/org/videolan/vlc/util/Strings.java
+++ b/vlc-android/src/org/videolan/vlc/util/Strings.java
@@ -20,6 +20,8 @@
package org.videolan.vlc.util;
+import android.text.TextUtils;
+
import org.videolan.vlc.MediaWrapper;
import java.text.DecimalFormat;
@@ -138,4 +140,18 @@ public class Strings {
title = getName(mediaWrapper.getLocation());
return title;
}
+
+ public static String getParent(String path){
+ if (TextUtils.equals("/", path))
+ return path;
+ String parentPath = path;
+ if (parentPath.endsWith("/"))
+ parentPath = parentPath.substring(0, parentPath.length()-1);
+ int index = parentPath.lastIndexOf('/');
+ if (index > 0){
+ parentPath = parentPath.substring(0, index);
+ } else if (index == 0)
+ parentPath = "/";
+ return parentPath;
+ }
}
More information about the Android
mailing list