aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Kernel/OVR_String_PathUtil.cpp
diff options
context:
space:
mode:
authorBrad Davis <[email protected]>2013-07-03 09:16:03 -0700
committerBrad Davis <[email protected]>2013-07-03 09:16:03 -0700
commitd46694c91c2bec4eb1e282c0c0101e6dab26e082 (patch)
treeeb5fba71edf1aedc0d6af9406881004289433b20 /LibOVR/Src/Kernel/OVR_String_PathUtil.cpp
parent7fa8be4bc565adc9911c95c814480cc48bf2d13c (diff)
SDK 0.2.3
Diffstat (limited to 'LibOVR/Src/Kernel/OVR_String_PathUtil.cpp')
-rw-r--r--LibOVR/Src/Kernel/OVR_String_PathUtil.cpp400
1 files changed, 200 insertions, 200 deletions
diff --git a/LibOVR/Src/Kernel/OVR_String_PathUtil.cpp b/LibOVR/Src/Kernel/OVR_String_PathUtil.cpp
index 27e79c6..698d16e 100644
--- a/LibOVR/Src/Kernel/OVR_String_PathUtil.cpp
+++ b/LibOVR/Src/Kernel/OVR_String_PathUtil.cpp
@@ -1,200 +1,200 @@
-/************************************************************************************
-
-Filename : OVR_String_PathUtil.cpp
-Content : String filename/url helper function
-Created : September 19, 2012
-Notes :
-
-Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
-
-Use of this software is subject to the terms of the Oculus license
-agreement provided at the time of installation or download, or which
-otherwise accompanies this software in either electronic or hard copy form.
-
-************************************************************************************/
-
-#include "OVR_String.h"
-#include "OVR_UTF8Util.h"
-
-namespace OVR {
-
-//--------------------------------------------------------------------
-// ***** Path-Scanner helper function
-
-// Scans file path finding filename start and extension start, fills in their addess.
-void ScanFilePath(const char* url, const char** pfilename, const char** pext)
-{
- const char* urlStart = url;
- const char *filename = 0;
- const char *lastDot = 0;
-
- UInt32 charVal = UTF8Util::DecodeNextChar(&url);
-
- while (charVal != 0)
- {
- if ((charVal == '/') || (charVal == '\\'))
- {
- filename = url;
- lastDot = 0;
- }
- else if (charVal == '.')
- {
- lastDot = url - 1;
- }
-
- charVal = UTF8Util::DecodeNextChar(&url);
- }
-
- if (pfilename)
- {
- // It was a naked filename
- if (urlStart && (*urlStart != '.') && *urlStart)
- *pfilename = urlStart;
- else
- *pfilename = filename;
- }
-
- if (pext)
- {
- *pext = lastDot;
- }
-}
-
-// Scans till the end of protocol. Returns first character past protocol,
-// 0 if not found.
-// - protocol: 'file://', 'http://'
-const char* ScanPathProtocol(const char* url)
-{
- UInt32 charVal = UTF8Util::DecodeNextChar(&url);
- UInt32 charVal2;
-
- while (charVal != 0)
- {
- // Treat a colon followed by a slash as absolute.
- if (charVal == ':')
- {
- charVal2 = UTF8Util::DecodeNextChar(&url);
- charVal = UTF8Util::DecodeNextChar(&url);
- if ((charVal == '/') && (charVal2 == '\\'))
- return url;
- }
- charVal = UTF8Util::DecodeNextChar(&url);
- }
- return 0;
-}
-
-
-//--------------------------------------------------------------------
-// ***** String Path API implementation
-
-bool String::HasAbsolutePath(const char* url)
-{
- // Absolute paths can star with:
- // - protocols: 'file://', 'http://'
- // - windows drive: 'c:\'
- // - UNC share name: '\\share'
- // - unix root '/'
-
- // On the other hand, relative paths are:
- // - directory: 'directory/file'
- // - this directory: './file'
- // - parent directory: '../file'
- //
- // For now, we don't parse '.' or '..' out, but instead let it be concatenated
- // to string and let the OS figure it out. This, however, is not good for file
- // name matching in library/etc, so it should be improved.
-
- if (!url || !*url)
- return true; // Treat empty strings as absolute.
-
- UInt32 charVal = UTF8Util::DecodeNextChar(&url);
-
- // Fist character of '/' or '\\' means absolute url.
- if ((charVal == '/') || (charVal == '\\'))
- return true;
-
- while (charVal != 0)
- {
- // Treat a colon followed by a slash as absolute.
- if (charVal == ':')
- {
- charVal = UTF8Util::DecodeNextChar(&url);
- // Protocol or windows drive. Absolute.
- if ((charVal == '/') || (charVal == '\\'))
- return true;
- }
- else if ((charVal == '/') || (charVal == '\\'))
- {
- // Not a first character (else 'if' above the loop would have caught it).
- // Must be a relative url.
- break;
- }
-
- charVal = UTF8Util::DecodeNextChar(&url);
- }
-
- // We get here for relative paths.
- return false;
-}
-
-
-bool String::HasExtension(const char* path)
-{
- const char* ext = 0;
- ScanFilePath(path, 0, &ext);
- return ext != 0;
-}
-bool String::HasProtocol(const char* path)
-{
- return ScanPathProtocol(path) != 0;
-}
-
-
-String String::GetPath() const
-{
- const char* filename = 0;
- ScanFilePath(ToCStr(), &filename, 0);
-
- // Technically we can have extra logic somewhere for paths,
- // such as enforcing protocol and '/' only based on flags,
- // but we keep it simple for now.
- return String(ToCStr(), filename ? (filename-ToCStr()) : GetSize());
-}
-
-String String::GetProtocol() const
-{
- const char* protocolEnd = ScanPathProtocol(ToCStr());
- return String(ToCStr(), protocolEnd ? (protocolEnd-ToCStr()) : 0);
-}
-
-String String::GetFilename() const
-{
- const char* filename = 0;
- ScanFilePath(ToCStr(), &filename, 0);
- return String(filename);
-}
-String String::GetExtension() const
-{
- const char* ext = 0;
- ScanFilePath(ToCStr(), 0, &ext);
- return String(ext);
-}
-
-void String::StripExtension()
-{
- const char* ext = 0;
- ScanFilePath(ToCStr(), 0, &ext);
- if (ext)
- {
- *this = String(ToCStr(), ext-ToCStr());
- }
-}
-
-void String::StripProtocol()
-{
- const char* protocol = ScanPathProtocol(ToCStr());
- if (protocol)
- AssignString(protocol, OVR_strlen(protocol));
-}
-
-} // OVR
+/************************************************************************************
+
+Filename : OVR_String_PathUtil.cpp
+Content : String filename/url helper function
+Created : September 19, 2012
+Notes :
+
+Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
+
+Use of this software is subject to the terms of the Oculus license
+agreement provided at the time of installation or download, or which
+otherwise accompanies this software in either electronic or hard copy form.
+
+************************************************************************************/
+
+#include "OVR_String.h"
+#include "OVR_UTF8Util.h"
+
+namespace OVR {
+
+//--------------------------------------------------------------------
+// ***** Path-Scanner helper function
+
+// Scans file path finding filename start and extension start, fills in their addess.
+void ScanFilePath(const char* url, const char** pfilename, const char** pext)
+{
+ const char* urlStart = url;
+ const char *filename = 0;
+ const char *lastDot = 0;
+
+ UInt32 charVal = UTF8Util::DecodeNextChar(&url);
+
+ while (charVal != 0)
+ {
+ if ((charVal == '/') || (charVal == '\\'))
+ {
+ filename = url;
+ lastDot = 0;
+ }
+ else if (charVal == '.')
+ {
+ lastDot = url - 1;
+ }
+
+ charVal = UTF8Util::DecodeNextChar(&url);
+ }
+
+ if (pfilename)
+ {
+ // It was a naked filename
+ if (urlStart && (*urlStart != '.') && *urlStart)
+ *pfilename = urlStart;
+ else
+ *pfilename = filename;
+ }
+
+ if (pext)
+ {
+ *pext = lastDot;
+ }
+}
+
+// Scans till the end of protocol. Returns first character past protocol,
+// 0 if not found.
+// - protocol: 'file://', 'http://'
+const char* ScanPathProtocol(const char* url)
+{
+ UInt32 charVal = UTF8Util::DecodeNextChar(&url);
+ UInt32 charVal2;
+
+ while (charVal != 0)
+ {
+ // Treat a colon followed by a slash as absolute.
+ if (charVal == ':')
+ {
+ charVal2 = UTF8Util::DecodeNextChar(&url);
+ charVal = UTF8Util::DecodeNextChar(&url);
+ if ((charVal == '/') && (charVal2 == '\\'))
+ return url;
+ }
+ charVal = UTF8Util::DecodeNextChar(&url);
+ }
+ return 0;
+}
+
+
+//--------------------------------------------------------------------
+// ***** String Path API implementation
+
+bool String::HasAbsolutePath(const char* url)
+{
+ // Absolute paths can star with:
+ // - protocols: 'file://', 'http://'
+ // - windows drive: 'c:\'
+ // - UNC share name: '\\share'
+ // - unix root '/'
+
+ // On the other hand, relative paths are:
+ // - directory: 'directory/file'
+ // - this directory: './file'
+ // - parent directory: '../file'
+ //
+ // For now, we don't parse '.' or '..' out, but instead let it be concatenated
+ // to string and let the OS figure it out. This, however, is not good for file
+ // name matching in library/etc, so it should be improved.
+
+ if (!url || !*url)
+ return true; // Treat empty strings as absolute.
+
+ UInt32 charVal = UTF8Util::DecodeNextChar(&url);
+
+ // Fist character of '/' or '\\' means absolute url.
+ if ((charVal == '/') || (charVal == '\\'))
+ return true;
+
+ while (charVal != 0)
+ {
+ // Treat a colon followed by a slash as absolute.
+ if (charVal == ':')
+ {
+ charVal = UTF8Util::DecodeNextChar(&url);
+ // Protocol or windows drive. Absolute.
+ if ((charVal == '/') || (charVal == '\\'))
+ return true;
+ }
+ else if ((charVal == '/') || (charVal == '\\'))
+ {
+ // Not a first character (else 'if' above the loop would have caught it).
+ // Must be a relative url.
+ break;
+ }
+
+ charVal = UTF8Util::DecodeNextChar(&url);
+ }
+
+ // We get here for relative paths.
+ return false;
+}
+
+
+bool String::HasExtension(const char* path)
+{
+ const char* ext = 0;
+ ScanFilePath(path, 0, &ext);
+ return ext != 0;
+}
+bool String::HasProtocol(const char* path)
+{
+ return ScanPathProtocol(path) != 0;
+}
+
+
+String String::GetPath() const
+{
+ const char* filename = 0;
+ ScanFilePath(ToCStr(), &filename, 0);
+
+ // Technically we can have extra logic somewhere for paths,
+ // such as enforcing protocol and '/' only based on flags,
+ // but we keep it simple for now.
+ return String(ToCStr(), filename ? (filename-ToCStr()) : GetSize());
+}
+
+String String::GetProtocol() const
+{
+ const char* protocolEnd = ScanPathProtocol(ToCStr());
+ return String(ToCStr(), protocolEnd ? (protocolEnd-ToCStr()) : 0);
+}
+
+String String::GetFilename() const
+{
+ const char* filename = 0;
+ ScanFilePath(ToCStr(), &filename, 0);
+ return String(filename);
+}
+String String::GetExtension() const
+{
+ const char* ext = 0;
+ ScanFilePath(ToCStr(), 0, &ext);
+ return String(ext);
+}
+
+void String::StripExtension()
+{
+ const char* ext = 0;
+ ScanFilePath(ToCStr(), 0, &ext);
+ if (ext)
+ {
+ *this = String(ToCStr(), ext-ToCStr());
+ }
+}
+
+void String::StripProtocol()
+{
+ const char* protocol = ScanPathProtocol(ToCStr());
+ if (protocol)
+ AssignString(protocol, OVR_strlen(protocol));
+}
+
+} // OVR