2008-01-26 04:33:34 +00:00
|
|
|
/* $Id: substr.h 530 2006-05-25 13:34:33Z helly $ */
|
2006-02-24 04:48:15 +00:00
|
|
|
#ifndef _substr_h
|
|
|
|
#define _substr_h
|
|
|
|
|
|
|
|
#include <iostream>
|
2006-05-25 04:32:20 +00:00
|
|
|
#include <string>
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "basics.h"
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
namespace re2c
|
|
|
|
{
|
|
|
|
|
|
|
|
class SubStr
|
|
|
|
{
|
2006-02-24 04:48:15 +00:00
|
|
|
public:
|
2006-05-25 04:32:20 +00:00
|
|
|
const char * str;
|
|
|
|
const char * const org;
|
|
|
|
uint len;
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
public:
|
2006-05-25 04:32:20 +00:00
|
|
|
friend bool operator==(const SubStr &, const SubStr &);
|
|
|
|
SubStr(const uchar*, uint);
|
|
|
|
SubStr(const char*, uint);
|
|
|
|
SubStr(const char*);
|
|
|
|
SubStr(const SubStr&);
|
|
|
|
virtual ~SubStr();
|
|
|
|
void out(std::ostream&) const;
|
|
|
|
std::string to_string() const;
|
|
|
|
uint ofs() const;
|
|
|
|
|
|
|
|
#ifdef PEDANTIC
|
|
|
|
protected:
|
|
|
|
SubStr& operator = (const SubStr& oth);
|
|
|
|
#endif
|
2006-02-24 04:48:15 +00:00
|
|
|
};
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
class Str: public SubStr
|
|
|
|
{
|
2006-02-24 04:48:15 +00:00
|
|
|
public:
|
2006-05-25 04:32:20 +00:00
|
|
|
Str(const SubStr&);
|
|
|
|
Str(Str&);
|
|
|
|
Str();
|
|
|
|
~Str();
|
2006-02-24 04:48:15 +00:00
|
|
|
};
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
inline std::ostream& operator<<(std::ostream& o, const SubStr &s)
|
|
|
|
{
|
|
|
|
s.out(o);
|
|
|
|
return o;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
inline std::ostream& operator<<(std::ostream& o, const SubStr* s)
|
|
|
|
{
|
|
|
|
return o << *s;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
inline SubStr::SubStr(const uchar *s, uint l)
|
|
|
|
: str((char*)s), org((char*)s), len(l)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
inline SubStr::SubStr(const char *s, uint l)
|
|
|
|
: str(s), org(s), len(l)
|
|
|
|
{ }
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-05-25 04:32:20 +00:00
|
|
|
inline SubStr::SubStr(const char *s)
|
|
|
|
: str(s), org(s), len(strlen(s))
|
|
|
|
{ }
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
inline SubStr::SubStr(const SubStr &s)
|
2006-05-25 04:32:20 +00:00
|
|
|
: str(s.str), org(s.str), len(s.len)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
inline SubStr::~SubStr()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
inline std::string SubStr::to_string() const
|
|
|
|
{
|
|
|
|
return std::string(str, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint SubStr::ofs() const
|
|
|
|
{
|
|
|
|
return str - org;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PEDANTIC
|
|
|
|
inline SubStr& SubStr::operator = (const SubStr& oth)
|
|
|
|
{
|
|
|
|
new(this) SubStr(oth);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // end namespace re2c
|
|
|
|
|
|
|
|
#ifndef HAVE_STRNDUP
|
|
|
|
|
|
|
|
char *strndup(const char *str, size_t len);
|
|
|
|
|
|
|
|
#endif
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
#endif
|