99 bool t()
const {
return !
empty(); }
110 virtual const char *
observe()
const;
116 const char *
s()
const {
return observe(); }
119 virtual char get(
int index)
const;
141 virtual void put(
int position,
char to_put) { (*this)[position] = to_put; }
148 int convert(
int default_value)
const;
155 long convert(
long default_value)
const;
157 float convert(
float default_value)
const;
159 double convert(
double default_value)
const;
162 bool equal_to(
const char *that)
const;
167 bool iequals(
const char *that)
const;
171 int start_second,
int count,
bool case_sensitive)
const;
186 {
return compare(maybe_prefix, 0, 0, maybe_prefix.
length(),
false); }
191 const int diff =
length() - maybe_suffix.length();
192 return (diff >= 0) &&
compare(maybe_suffix, diff, 0, maybe_suffix.length(),
true);
197 return (diff >= 0) &&
compare(maybe_suffix, diff, 0, maybe_suffix.
length(),
false);
211 void copy(
char *to_stuff,
int count)
const;
219 void stuff(
char *to_stuff,
int count)
const {
copy(to_stuff, count); }
236 int find(
char to_find,
int position = 0,
bool reverse =
false)
const;
241 int find(
const astring &to_find,
int posn = 0,
bool reverse =
false)
const;
244 int ifind(
char to_find,
int position = 0,
bool reverse =
false)
const;
246 int ifind(
const astring &to_find,
int posn = 0,
bool reverse =
false)
const;
249 int find_any(
const char *to_find,
int position = 0,
250 bool reverse =
false)
const;
254 int ifind_any(
const char *to_find,
int position = 0,
255 bool reverse =
false)
const;
260 bool reverse =
false)
const;
281 void pad(
int length,
char padding =
' ');
291 virtual void zap(
int start,
int end);
333 {
strip(
" \t", way); }
342 void pack(byte_array &target)
const;
344 bool unpack(byte_array &source);
381 virtual bool equal_to(
const equalizable &s2)
const;
382 virtual bool less_than(
const orderable &s2)
const;
386 virtual base_string &
assign(
const base_string &
s);
387 virtual base_string &
upgrade(
const char *
s);
388 virtual bool sub_string(base_string &target,
int start,
int end)
const;
389 virtual bool sub_compare(
const base_string &to_compare,
int start_first,
390 int start_second,
int count,
bool case_sensitive)
const;
391 virtual void insert(
int position,
const base_string &to_insert);
392 virtual void text_form(base_string &state_fill)
const;
395 byte_array c_character_manager;
399 int char_find(
char to_find,
int position,
bool reverse,
400 bool case_sense)
const;
402 int char_find_any(
const astring &to_find,
int position,
bool reverse,
403 bool case_sense,
bool invert_find =
false)
const;
404 int str_find(
const astring &to_find,
int posn,
bool reverse,
411 char *
const *c_held_string;
413 void seek_flag(
const char *&traverser,
char *flag_chars,
bool &failure);
415 void seek_width(
const char *&traverser,
char *width_chars);
417 void seek_precision(
const char *&traverser,
char *precision_chars);
419 void seek_modifier(
const char *&traverser,
char *modifier_char);
421 void get_type_character(
const char *&traverser, va_list &args,
422 astring &output_string,
const char *flag_chars,
423 const char *width_chars,
const char *precision_chars,
424 const char *modifier_chars);
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
virtual ~astring()
destroys any storage for the string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
astring & operator=(const astring &s)
Sets the contents of this string to "s".
astring lower() const
like to_lower(), but returns a new string rather than modifying this.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
astring middle(int start, int count)
returns the middle of the string from "start" with "count" characters.
static bool matches(const astring &match_list, char to_match)
returns true if "to_match" is found in the "match_list" string.
void pack(byte_array &target) const
stores this string in the "target". it can later be unpacked again.
bool replace(const astring &tag, const astring &replacement)
replaces the first occurrence of "tag" text with the "replacement".
int packed_size() const
Reports the size required to pack this string into a byte array.
int ifind_any(const char *to_find, int position=0, bool reverse=false) const
searches case-insensitively for any of the characters in "to_find".
void trim(int length)
shortens the string to "length" if it's longer than that.
byte_array & get_implementation()
bool ends(const astring &maybe_suffix) const
returns true if this string ends with "maybe_suffix".
virtual base_string & assign(const base_string &s)
Sets the contents of this string to "s".
virtual char get(int index) const
a constant peek at the string's internals at the specified index.
astring operator+(const astring &s) const
Returns the concatenation of "this" and "s".
int convert(int default_value) const
Converts the string into a corresponding integer.
astring & operator+=(const astring &s)
Modifies "this" by concatenating "s" onto it.
bool non_empty() const
non_empty() reports if the string has some contents.
void copy(char *to_stuff, int count) const
Copies a maximum of "count" characters from this into "to_stuff".
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
astring()
constructs an empty string.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
DEFINE_CLASS_NAME("astring")
void strip_white_spaces(how_to_strip way=FROM_BOTH_SIDES)
like strip_spaces, but includes tabs in the list to strip.
void strip(const astring &strip_list, how_to_strip way=FROM_BOTH_SIDES)
strips all chars from "strip_list" out of "this" given the "way".
static const astring & empty_string()
useful wherever empty strings are needed, e.g., function defaults.
const char * c_str() const
synonym for observe. mimics the STL method name.
astring & base_sprintf(const char *s, va_list &args)
void shrink()
changes all occurrences of "to_replace" into "new_string".
bool operator!() const
the negation operator returns true if the string is empty.
bool begins(const astring &maybe_prefix) const
Returns true if "this" string begins with "maybe_prefix".
void strip_spaces(how_to_strip way=FROM_BOTH_SIDES)
removes excess space characters from string's beginning, end or both.
astring & sprintf(const char *s,...)
similar to the SPRINTF constructor, but works on an existing string.
virtual base_string & concatenate_string(const base_string &s)
Modifies "this" by concatenating "s" onto it.
void to_upper()
to_upper does the opposite of to_lower (that is, q becomes Q).
virtual void text_form(base_string &state_fill) const
Provides a text view of all the important info owned by this object.
bool iequals(const astring &that) const
returns true if this is case-insensitively equal to "that".
astring left(int count)
returns the left "count" characters from the string.
void stuff(char *to_stuff, int count) const
a synonym for copy().
void insert(int position, const astring &to_insert)
Copies "to_insert" into "this" at the "position".
void pad(int length, char padding=' ')
makes the string "length" characters long.
virtual base_string & concatenate_char(char c)
concatenater for single characters.
void reset()
clears out the contents string.
int find_non_match(const char *to_find, int position=0, bool reverse=false) const
searches for any character that is not in "to_find" and returns index.
bool equal_to(const char *that) const
returns true if "that" is equal to this.
int end() const
returns the index of the last (non-null) character in the string.
virtual bool less_than(const orderable &s2) const
virtual int comparator(const astring &s2) const
helps to fulfill orderable contract.
char & operator[](int position)
accesses individual characters in "this" string.
int find_any(const char *to_find, int position=0, bool reverse=false) const
searches for any of the characters in "to_find".
astring right(int count)
returns the right "count" characters from the string.
bool empty() const
empty() reports if the string is empty, that is, of zero length().
virtual void put(int position, char to_put)
stores the character "to_put" at index "position" in the string.
bool replace_all(char to_replace, char new_char)
changes all occurrences of "to_replace" with "new_char".
bool ibegins(const astring &maybe_prefix) const
a case-insensitive method similar to begins().
int length() const
Returns the current length of the string.
bool unpack(byte_array &source)
retrieves a string (packed with pack()) from "source" into this string.
virtual char * access()
provides access to the actual string held.
astring upper() const
like to_upper(), but returns a new string rather than modifying this.
bool compare(const astring &to_compare, int start_first, int start_second, int count, bool case_sensitive) const
Compares "this" string with "to_compare".
virtual bool sub_string(base_string &target, int start, int end) const
Gets the segment of "this" between the indices "start" and "end".
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
bool contains(const astring &to_find) const
Returns true if "to_find" is contained in this string or false if not.
virtual bool sub_compare(const base_string &to_compare, int start_first, int start_second, int count, bool case_sensitive) const
Compares "this" string with "to_compare".
bool iends(const astring &maybe_suffix) const
int ifind(char to_find, int position=0, bool reverse=false) const
like the find() methods above, but case-insensitive.
virtual const char * observe() const
observes the underlying pointer to the zero-terminated string.
void to_lower()
to_lower modifies "this" by replacing capitals with lower-case.
virtual base_string & upgrade(const char *s)
Sets the contents of this string to "s".
Defines the base class for all string processing objects in hoople.
A very common template for a dynamic array of bytes.
the base class of the most easily used and tested objects in the library.
The guards collection helps in testing preconditions and reporting errors.
bool string_comparator_function(const astring &a, const astring &b)
returns true if the strings "a" and "b" are considered equal.
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
bool astring_comparator(const astring &a, const astring &b)
implements a string comparator that just does simple astring ==.