Go to the documentation of this file.
44 #ifndef CCXX_STRING_H_
45 #define CCXX_STRING_H_
47 #ifndef CCXX_MISSING_H_
51 #ifndef CCXX_STRCHAR_H_
55 #ifdef CCXX_NAMESPACES
108 char text[(
sizeof(
char *) + (
sizeof(
size_t) * 2) + 1)];
126 {
return content.ministring.big;};
136 const char *
set(
const char *str,
size_t len = 0);
154 const char *
set(
size_t size,
const char *format, ...);
205 virtual int compare(
const char *text,
size_t len = 0,
size_t index = 0)
const;
216 size_t search(
const char *text,
size_t clen = 0,
size_t offset = 0)
const;
265 String(
size_t size,
const char *format, ...);
274 String(
size_t count,
const char *str);
283 String(
size_t count,
const char fill =
' ');
358 char at(ssize_t offset)
const;
379 unsigned count(
const char *s,
size_t offset = 0,
size_t len = 0)
const;
398 size_t find(
const String &s,
size_t offset = 0,
unsigned instance = 1)
const;
418 size_t find(
const char *s,
size_t offset = 0,
size_t len = 0,
unsigned count = 1)
const;
428 size_t rfind(
const char *s,
size_t offset = 0,
size_t len = 0)
const;
435 inline void trim(
const char *cs)
436 {setLength(
strtrim(cs, getText(), getLength()));};
443 inline void chop(
const char *cs)
444 {setLength(
strchop(cs, getText(), getLength()));};
474 void erase(
size_t start,
size_t len = npos);
483 void insert(
size_t start,
const char *text,
size_t len = 0);
502 void replace(
size_t start,
size_t len,
const char *text,
size_t count = 0);
523 inline size_t find(
unsigned instance,
const char *text,
size_t offset = 0,
size_t len = 0)
const
524 {
return find(text, offset, len, instance);};
534 inline size_t find(
unsigned instance,
const String &
string,
size_t offset = 0)
const
535 {
return find(
string, offset, instance);};
546 {
return String(*
this, start, len);};
555 inline const char *(
index)(
size_t ind)
const
556 {
return getIndex(ind);};
563 {resize(getLength() + 1);};
578 inline operator char *()
const
611 {
return strlen(getText());};
619 {
return getLength();};
641 void append(
const char *str,
size_t count = 0);
650 void append(
size_t size,
const char *format, ...);
660 void append(
const char *str,
size_t offset,
size_t count);
687 inline const char *operator =(
const char *str)
707 {append(str);
return *
this;};
713 {add(c);
return *
this;};
719 {append(str);
return *
this;};
725 {append(str.c_str());
return *
this;};
737 friend std::istream &
getline(std::istream &is,
String &str,
char delim,
size_t size);
782 {append(16,
"%d", i);
return *
this;};
785 {append(16,
"%u", i);
return *
this;};
788 {append(16,
"%l", l);
return *
this;};
791 {append(16,
"%ul", l);
return *
this;};
794 {append(32,
"%f", f);
return *
this;};
797 {append(32,
"%f", d);
return *
this;};
800 {append(8,
"%hd", s);
return *
this;};
803 {append(8,
"%hu", s);
return *
this;};
810 {set(16,
"%d", i);
return *
this;};
813 {set(16,
"%u", i);
return *
this;};
816 {set(16,
"%l", l);
return *
this;};
819 {set(16,
"%ul", l);
return *
this;};
822 {set(32,
"%f", f);
return *
this;};
825 {set(32,
"%f", d);
return *
this;};
828 {set(8,
"%hd", s);
return *
this;};
831 {set(8,
"%hu", s);
return *
this;};
835 {copy(original);
return *
this;};
895 void operator delete(
void *obj);
898 #ifdef CCXX_NAMESPACES
const size_t getLength(void) const
Get the assigned length of string.
void setLength(size_t len)
Set the length value of the string content.
void insert(size_t start, const char *text, size_t len=0)
Insert text into a string.
static const unsigned slotcount
Definition: string.h:87
String(const String &str, size_t offset, size_t len=npos)
Create a new string from a subset of another string.
bool operator*=(const char *str) const
Test if text is contained in our string.
virtual ~String()
Destroy the string...
friend __EXPORT String operator+(const String &s1, const char *s2)
void strip(const char *cs)
Strip lead and trailing characters from a string.
friend std::istream & getline(std::istream &is, String &str, char delim, size_t size)
Fetch input from a std::istream into the current string variable until either the string variable is ...
String & operator+=(unsigned long l)
Definition: string.h:790
String & operator=(const String &original)
Definition: string.h:834
void append(const String &str)
Append string to the end of the current string.
static const unsigned minsize
Definition: string.h:83
void erase(size_t start, size_t len=npos)
Erase a portion of string.
static const unsigned slotlimit
Definition: string.h:86
void chop(size_t chars)
Chop n leading characters from a string.
Definition: string.h:458
~SString()
Cancel out the object.
size_t size_type
Definition: string.h:221
size_t size(void) const
Get actual length of string data.
Definition: string.h:618
String & operator+=(const std::string &str)
Append operator.
Definition: string.h:724
String token(const char *delim=" \t\n\r", size_t offset=0)
Extract a new string as a token from the current string.
String & operator+=(char c)
Append operator.
Definition: string.h:712
SString()
Create an empty streamable string ready for input.
The StringObject class is used to derive subclasses that use the String managed memory pool for all s...
Definition: string.h:885
__EXPORT size_t strtrim(const char *cs, char *str, size_t len=0)
String & operator=(long l)
Definition: string.h:815
void chop(const char *cs)
Chop leading characters from a string.
Definition: string.h:443
static const size_t npos
Definition: string.h:219
String(size_t count, const char fill=' ')
Fill a new string with character data.
friend __EXPORT String operator+(const String &s1, const char c2)
const size_t getSize(void) const
Get the allocation size of the string variable.
String & operator+=(short s)
Definition: string.h:799
size_t capacity(void) const
Get space allocated to hold current string.
Definition: string.h:626
String & operator=(unsigned short s)
Definition: string.h:830
size_t search(const char *text, size_t clen=0, size_t offset=0) const
An internal method used to search for a substring starting at a known offset.
bool operator==(const char *str) const
String(std::string string)
Create a String from std::string.
size_t find(const char *s, size_t offset=0, size_t len=0, unsigned count=1) const
Find the index to the nth instance of text in our string.
long getValue(long defvalue=0l) const
Get the value of a string.
String(const String &original)
Copy constructor.
bool operator!(void) const
Logical test for string empty.
Definition: string.h:586
void insert(size_t start, const String &str)
Insert other string into our string.
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.
Definition: string.h:534
void add(char c)
Add a character to the end of a string.
unsigned count(const String &s, size_t offset=0) const
Count the number of occurences of a specific string within our string.
friend __EXPORT int strprintf(String &str, size_t size, const char *format,...)
Print values directly into a string variable.
void copy(const String &str)
Impliment the copy constructor, used internally.
unsigned count(const char *s, size_t offset=0, size_t len=0) const
Count the number of occurrences of a specific text pattern within our string.
friend __EXPORT std::ostream & operator<<(std::ostream &os, const String &str)
Stream the content of our string variable directly to a C++ streaming source.
String(const char *str)
Create a string from a cstring.
String & operator=(int i)
Assignment operator.
Definition: string.h:809
int overflow(int c)
This is the streambuf function that actually outputs the data to the string.
bool operator==(const String &str) const
bool operator>=(const char *str) const
String & operator+=(unsigned short s)
Definition: string.h:802
void trim(size_t count)
Trim n trailing characters from a string.
String & operator=(unsigned long l)
Definition: string.h:818
friend __EXPORT String operator+(const char c1, const String &s2)
bool isBig(void) const
Determine if string is allocated in local variable or an external reference.
Definition: string.h:125
#define __EXPORT
Definition: config.h:979
String & operator+=(const String &str)
Append operator.
Definition: string.h:706
String & operator+=(double d)
Definition: string.h:796
const char operator[](unsigned ind) const
Extract a character by array indexing.
Definition: string.h:681
friend __EXPORT String operator+(const String &s1, const String &s2)
Add two strings and return a temporary object.
bool operator<(const char *str) const
void resize(size_t size)
Re-allocate buffer space for string.
#define NEW_THROWS
Definition: config.h:945
static const unsigned slotsize
Definition: string.h:84
bool operator<=(const char *str) const
char at(ssize_t offset) const
Return a character at a known offset.
const char * set(size_t size, const char *format,...)
Set the content of the string variable to that of a formatted printf style string.
SString(const SString &from)
Copy constructor.
void init(void)
Used to initialize a string object.
bool getBool(bool defbool=false) const
Get the bool flag of a string.
size_t rfind(const char *s, size_t offset=0, size_t len=0) const
Find last occurence of a text in our string.
friend std::istream & operator>>(std::istream &is, String &str)
Stream input into our variable.
Definition: string.h:748
char length
Definition: string.h:109
static const unsigned pagesize
Definition: string.h:85
static char * getSpace(size_t size)
Used to fetch memory, if needed, based on the size, from the pager, or the system heap.
Common and portable character string related functions.
String(size_t size, const char *format,...)
Create a string from formatted text input.
bool operator<=(const String &str) const
bool operator*=(const String &str) const
Test if string is contained in our string.
size_t length
Definition: string.h:105
void replace(size_t start, size_t len, const String &string)
Replace text at a specific position in the string with new string,.
String & operator+=(long l)
Definition: string.h:787
String & operator=(short s)
Definition: string.h:827
substitute functions which may be missing in target platform libc.
bool operator>(const String &str) const
String & operator+=(const char *str)
Append operator.
Definition: string.h:718
void set(const String &str)
Set the content of the string variable to that of another variable.
bool operator<(const String &str) const
void append(const char *str, size_t offset, size_t count)
Append text into the current string.
friend __EXPORT String operator+(const char *s1, const String &s2)
__EXPORT size_t strchop(const char *cs, char *str, size_t len=0)
__EXPORT char * find(const char *cs, char *str, size_t len=0)
char * text(void) const
Alternate get text method.
Definition: string.h:594
size_t rfind(const String &s, size_t offset=0) const
Find last occurence of a substring in our string.
void clear(void)
Clear the contents of the entire string.
size_t setSize(size_t size)
Set the size of allocated space in the string variable (capacity) to a known value.
bool operator>=(const String &str) const
void append(const char *str, size_t count=0)
Append text to the end of the current string.
bool operator!=(const char *str) const
char * text
Definition: string.h:103
String()
Construct an empty string.
String substr(size_t start, size_t len) const
Return a new string that contains a specific substring of the current string.
Definition: string.h:545
String & operator=(unsigned int i)
Definition: string.h:812
void trim(const char *cs)
Trim trailing characters from a string.
Definition: string.h:435
const char * set(const char *str, size_t len=0)
Set the content of the string variable to the specified string value, and use smart re-allocation str...
const char * getIndex(size_t index) const
Get a string pointer to string content based on an indexed offset.
char * c_str(void) const
Old ANSI C++ compatible string pointer extraction.
Definition: string.h:570
char * getText(void) const
Get the text of a string.
__EXPORT std::istream & getline(std::istream &is, String &str, char delim='\n', size_t size=0)
virtual int compare(const char *text, size_t len=0, size_t index=0) const
A derivable low level comparison operator.
size_t find(const String &s, size_t offset=0, unsigned instance=1) const
Find the index to the nth instance of a substring in our string.
size_t length(void) const
Get length as if null terminated string.
Definition: string.h:610
size_t size
Definition: string.h:104
String & operator+=(float f)
Definition: string.h:793
void replace(size_t start, size_t len, const char *text, size_t count=0)
Replace text at a specific position in the string with new text.
String & operator+=(unsigned int i)
Definition: string.h:784
bool empty(void) const
Return true if string is empty.
Definition: string.h:632
void append(size_t size, const char *format,...)
Append formatted text to the end of the current string.
bool operator>(const char *str) const
void compact(void)
Reduce the size of the string allocation to the minimum needed based on the current effective length.
Definition: string.h:562
bool big
Definition: string.h:110
String & operator+=(int i)
Append operator.
Definition: string.h:781
char * data(void) const
Alternate get text method.
Definition: string.h:602
This is a generic and portable string class.
Definition: string.h:81
bool operator!=(const String &str) const
bool isEmpty(void) const
Return true if string is empty.
String & operator=(double d)
Definition: string.h:824
String & operator=(float f)
Definition: string.h:821
const char *() index(size_t ind) const
Return an indexed string based on the index, such as from a find.
Definition: string.h:555
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.
Definition: string.h:523