20 #define TB_ALL_TO_TERMINATION 2147483647
23 const char *
stristr(
const char *arg1,
const char *arg2);
31 TBStrC(
const char *str) : s(const_cast<char *>(str)) {}
33 inline int Length()
const {
return (
int)strlen(s); }
34 inline bool IsEmpty()
const {
return s[0] == 0; }
36 inline int Compare(
const char* str)
const {
return strcmp(s, str); }
37 inline bool Equals(
const char* str)
const {
return !strcmp(s, str); }
38 const char *CStr()
const {
return s; }
40 inline const char & operator[](
int n)
const { assert(n >= 0); assert(n <= Length());
return s[n]; }
41 explicit inline operator const char *()
const {
return s; }
42 bool operator ==(
const char *b)
const {
return strcmp(s, b) == 0; }
43 bool operator ==(
const TBStrC &b)
const {
return strcmp(s, b.s) == 0; }
44 bool operator !=(
const TBStrC &b)
const {
return strcmp(s, b.s) != 0; }
45 bool operator <(
const TBStrC &b)
const {
return strcmp(s, b.s) < 0; }
47 bool operator ==(
const std::string &b)
const {
return s == b; }
69 TBStr(
const char* str);
70 TBStr(
const char* str,
int len);
72 bool Set(
TBStr str) { *
this = str;
return true; }
73 bool SetFormatted(
const char* format, ...) TB_POST_FORMAT(2,3);
77 void Remove(
int ofs,
int len);
80 bool Insert(
int ofs,
const char *ins,
int ins_len = TB_ALL_TO_TERMINATION);
83 bool Append(
const char *ins,
int ins_len = TB_ALL_TO_TERMINATION) {
84 return Insert((
int)strlen(s), ins, ins_len);
89 return Insert((
int)strlen(s), (
const char *)str, str.Length());
93 char *
CStr()
const {
return s; }
96 double atof()
const { return ::atof(s); }
99 int atoi()
const { return ::atoi(s); }
102 long atol()
const { return ::atol(s); }
105 explicit inline operator char *()
const {
return s; }
108 inline operator std::string()
const {
return std::string(s); }
114 explicit operator bool()
const;
const char * stristr(const char *arg1, const char *arg2)
Some useful C-like functions that's missing in the standard.
Definition: tb_str.cpp:25
Simple string class that doesn't own or change the string pointer.
Definition: tb_str.h:26
bool Insert(int ofs, const char *ins, int ins_len=TB_ALL_TO_TERMINATION)
Insert a c-string to this TBStr at 'ofs'.
Definition: tb_str.cpp:156
double atof() const
Call atof() on the string.
Definition: tb_str.h:96
bool Append(const char *ins, int ins_len=TB_ALL_TO_TERMINATION)
Append a c-string to this TBStr.
Definition: tb_str.h:83
TBStr & operator=(TBStr str)
Assignment operator.
Definition: tb_str.h:117
TBStr is a simple string class.
Definition: tb_str.h:62
long atol() const
Call atol() on the string.
Definition: tb_str.h:102
TBValue holds value of a specific type.
Definition: tb_value.h:59
char * CStr() const
Get the c-string raw (char *)
Definition: tb_str.h:93
bool Append(const TBStr &str)
Append another TBStr to this string.
Definition: tb_str.h:88
int atoi() const
Call atoi() on the string.
Definition: tb_str.h:99
char & operator*()
Pointer dereference, returns a reference to the zeroth char of the string (or the terminator of an em...
Definition: tb_str.h:121