1 #include "../include/string.hpp"
2 #include "../include/util.hpp"
3 #if !defined CSDBG_WITH_PLUGIN && !defined CSDBG_WITH_HIGHLIGHT
4 #include "../include/exception.hpp"
29 return (keep) ? *
this :
clear();
89 va_copy(cpargs, args);
114 std::ostream&
operator<<(std::ostream &lval,
const string &rval)
116 return lval << rval.
m_data;
492 i32 flags = REG_EXTENDED | REG_NOSUB;
498 i32 retval = regcomp(®exp, exp.
cstr(), flags);
499 if (
likely(retval == 0) ) {
500 retval = regexec(®exp,
m_data, 0, NULL, 0);
506 i32 len = regerror(retval, ®exp, NULL, 0);
508 regerror(retval, ®exp, errbuf, len);
512 "failed to compile regexp '%s' (regex errno %d - %s)",
520 #if defined CSDBG_WITH_PLUGIN || defined CSDBG_WITH_HIGHLIGHT
531 if (
likely(which <= 0) ) {
549 if (
likely(which >= 0) ) {
587 while (
likely(tail-- >= 0) )
653 i32 flags = REG_EXTENDED;
657 i32 retval = regcomp(®exp, exp.
cstr(), flags);
659 i32 len = regerror(retval, ®exp, NULL, 0);
661 regerror(retval, ®exp, errbuf, len);
664 "failed to compile regexp '%s' (regex errno %d - %s)",
675 bool found = !regexec(®exp,
m_data + offset, 1, &match, 0);
685 i32 bgn = match.rm_so;
686 i32 end = match.rm_eo;
688 throw exception(
"logic error in regular expression '%s'", exp.
cstr());
695 word =
new string(
"%.*s", end - bgn,
m_data + offset + bgn);
711 else if (
likely(offset <= len) ) {
virtual string & trim(i32=0)
Remove leading and/or trailing whitespace characters.
virtual string & append(const string &)
Append a string.
virtual string * clone() const
Object virtual copy constructor.
virtual string & set(const i8 *,...)
Fill with a printf-style format C-string expanded with the values of a variable argument list...
virtual u32 available() const
Get the available buffer size, the number of characters that can be appended without reallocation...
virtual u32 bufsize() const
Get the buffer size.
virtual string & operator+=(const string &)
Compound addition-assignment operator (append)
virtual string & format(const i8 *, va_list)
Fill with a printf-style format C-string expanded with the values of a variable argument list...
static void * memset(void *, u8, u32)
Fill a memory block with a constant byte.
char i8
8-bit signed integer
std::ostream & operator<<(std::ostream &, const std::exception &)
Stream insertion operator for std::exception objects.
virtual ~string()
Object destructor.
static const u16 g_memblock_sz
Block size (allocation alignment)
virtual string & operator=(const string &)
Assignment operator.
virtual string & insert(u32, const string &)
Insert a string at a specified position.
string(u32=0)
Object constructor.
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
virtual string & memalign(u32, bool=false)
Allocate aligned memory, mandate a minimum buffer size.
virtual i8 & operator[](u32)
Subscript operator.
unsigned char u8
8-bit unsigned integer
virtual string & clear()
Clear contents.
virtual i32 cmp(const string &, bool=false) const
Compare to another string.
virtual i8 & at(u32)
Get/set the character at an offset.
virtual const i8 * cstr() const
Get the C-string equivalent.
virtual chain & add(T *)
Add a node to the chain.
virtual bool match(const string &, bool=false) const
Match against a POSIX extended regular expression.
static i8 * va_format(const i8 *, va_list)
Format a buffer with a printf-style string expanded with the values of a variable argument list...
unsigned int u32
32-bit unsigned integer
int i32
32-bit signed integer
virtual u32 length() const
Get the character count.
virtual string & shred(u8=0)
Fill the whole buffer with a constant byte.
This class is a throwable with a textual description of an error.
virtual chain< string > * split(const string &, bool=true, bool=false) const
Tokenize using a POSIX extended regular expression.
static i32 va_size(const i8 *, va_list)
Compute the size of a printf-style format string expanded with the values of a variable argument list...
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
u32 m_length
Character count.
#define __D_ASSERT(x)
Assertion macro.