summaryrefslogtreecommitdiff
path: root/orkbasecxx/Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'orkbasecxx/Utils.cpp')
-rw-r--r--orkbasecxx/Utils.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/orkbasecxx/Utils.cpp b/orkbasecxx/Utils.cpp
new file mode 100644
index 0000000..c1ba665
--- /dev/null
+++ b/orkbasecxx/Utils.cpp
@@ -0,0 +1,50 @@
+#include "Utils.h"
+#include "ace/OS_NS_stdio.h"
+
+//========================================================
+// file related stuff
+
+CStdString FileBaseName(CStdString& path)
+{
+ CStdString result;
+ int lastSeparatorPosition = path.ReverseFind('/');
+ if(lastSeparatorPosition == -1)
+ {
+ lastSeparatorPosition = path.ReverseFind('\\');
+ }
+ if(lastSeparatorPosition != -1 && path.GetLength()>3)
+ {
+ result = path.Right(path.GetLength() - lastSeparatorPosition - 1);
+ }
+ else
+ {
+ result = path;
+ }
+ return result;
+}
+
+CStdString FileStripExtension(CStdString& filename)
+{
+ CStdString result;
+ int extensionPosition = filename.ReverseFind('.');
+ if (extensionPosition != -1)
+ {
+ result = filename.Left(extensionPosition);
+ }
+ else
+ {
+ result = filename;
+ }
+ return result;
+}
+
+bool FileCanOpen(CStdString& path)
+{
+ FILE* file = ACE_OS::fopen((PCSTR)path, "r");
+ if(file)
+ {
+ ACE_OS::fclose(file);
+ return true;
+ }
+ return false;
+}