2006-05-25 04:32:20 +00:00
|
|
|
/* $Id: substr.cc,v 1.11 2006/02/26 20:30:54 helly Exp $ */
|
2006-02-24 04:48:15 +00:00
|
|
|
#include <string.h>
|
2006-05-25 04:32:20 +00:00
|
|
|
#include <stdlib.h>
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "substr.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
#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);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
bool operator==(const SubStr &s1, const SubStr &s2)
|
|
|
|
{
|
|
|
|
return (bool) (s1.len == s2.len && memcmp(s1.str, s2.str, s1.len) == 0);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
Str::Str(const SubStr& s)
|
|
|
|
: SubStr(strndup(s.str, s.len), s.len)
|
|
|
|
{
|
|
|
|
;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
Str::Str(Str& s)
|
|
|
|
: SubStr(s.str, s.len)
|
|
|
|
{
|
|
|
|
s.str = NULL;
|
|
|
|
s.len = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
Str::Str()
|
|
|
|
: SubStr((char*) NULL, 0)
|
|
|
|
{
|
|
|
|
;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
Str::~Str()
|
|
|
|
{
|
|
|
|
if (str) {
|
|
|
|
free((void*)str);
|
|
|
|
}
|
|
|
|
str = (char*) - 1;
|
|
|
|
len = (uint) - 1;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2006-05-25 04:32:20 +00:00
|
|
|
|
|
|
|
} // end namespace re2c
|