Move misc files back to components

pull/7/head
athile 15 years ago
parent 67f89f27a2
commit 97feee6cb6

@ -0,0 +1,8 @@
#include "fileops.hpp"
#include <boost/filesystem.hpp>
bool isFile(const char *name)
{
boost::filesystem::path cfg_file_path(name);
return boost::filesystem::exists(cfg_file_path);
}

@ -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

@ -0,0 +1,59 @@
#include "stringops.hpp"
#include <string.h>
#include <libs/platform/strings.h>
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;
}

@ -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

@ -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

@ -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})

@ -1,11 +0,0 @@
#include "fileops.hpp"
#include <boost/filesystem.hpp>
namespace OMW { namespace Platform {
bool isFile(const char *name)
{
boost::filesystem::path cfg_file_path(name);
return boost::filesystem::exists(cfg_file_path);
}
}}

@ -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

@ -1,63 +0,0 @@
#include "stringops.hpp"
#include <string.h>
#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;
}
}}

@ -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
Loading…
Cancel
Save