feisty meow concerns codebase  2.140
base_string.h
Go to the documentation of this file.
1 #ifndef BASE_STRING_CLASS
2 #define BASE_STRING_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : base_string *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1992-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 //hmmm: some of these methods could be pulled out to a base_array class.
19 // that would be a nice further abstraction.
20 
21 #include "contracts.h"
22 
23 namespace basis {
24 
26 
27 class base_string : public virtual orderable
28 {
29 public:
30  virtual int length() const = 0;
32 
35  virtual const char *observe() const = 0;
37 
40  virtual char *access() = 0;
42 
46  virtual char get(int index) const = 0;
48 
49  virtual void put(int position, char to_put) = 0;
51 
52  virtual bool sub_compare(const base_string &to_compare, int start_first,
53  int start_second, int count, bool case_sensitive) const = 0;
55 
64  virtual base_string &assign(const base_string &s) = 0;
66 
67  virtual base_string &upgrade(const char *s) = 0;
69 
70  virtual void insert(int position, const base_string &to_insert) = 0;
72 
74  virtual void zap(int start, int end) = 0;
76 
79  virtual base_string &concatenate_string(const base_string &s) = 0;
81 
82  virtual base_string &concatenate_char(char c) = 0;
84 
85  virtual bool sub_string(base_string &target, int start, int end) const = 0;
87 
90 
92  virtual base_string &operator =(const base_string &to_copy) { return assign(to_copy); }
93 };
94 
95 } //namespace.
96 
97 #endif
98 
Defines the base class for all string processing objects in hoople.
Definition: base_string.h:28
virtual void insert(int position, const base_string &to_insert)=0
Copies "to_insert" into "this" at the "position".
virtual const char * observe() const =0
observes the underlying pointer to the zero-terminated string.
virtual base_string & upgrade(const char *s)=0
Sets the contents of this string to "s".
virtual char get(int index) const =0
a constant peek at the string's internals at the specified index.
virtual base_string & operator=(const base_string &to_copy)
sets this string's contents equal to the contents of "to_copy".
Definition: base_string.h:92
virtual void put(int position, char to_put)=0
stores the character "to_put" at index "position" in the string.
virtual bool sub_string(base_string &target, int start, int end) const =0
Gets the segment of "this" between the indices "start" and "end".
virtual void zap(int start, int end)=0
Deletes the characters between "start" and "end" inclusively.
virtual char * access()=0
provides access to the actual string held.
virtual int length() const =0
Returns the current length of the string.
virtual bool sub_compare(const base_string &to_compare, int start_first, int start_second, int count, bool case_sensitive) const =0
Compares "this" string with "to_compare".
virtual base_string & concatenate_char(char c)=0
concatenater for single characters.
virtual base_string & concatenate_string(const base_string &s)=0
Modifies "this" by concatenating "s" onto it.
virtual base_string & assign(const base_string &s)=0
Sets the contents of this string to "s".
A base for objects that can be alphabetically (lexicographically) ordered.
Definition: contracts.h:57
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30