mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2024-12-04 16:24:16 +01:00
1d9949e1a0
--HG-- rename : core-1.4/CPlugin.cpp => core-legacy/CPlugin.cpp rename : core-1.4/CPlugin.h => core-legacy/CPlugin.h rename : core-1.4/CSmmAPI.cpp => core-legacy/CSmmAPI.cpp rename : core-1.4/CSmmAPI.h => core-legacy/CSmmAPI.h rename : core-1.4/IPluginManager.h => core-legacy/IPluginManager.h rename : core-1.4/ISmmAPI.h => core-legacy/ISmmAPI.h rename : core-1.4/ISmmPlugin.h => core-legacy/ISmmPlugin.h rename : core-1.4/Makefile => core-legacy/Makefile rename : core-1.4/concommands.cpp => core-legacy/concommands.cpp rename : core-1.4/concommands.h => core-legacy/concommands.h rename : core-1.4/convar_smm.h => core-legacy/convar_smm.h rename : core-1.4/msvc7/sourcemm.sln => core-legacy/msvc7/sourcemm.sln rename : core-1.4/msvc7/sourcemm.vcproj => core-legacy/msvc7/sourcemm.vcproj rename : core-1.4/msvc8/sourcemm.sln => core-legacy/msvc8/sourcemm.sln rename : core-1.4/msvc8/sourcemm.vcproj => core-legacy/msvc8/sourcemm.vcproj rename : core-1.4/msvc9/sourcemm.sln => core-legacy/msvc9/sourcemm.sln rename : core-1.4/msvc9/sourcemm.vcproj => core-legacy/msvc9/sourcemm.vcproj rename : core-1.4/oslink.cpp => core-legacy/oslink.cpp rename : core-1.4/oslink.h => core-legacy/oslink.h rename : core-1.4/sourcehook.cpp => core-legacy/sourcehook.cpp rename : core-1.4/sourcehook/FastDelegate.h => core-legacy/sourcehook/FastDelegate.h rename : core-1.4/sourcehook/generate/FastDelegate.h => core-legacy/sourcehook/generate/FastDelegate.h rename : core-1.4/sourcehook/generate/FastDelegate.hxx => core-legacy/sourcehook/generate/FastDelegate.hxx rename : core-1.4/sourcehook/generate/generate => core-legacy/sourcehook/generate/generate rename : core-1.4/sourcehook/generate/generate.bat => core-legacy/sourcehook/generate/generate.bat rename : core-1.4/sourcehook/generate/sh_memfuncinfo.h => core-legacy/sourcehook/generate/sh_memfuncinfo.h rename : core-1.4/sourcehook/generate/sh_memfuncinfo.hxx => core-legacy/sourcehook/generate/sh_memfuncinfo.hxx rename : core-1.4/sourcehook/generate/shworker.bin => core-legacy/sourcehook/generate/shworker.bin rename : core-1.4/sourcehook/generate/shworker.exe => core-legacy/sourcehook/generate/shworker.exe rename : core-1.4/sourcehook/generate/shworker/Makefile => core-legacy/sourcehook/generate/shworker/Makefile rename : core-1.4/sourcehook/generate/shworker/fd_hopter.cpp => core-legacy/sourcehook/generate/shworker/fd_hopter.cpp rename : core-1.4/sourcehook/generate/shworker/msvc7/shworker.vcproj => core-legacy/sourcehook/generate/shworker/msvc7/shworker.vcproj rename : core-1.4/sourcehook/generate/shworker/msvc8/shworker.vcproj => core-legacy/sourcehook/generate/shworker/msvc8/shworker.vcproj rename : core-1.4/sourcehook/generate/shworker/shworker.cpp => core-legacy/sourcehook/generate/shworker/shworker.cpp rename : core-1.4/sourcehook/generate/sourcehook.h => core-legacy/sourcehook/generate/sourcehook.h rename : core-1.4/sourcehook/generate/sourcehook.hxx => core-legacy/sourcehook/generate/sourcehook.hxx rename : core-1.4/sourcehook/sh_list.h => core-legacy/sourcehook/sh_list.h rename : core-1.4/sourcehook/sh_memfuncinfo.h => core-legacy/sourcehook/sh_memfuncinfo.h rename : core-1.4/sourcehook/sh_memory.h => core-legacy/sourcehook/sh_memory.h rename : core-1.4/sourcehook/sh_stack.h => core-legacy/sourcehook/sh_stack.h rename : core-1.4/sourcehook/sh_string.h => core-legacy/sourcehook/sh_string.h rename : core-1.4/sourcehook/sh_tinyhash.h => core-legacy/sourcehook/sh_tinyhash.h rename : core-1.4/sourcehook/sh_vector.h => core-legacy/sourcehook/sh_vector.h rename : core-1.4/sourcehook/sourcehook.cpp => core-legacy/sourcehook/sourcehook.cpp rename : core-1.4/sourcehook/sourcehook.h => core-legacy/sourcehook/sourcehook.h rename : core-1.4/sourcehook/sourcehook_impl.h => core-legacy/sourcehook/sourcehook_impl.h rename : core-1.4/sourcehook/test/Makefile => core-legacy/sourcehook/test/Makefile rename : core-1.4/sourcehook/test/main.cpp => core-legacy/sourcehook/test/main.cpp rename : core-1.4/sourcehook/test/msvc7/test.vcproj => core-legacy/sourcehook/test/msvc7/test.vcproj rename : core-1.4/sourcehook/test/msvc8/test.vcproj => core-legacy/sourcehook/test/msvc8/test.vcproj rename : core-1.4/sourcehook/test/sourcehook_test.h => core-legacy/sourcehook/test/sourcehook_test.h rename : core-1.4/sourcehook/test/test1.cpp => core-legacy/sourcehook/test/test1.cpp rename : core-1.4/sourcehook/test/test2.cpp => core-legacy/sourcehook/test/test2.cpp rename : core-1.4/sourcehook/test/test3.cpp => core-legacy/sourcehook/test/test3.cpp rename : core-1.4/sourcehook/test/test4.cpp => core-legacy/sourcehook/test/test4.cpp rename : core-1.4/sourcehook/test/testbail.cpp => core-legacy/sourcehook/test/testbail.cpp rename : core-1.4/sourcehook/test/testbail.h => core-legacy/sourcehook/test/testbail.h rename : core-1.4/sourcehook/test/testbail2.cpp => core-legacy/sourcehook/test/testbail2.cpp rename : core-1.4/sourcehook/test/testevents.h => core-legacy/sourcehook/test/testevents.h rename : core-1.4/sourcehook/test/testlist.cpp => core-legacy/sourcehook/test/testlist.cpp rename : core-1.4/sourcehook/test/testmanual.cpp => core-legacy/sourcehook/test/testmanual.cpp rename : core-1.4/sourcehook/test/testmulti.cpp => core-legacy/sourcehook/test/testmulti.cpp rename : core-1.4/sourcehook/test/testrecall.cpp => core-legacy/sourcehook/test/testrecall.cpp rename : core-1.4/sourcehook/test/testreentr.cpp => core-legacy/sourcehook/test/testreentr.cpp rename : core-1.4/sourcehook/test/testref.cpp => core-legacy/sourcehook/test/testref.cpp rename : core-1.4/sourcehook/test/testrefret.cpp => core-legacy/sourcehook/test/testrefret.cpp rename : core-1.4/sourcemm.cpp => core-legacy/sourcemm.cpp rename : core-1.4/sourcemm.h => core-legacy/sourcemm.h rename : core-1.4/svn_version.h => core-legacy/svn_version.h rename : core-1.4/svn_version.tpl => core-legacy/svn_version.tpl rename : core-1.4/util.cpp => core-legacy/util.cpp rename : core-1.4/util.h => core-legacy/util.h rename : core-1.4/version.rc => core-legacy/version.rc rename : core-1.4/vsp_listener.cpp => core-legacy/vsp_listener.cpp rename : core-1.4/vsp_listener.h => core-legacy/vsp_listener.h
402 lines
5.2 KiB
C++
Executable File
402 lines
5.2 KiB
C++
Executable File
/* ======== SourceMM ========
|
|
* Copyright (C) 2004-2008 Metamod:Source Development Team
|
|
* No warranties of any kind
|
|
*
|
|
* License: zlib/libpng
|
|
*
|
|
* Author(s): David "BAILOPAN" Anderson
|
|
* ============================
|
|
*/
|
|
|
|
/* AMX Mod X
|
|
*
|
|
* by the AMX Mod X Development Team
|
|
*/
|
|
|
|
#ifndef _INCLUDE_CSTRING_H
|
|
#define _INCLUDE_CSTRING_H
|
|
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
namespace SourceHook
|
|
{
|
|
class String
|
|
{
|
|
public:
|
|
String()
|
|
{
|
|
v = NULL;
|
|
a_size = 0;
|
|
//assign("");
|
|
}
|
|
|
|
~String()
|
|
{
|
|
if (v)
|
|
delete [] v;
|
|
}
|
|
|
|
String(const char *src)
|
|
{
|
|
v = NULL;
|
|
a_size = 0;
|
|
assign(src);
|
|
}
|
|
|
|
String(const String &src)
|
|
{
|
|
v = NULL;
|
|
a_size = 0;
|
|
assign(src.c_str());
|
|
}
|
|
|
|
bool operator ==(const String &other)
|
|
{
|
|
return (compare(other.c_str()) == 0);
|
|
}
|
|
|
|
bool operator ==(const char *other)
|
|
{
|
|
return (compare(other) == 0);
|
|
}
|
|
|
|
const char *c_str() { return v?v:""; }
|
|
|
|
const char *c_str() const { return v?v:""; }
|
|
|
|
void append(const char *t)
|
|
{
|
|
Grow(size() + strlen(t) + 1);
|
|
strcat(v, t);
|
|
}
|
|
|
|
void append(const char c)
|
|
{
|
|
size_t len = size();
|
|
Grow(len + 2);
|
|
v[len] = c;
|
|
v[len + 1] = '\0';
|
|
}
|
|
|
|
void append(String &d)
|
|
{
|
|
append(d.c_str());
|
|
}
|
|
|
|
void assign(const String &src)
|
|
{
|
|
assign(src.c_str());
|
|
}
|
|
|
|
void assign(const char *d)
|
|
{
|
|
if (!d)
|
|
{
|
|
clear();
|
|
} else {
|
|
Grow(strlen(d) + 1, false);
|
|
strcpy(v, d);
|
|
}
|
|
}
|
|
|
|
void clear()
|
|
{
|
|
if (v)
|
|
v[0] = '\0';
|
|
}
|
|
|
|
int compare (const char *d) const
|
|
{
|
|
if (!v)
|
|
return strcmp("", d);
|
|
else
|
|
return strcmp(v, d);
|
|
}
|
|
|
|
//Added this for amxx inclusion
|
|
bool empty() const
|
|
{
|
|
if (!v)
|
|
return true;
|
|
|
|
if (v[0] == '\0')
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
size_t size() const
|
|
{
|
|
if (v)
|
|
return strlen(v);
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
int find(const char c, int index = 0) const
|
|
{
|
|
int len = static_cast<int>(size());
|
|
if (len < 1)
|
|
return npos;
|
|
if (index >= len || index < 0)
|
|
return npos;
|
|
int i = 0;
|
|
for (i=index; i<len; i++)
|
|
{
|
|
if (v[i] == c)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return npos;
|
|
}
|
|
|
|
int find_last_of(const char c, int index = npos) const
|
|
{
|
|
int len = static_cast<int>(size());
|
|
if (len < 1)
|
|
return npos;
|
|
if (index >= len || index < npos)
|
|
return npos;
|
|
int i;
|
|
if (index == npos)
|
|
i = len - 1;
|
|
else
|
|
i = index;
|
|
|
|
for (; i>=0; i--)
|
|
{
|
|
if (v[i] == c)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return npos;
|
|
}
|
|
|
|
bool is_space(int c) const
|
|
{
|
|
if (c == '\f' || c == '\n' ||
|
|
c == '\t' || c == '\r' ||
|
|
c == '\v' || c == ' ')
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void trim()
|
|
{
|
|
if (!v)
|
|
return;
|
|
|
|
unsigned int i = 0;
|
|
unsigned int j = 0;
|
|
size_t len = strlen(v);
|
|
|
|
if (len == 1)
|
|
{
|
|
if (is_space(v[i]))
|
|
{
|
|
clear();
|
|
return;
|
|
}
|
|
}
|
|
|
|
unsigned char c0 = v[0];
|
|
|
|
if (is_space(c0))
|
|
{
|
|
for (i=0; i<len; i++)
|
|
{
|
|
if (!is_space(v[i]) || (is_space(v[i]) && ((unsigned char)i==len-1)))
|
|
{
|
|
erase(0, i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
len = strlen(v);
|
|
|
|
if (len < 1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (is_space(v[len-1]))
|
|
{
|
|
for (i=len-1; i>=0; i--)
|
|
{
|
|
if (!is_space(v[i])
|
|
|| (is_space(v[i]) && i==0))
|
|
{
|
|
erase(i+1, j);
|
|
break;
|
|
}
|
|
j++;
|
|
}
|
|
}
|
|
|
|
if (len == 1)
|
|
{
|
|
if (is_space(v[0]))
|
|
{
|
|
clear();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void erase(unsigned int start, int num = npos)
|
|
{
|
|
if (!v)
|
|
return;
|
|
unsigned int i = 0;
|
|
size_t len = size();
|
|
//check for bounds
|
|
if (num == npos || start+num > len-start)
|
|
num = len - start;
|
|
//do the erasing
|
|
bool copyflag = false;
|
|
for (i=0; i<len; i++)
|
|
{
|
|
if (i>=start && i<start+num)
|
|
{
|
|
if (i+num < len)
|
|
{
|
|
v[i] = v[i+num];
|
|
} else {
|
|
v[i] = 0;
|
|
}
|
|
copyflag = true;
|
|
} else if (copyflag) {
|
|
if (i+num < len)
|
|
{
|
|
v[i] = v[i+num];
|
|
} else {
|
|
v[i] = 0;
|
|
}
|
|
}
|
|
}
|
|
len -= num;
|
|
v[len] = 0;
|
|
}
|
|
|
|
String substr(unsigned int index, int num = npos) const
|
|
{
|
|
if (!v)
|
|
{
|
|
String b("");
|
|
return b;
|
|
}
|
|
|
|
String ns;
|
|
|
|
size_t len = size();
|
|
|
|
if (index >= len || !v)
|
|
return ns;
|
|
|
|
if (num == npos)
|
|
{
|
|
num = len - index;
|
|
} else if (index+num >= len) {
|
|
num = len - index;
|
|
}
|
|
|
|
unsigned int i = 0;
|
|
unsigned int nslen = num + 2;
|
|
|
|
ns.Grow(nslen);
|
|
|
|
for (i=index; i<index+num; i++)
|
|
ns.append(v[i]);
|
|
|
|
return ns;
|
|
}
|
|
|
|
void toLower()
|
|
{
|
|
if (!v)
|
|
return;
|
|
unsigned int i = 0;
|
|
size_t len = strlen(v);
|
|
for (i=0; i<len; i++)
|
|
{
|
|
if (v[i] >= 65 && v[i] <= 90)
|
|
v[i] &= ~(1<<5);
|
|
}
|
|
}
|
|
|
|
String & operator = (const String &src)
|
|
{
|
|
assign(src);
|
|
return *this;
|
|
}
|
|
|
|
String & operator = (const char *src)
|
|
{
|
|
assign(src);
|
|
return *this;
|
|
|
|
}
|
|
|
|
char operator [] (unsigned int index) const
|
|
{
|
|
if (index > size() || !v)
|
|
{
|
|
return -1;
|
|
} else {
|
|
return v[index];
|
|
}
|
|
}
|
|
|
|
int at(int a) const
|
|
{
|
|
if (a < 0 || a >= (int)size() || !v)
|
|
return -1;
|
|
|
|
return v[a];
|
|
}
|
|
|
|
bool at(int at, char c)
|
|
{
|
|
if (at < 0 || at >= (int)size() || !v)
|
|
return false;
|
|
|
|
v[at] = c;
|
|
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
void Grow(unsigned int d, bool copy=true)
|
|
{
|
|
if (d <= a_size)
|
|
return;
|
|
char *n = new char[d + 1];
|
|
if (copy && v)
|
|
strcpy(n, v);
|
|
if (v)
|
|
delete [] v;
|
|
else
|
|
strcpy(n, "");
|
|
v = n;
|
|
a_size = d + 1;
|
|
}
|
|
|
|
char *v;
|
|
unsigned int a_size;
|
|
public:
|
|
static const int npos = -1;
|
|
};
|
|
|
|
}; //NAMESPACE
|
|
|
|
#endif //_INCLUDE_CSTRING_H
|