Hi, I needed to check whether a path was absolute, and it looks like there is not public method for this. Looking at juce_File.cpp, I found out that this is already done in getChildFile, so what about putting it into a static public method? Here is the patch I propose:
Index: deps/juce/src/juce_core/io/files/juce_File.cpp
===================================================================
--- deps/juce/src/juce_core/io/files/juce_File.cpp (revision 1723)
+++ deps/juce/src/juce_core/io/files/juce_File.cpp (working copy)
@@ -233,6 +233,21 @@
#endif
}
+bool File::isAbsolutePath(const String& path)
+{
+ if (path.startsWithChar (T('/'))
+ || path.startsWithChar (T('\\'))
+#if JUCE_WIN32
+ || (path.isNotEmpty() && path[1] == T(':')))
+#else
+ || path.startsWithChar (T('~')))
+#endif
+ {
+ return true;
+ }
+ return false;
+}
+
bool File::operator== (const File& other) const throw()
{
// case-insensitive on Windows, but not on linux.
@@ -441,13 +456,7 @@
//==============================================================================
const File File::getChildFile (String relativePath) const throw()
{
- if (relativePath.startsWithChar (T('/'))
- || relativePath.startsWithChar (T('\\'))
-#if JUCE_WIN32
- || (relativePath.isNotEmpty() && ((const String&) relativePath)[1] == T(':')))
-#else
- || relativePath.startsWithChar (T('~')))
-#endif
+ if (File::isAbsolutePath(relativePath))
{
// the path is really absolute..
return File (relativePath);
Index: deps/juce/src/juce_core/io/files/juce_File.h
===================================================================
--- deps/juce/src/juce_core/io/files/juce_File.h (revision 1723)
+++ deps/juce/src/juce_core/io/files/juce_File.h (working copy)
@@ -834,6 +834,10 @@
*/
static bool areFileNamesCaseSensitive();
+ /** Indicates wheter the given path is absolute.
+ */
+ static bool isAbsolutePath(const String& path);
+
//==============================================================================
juce_UseDebuggingNewOperator