diff options
author | Henri Herscher <henri@oreka.org> | 2006-03-03 15:23:24 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2006-03-03 15:23:24 +0000 |
commit | 229c98b195b283b9a5dc798480fb12f78eee06cd (patch) | |
tree | d17b41ccec986f2e2ba0ba54f0c9eedca3cbd81c /orkbasecxx/Utils.cpp | |
parent | 5c71b9542c24ff132c2c67c6ffe4a6a5bc43746c (diff) |
Created Utils.cpp - Moved file utility functions from Utils.h to Utils.cpp - Created FileCanOpen()
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@191 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx/Utils.cpp')
-rw-r--r-- | orkbasecxx/Utils.cpp | 50 |
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; +} |