mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-14 16:40:56 +00:00
43abfba723
re2c instead of "Linking X". - Updated lemon and re2c to the latest versions and ported dehsupp to use them for code generation. (Xlatcc is next.) - Added function level linking for Makefile.mingw. SVN r144 (trunk)
62 lines
838 B
C++
62 lines
838 B
C++
/* $Id: substr.cc,v 1.11 2006/02/26 20:30:54 helly Exp $ */
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include "substr.h"
|
|
#include "globals.h"
|
|
|
|
#ifndef HAVE_STRNDUP
|
|
|
|
char *strndup(const char *str, size_t len)
|
|
{
|
|
char * ret = (char*)malloc(len + 1);
|
|
|
|
memcpy(ret, str, len);
|
|
ret[len] = '\0';
|
|
return ret;
|
|
}
|
|
|
|
#endif
|
|
|
|
namespace re2c
|
|
{
|
|
|
|
void SubStr::out(std::ostream& o) const
|
|
{
|
|
o.write(str, len);
|
|
}
|
|
|
|
bool operator==(const SubStr &s1, const SubStr &s2)
|
|
{
|
|
return (bool) (s1.len == s2.len && memcmp(s1.str, s2.str, s1.len) == 0);
|
|
}
|
|
|
|
Str::Str(const SubStr& s)
|
|
: SubStr(strndup(s.str, s.len), s.len)
|
|
{
|
|
;
|
|
}
|
|
|
|
Str::Str(Str& s)
|
|
: SubStr(s.str, s.len)
|
|
{
|
|
s.str = NULL;
|
|
s.len = 0;
|
|
}
|
|
|
|
Str::Str()
|
|
: SubStr((char*) NULL, 0)
|
|
{
|
|
;
|
|
}
|
|
|
|
|
|
Str::~Str()
|
|
{
|
|
if (str) {
|
|
free((void*)str);
|
|
}
|
|
str = (char*) - 1;
|
|
len = (uint) - 1;
|
|
}
|
|
|
|
} // end namespace re2c
|