diff --git a/components/misc/fileops.cpp b/components/misc/fileops.cpp new file mode 100644 index 0000000000..bb859836bf --- /dev/null +++ b/components/misc/fileops.cpp @@ -0,0 +1,8 @@ +#include "fileops.hpp" +#include + +bool isFile(const char *name) +{ + boost::filesystem::path cfg_file_path(name); + return boost::filesystem::exists(cfg_file_path); +} diff --git a/components/misc/fileops.hpp b/components/misc/fileops.hpp new file mode 100644 index 0000000000..6a5ad7c611 --- /dev/null +++ b/components/misc/fileops.hpp @@ -0,0 +1,7 @@ +#ifndef __FILEOPS_H_ +#define __FILEOPS_H_ + +/// Check if a given path is an existing file (not a directory) +bool isFile(const char *name); + +#endif diff --git a/libs/platform/slice_array.hpp b/components/misc/slice_array.hpp similarity index 100% rename from libs/platform/slice_array.hpp rename to components/misc/slice_array.hpp diff --git a/components/misc/stringops.cpp b/components/misc/stringops.cpp new file mode 100644 index 0000000000..f6b63372c2 --- /dev/null +++ b/components/misc/stringops.cpp @@ -0,0 +1,59 @@ +#include "stringops.hpp" + +#include +#include + +bool begins(const char* str1, const char* str2) +{ + while(*str2) + { + if(*str1 == 0 || *str1 != *str2) return false; + + str1++; + str2++; + } + return true; +} + +bool ends(const char* str1, const char* str2) +{ + int len1 = strlen(str1); + int len2 = strlen(str2); + + if(len1 < len2) return false; + + return strcmp(str2, str1+len1-len2) == 0; +} + +// True if the given chars match, case insensitive +static bool icmp(char a, char b) +{ + if(a >= 'A' && a <= 'Z') + a += 'a' - 'A'; + if(b >= 'A' && b <= 'Z') + b += 'a' - 'A'; + + return a == b; +} + +bool ibegins(const char* str1, const char* str2) +{ + while(*str2) + { + if(*str1 == 0 || !icmp(*str1,*str2)) return false; + + str1++; + str2++; + } + return true; +} + +bool iends(const char* str1, const char* str2) +{ + int len1 = strlen(str1); + int len2 = strlen(str2); + + if(len1 < len2) return false; + + return strcasecmp(str2, str1+len1-len2) == 0; +} diff --git a/components/misc/stringops.hpp b/components/misc/stringops.hpp new file mode 100644 index 0000000000..e76b8a87a2 --- /dev/null +++ b/components/misc/stringops.hpp @@ -0,0 +1,16 @@ +#ifndef __STRINGOPS_H +#define __STRINGOPS_H + +/// Returns true if str1 begins with substring str2 +bool begins(const char* str1, const char* str2); + +/// Returns true if str1 ends with substring str2 +bool ends(const char* str1, const char* str2); + +/// Case insensitive, returns true if str1 begins with substring str2 +bool ibegins(const char* str1, const char* str2); + +/// Case insensitive, returns true if str1 ends with substring str2 +bool iends(const char* str1, const char* str2); + +#endif diff --git a/libs/platform/tests/.gitignore b/components/misc/tests/.gitignore similarity index 100% rename from libs/platform/tests/.gitignore rename to components/misc/tests/.gitignore diff --git a/components/misc/tests/Makefile b/components/misc/tests/Makefile new file mode 100644 index 0000000000..dc1ded5ff1 --- /dev/null +++ b/components/misc/tests/Makefile @@ -0,0 +1,12 @@ +GCC=g++ + +all: strops_test slice_test + +slice_test: slice_test.cpp ../slice_array.hpp + $(GCC) $< -o $@ + +strops_test: strops_test.cpp ../stringops.hpp ../stringops.cpp + $(GCC) $< -o $@ ../stringops.cpp + +clean: + rm *_test diff --git a/libs/platform/tests/output/slice_test.out b/components/misc/tests/output/slice_test.out similarity index 100% rename from libs/platform/tests/output/slice_test.out rename to components/misc/tests/output/slice_test.out diff --git a/libs/platform/tests/output/strops_test.out b/components/misc/tests/output/strops_test.out similarity index 100% rename from libs/platform/tests/output/strops_test.out rename to components/misc/tests/output/strops_test.out diff --git a/libs/platform/tests/slice_test.cpp b/components/misc/tests/slice_test.cpp similarity index 100% rename from libs/platform/tests/slice_test.cpp rename to components/misc/tests/slice_test.cpp diff --git a/libs/platform/tests/strops_test.cpp b/components/misc/tests/strops_test.cpp similarity index 100% rename from libs/platform/tests/strops_test.cpp rename to components/misc/tests/strops_test.cpp diff --git a/libs/platform/tests/test.sh b/components/misc/tests/test.sh similarity index 100% rename from libs/platform/tests/test.sh rename to components/misc/tests/test.sh diff --git a/libs/platform/CMakeLists.txt b/libs/platform/CMakeLists.txt deleted file mode 100755 index 672f815b07..0000000000 --- a/libs/platform/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -project(Platform) - -set(SOURCES - fileops.cpp - fileops.hpp - slice_array.hpp - stdint.h - stringops.cpp - stringops.hpp - strings.h) -add_library(platform STATIC ${SOURCES}) \ No newline at end of file diff --git a/libs/platform/fileops.cpp b/libs/platform/fileops.cpp deleted file mode 100644 index 52609488ba..0000000000 --- a/libs/platform/fileops.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "fileops.hpp" -#include - -namespace OMW { namespace Platform { - - bool isFile(const char *name) - { - boost::filesystem::path cfg_file_path(name); - return boost::filesystem::exists(cfg_file_path); - } -}} diff --git a/libs/platform/fileops.hpp b/libs/platform/fileops.hpp deleted file mode 100644 index 65f4b2ac72..0000000000 --- a/libs/platform/fileops.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __FILEOPS_H_ -#define __FILEOPS_H_ - -namespace OMW { namespace Platform { - - /// Check if a given path is an existing file (not a directory) - bool isFile(const char *name); -}} - -#endif diff --git a/libs/platform/stringops.cpp b/libs/platform/stringops.cpp deleted file mode 100644 index 16010aef7d..0000000000 --- a/libs/platform/stringops.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "stringops.hpp" - -#include -#include "strings.h" - -namespace OMW { namespace Platform { - - bool begins(const char* str1, const char* str2) - { - while(*str2) - { - if(*str1 == 0 || *str1 != *str2) return false; - - str1++; - str2++; - } - return true; - } - - bool ends(const char* str1, const char* str2) - { - int len1 = strlen(str1); - int len2 = strlen(str2); - - if(len1 < len2) return false; - - return strcmp(str2, str1+len1-len2) == 0; - } - - // True if the given chars match, case insensitive - static bool icmp(char a, char b) - { - if(a >= 'A' && a <= 'Z') - a += 'a' - 'A'; - if(b >= 'A' && b <= 'Z') - b += 'a' - 'A'; - - return a == b; - } - - bool ibegins(const char* str1, const char* str2) - { - while(*str2) - { - if(*str1 == 0 || !icmp(*str1,*str2)) return false; - - str1++; - str2++; - } - return true; - } - - bool iends(const char* str1, const char* str2) - { - int len1 = strlen(str1); - int len2 = strlen(str2); - - if(len1 < len2) return false; - - return strcasecmp(str2, str1+len1-len2) == 0; - } - -}} diff --git a/libs/platform/stringops.hpp b/libs/platform/stringops.hpp deleted file mode 100644 index 8b53bd7e94..0000000000 --- a/libs/platform/stringops.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __STRINGOPS_H -#define __STRINGOPS_H - -namespace OMW { namespace Platform { - - /// Returns true if str1 begins with substring str2 - bool begins(const char* str1, const char* str2); - - /// Returns true if str1 ends with substring str2 - bool ends(const char* str1, const char* str2); - - /// Case insensitive, returns true if str1 begins with substring str2 - bool ibegins(const char* str1, const char* str2); - - /// Case insensitive, returns true if str1 ends with substring str2 - bool iends(const char* str1, const char* str2); -}} - -#endif