44 #ifndef CCXX_STRING_H_
45 #define CCXX_STRING_H_
47 #ifndef CCXX_MISSING_H_
51 #ifndef CCXX_STRCHAR_H_
55 #ifdef CCXX_NAMESPACES
105 char text[(
sizeof(
char *) + (
sizeof(
size_t) * 2) + 1)];
123 {
return content.ministring.big;};
133 const char *set(
const char *str,
size_t len = 0);
141 void set(
const String &str);
151 const char *set(
size_t size,
const char *format, ...);
160 void copy(
const String &str);
174 static char *getSpace(
size_t size);
183 size_t setSize(
size_t size);
190 void setLength(
size_t len);
202 virtual int compare(
const char *text,
size_t len = 0,
size_t index = 0)
const;
213 size_t search(
const char *text,
size_t clen = 0,
size_t offset = 0)
const;
244 String(std::string
string);
253 String(
const String &str,
size_t offset,
size_t len = npos);
262 String(
size_t size,
const char *format, ...);
271 String(
size_t count,
const char *str);
280 String(
size_t count,
const char fill =
' ');
294 const char *getIndex(
size_t index)
const;
301 char *getText(
void)
const;
308 long getValue(
long defvalue = 0l)
const;
315 bool getBool(
bool defbool =
false)
const;
322 const size_t getLength(
void)
const;
329 const size_t getSize(
void)
const;
336 bool isEmpty(
void)
const;
343 void resize(
size_t size);
355 char at(ssize_t offset)
const;
365 unsigned count(
const String &s,
size_t offset = 0)
const;
376 unsigned count(
const char *s,
size_t offset = 0,
size_t len = 0)
const;
385 String token(
const char *delim =
" \t\n\r",
size_t offset = 0);
395 size_t find(
const String &s,
size_t offset = 0,
unsigned instance = 1)
const;
404 size_t rfind(
const String &s,
size_t offset = 0)
const;
415 size_t find(
const char *s,
size_t offset = 0,
size_t len = 0,
unsigned count = 1)
const;
425 size_t rfind(
const char *s,
size_t offset = 0,
size_t len = 0)
const;
432 inline void trim(
const char *cs)
433 {setLength(
strtrim(cs, getText(), getLength()));};
440 inline void chop(
const char *cs)
441 {setLength(
strchop(cs, getText(), getLength()));};
448 void strip(
const char *cs);
463 void trim(
size_t count);
471 void erase(
size_t start,
size_t len = npos);
480 void insert(
size_t start,
const char *text,
size_t len = 0);
488 void insert(
size_t start,
const String &str);
499 void replace(
size_t start,
size_t len,
const char *text,
size_t count = 0);
509 void replace(
size_t start,
size_t len,
const String &
string);
520 inline size_t find(
unsigned instance,
const char *text,
size_t offset = 0,
size_t len = 0)
const
521 {
return find(text, offset, len, instance);};
531 inline size_t find(
unsigned instance,
const String &
string,
size_t offset = 0)
const
532 {
return find(
string, offset, instance);};
543 {
return String(*
this, start, len);};
552 inline const char *(
index)(
size_t ind)
const
553 {
return getIndex(ind);};
560 {resize(getLength() + 1);};
575 inline operator char *()
const
608 {
return strlen(getText());};
616 {
return getLength();};
638 void append(
const char *str,
size_t count = 0);
647 void append(
size_t size,
const char *format, ...);
657 void append(
const char *str,
size_t offset,
size_t count);
671 void append(
const String &str);
684 inline const char *operator =(
const char *str)
704 {append(str);
return *
this;};
710 {add(c);
return *
this;};
716 {append(str);
return *
this;};
722 {append(str.c_str());
return *
this;};
734 friend __EXPORT std::istream &getline(std::istream &is,
String &str,
char delim =
'\n',
size_t size = 0);
746 {
return getline(is, str);};
757 friend __EXPORT int strprintf(
String &str,
size_t size,
const char *format, ...);
760 bool operator<(
const String &str)
const;
761 bool operator<(
const char *str)
const;
762 bool operator>(
const String &str)
const;
763 bool operator>(
const char *str)
const;
764 bool operator<=(
const String &str)
const;
765 bool operator<=(
const char *str)
const;
766 bool operator>=(
const String &str)
const;
767 bool operator>=(
const char *str)
const;
768 bool operator==(
const String &str)
const;
769 bool operator==(
const char *str)
const;
770 bool operator!=(
const String &str)
const;
771 bool operator!=(
const char *str)
const;
778 inline String &operator+=(
int i)
779 {append(16,
"%d", i);
return *
this;};
781 inline String &operator+=(
unsigned int i)
782 {append(16,
"%u", i);
return *
this;};
784 inline String &operator+=(
long l)
785 {append(16,
"%l", l);
return *
this;};
787 inline String &operator+=(
unsigned long l)
788 {append(16,
"%ul", l);
return *
this;};
790 inline String &operator+=(
float f)
791 {append(32,
"%f", f);
return *
this;};
793 inline String &operator+=(
double d)
794 {append(32,
"%f", d);
return *
this;};
796 inline String &operator+=(
short s)
797 {append(8,
"%hd", s);
return *
this;};
799 inline String &operator+=(
unsigned short s)
800 {append(8,
"%hu", s);
return *
this;};
806 inline String &operator=(
int i)
807 {set(16,
"%d", i);
return *
this;};
809 inline String &operator=(
unsigned int i)
810 {set(16,
"%u", i);
return *
this;};
812 inline String &operator=(
long l)
813 {set(16,
"%l", l);
return *
this;};
815 inline String &operator=(
unsigned long l)
816 {set(16,
"%ul", l);
return *
this;};
818 inline String &operator=(
float f)
819 {set(32,
"%f", f);
return *
this;};
821 inline String &operator=(
double d)
822 {set(32,
"%f", d);
return *
this;};
824 inline String &operator=(
short s)
825 {set(8,
"%hd", s);
return *
this;};
827 inline String &operator=(
unsigned short s)
828 {set(8,
"%hu", s);
return *
this;};
832 {copy(original);
return *
this;};
837 bool operator*=(
const String &str)
const;
842 bool operator*=(
const char *str)
const;
887 void *
operator new(
size_t size) NEW_THROWS;
892 void operator delete(
void *obj);
895 #ifdef CCXX_NAMESPACES
String & operator+=(const std::string &str)
Append operator.
size_t size(void) const
Get actual length of string data.
const char *() index(size_t ind) const
Return an indexed string based on the index, such as from a find.
__EXPORT char * strip(const char *cs, char *str, size_t len=0)
void chop(size_t chars)
Chop n leading characters from a string.
String & operator=(const String &original)
__EXPORT char * rfind(const char *cs, char *str, size_t len=0)
__EXPORT size_t strtrim(const char *cs, char *str, size_t len=0)
String & operator+=(const String &str)
Append operator.
size_t length(void) const
Get length as if null terminated string.
substitute functions which may be missing in target platform libc.
void compact(void)
Reduce the size of the string allocation to the minimum needed based on the current effective length...
bool empty(void) const
Return true if string is empty.
__EXPORT char * find(const char *cs, char *str, size_t len=0)
This is a generic and portable string class.
String & operator+=(const char *str)
Append operator.
char * text(void) const
Alternate get text method.
Common and portable character string related functions.
__EXPORT std::ostream & operator<<(std::ostream &os, const IPV4Address &ia)
friend std::istream & operator>>(std::istream &is, String &str)
Stream input into our variable.
const char operator[](unsigned ind) const
Extract a character by array indexing.
bool isBig(void) const
Determine if string is allocated in local variable or an external reference.
char * c_str(void) const
Old ANSI C++ compatible string pointer extraction.
size_t find(unsigned instance, const char *text, size_t offset=0, size_t len=0) const
A more convenient version of find for nth occurences, by putting the instance first.
String substr(size_t start, size_t len) const
Return a new string that contains a specific substring of the current string.
static const unsigned slotcount
void trim(const char *cs)
Trim trailing characters from a string.
static const unsigned slotsize
void chop(const char *cs)
Chop leading characters from a string.
static const unsigned minsize
size_t find(unsigned instance, const String &string, size_t offset=0) const
A more convenient version of find for nth occurences, by putting the instance first.
size_t capacity(void) const
Get space allocated to hold current string.
static const unsigned slotlimit
The StringObject class is used to derive subclasses that use the String managed memory pool for all s...
__EXPORT size_t strchop(const char *cs, char *str, size_t len=0)
bool operator!(void) const
Logical test for string empty.
char * data(void) const
Alternate get text method.
static const unsigned pagesize
String & operator+=(char c)
Append operator.