1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 21:45:32 +00:00

Move misc files back to components

This commit is contained in:
athile 2010-06-28 12:40:39 -07:00
parent 67f89f27a2
commit 97feee6cb6
17 changed files with 102 additions and 114 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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