BFLibCPP 0.1
CPP Library
Loading...
Searching...
No Matches
string.hpp
Go to the documentation of this file.
1
6#ifndef STRING_HPP
7#define STRING_HPP
8
9#include "array.hpp"
10#include "access.hpp"
11
12namespace BF {
13
14class String : protected Array<char, size_t> {
15public:
16 virtual ~String();
17
21 static String * createWithFormat(const char * format, ...);
22
23 String();
24 String(const char * str);
25 String(char * str);
26 String(const String & str);
27
28 // both integer param constructors throw
29 // std::invalid_argument if nullstr != 0
30 String(long int nullstr);
31 String(int nullstr);
32
33 // Returns raw c string
34 const char * cString() const;
35
36 // returns a copy of string
37 //
38 // caller must free()
39 char * cStringCopy() const;
40
44 int compareString(const String & s) const;
45
49 size_t length() const;
50
56 int copy(String & s) const;
57
61 int readFromFile(const char * file);
62
68 int addChar(char c);
69
75 int remChar();
76
80 int addCharAtIndex(char c, size_t index);
81
85 int remCharAtIndex(size_t index);
86
90 int clear();
91
92// Overloading operators
93public:
94 friend std::ostream& operator<<(std::ostream& out, const String & s) {
95 return out << s.cString();
96 }
97
98 operator const char * () const; // casting overloader
99 bool operator==(const String & s);
100 bool operator<(const String & s);
101 bool operator>(const String & s);
102 bool operator!=(const String & s);
103 String & operator=(const String & str);
104 const char operator[](size_t index);
105
106// Conversions
107public:
108
110 static int toi(const String & s);
111};
112
113} // namespace BF
114
115#endif // STRING_HPP
116
Definition array.hpp:29
Definition string.hpp:14
int compareString(const String &s) const
Definition string.cpp:119
const char * cString() const
Definition string.cpp:46
static int toi(const String &s)
similar to std::atoi
Definition string.cpp:136
String & operator=(const String &str)
Definition string.cpp:127
int remCharAtIndex(size_t index)
Definition string.cpp:84
bool operator==(const String &s)
Definition string.cpp:103
bool operator>(const String &s)
Definition string.cpp:115
bool operator<(const String &s)
Definition string.cpp:111
friend std::ostream & operator<<(std::ostream &out, const String &s)
Definition string.hpp:94
String()
Definition string.cpp:18
int addChar(char c)
Definition string.cpp:69
int addCharAtIndex(char c, size_t index)
Definition string.cpp:73
const char operator[](size_t index)
Definition string.cpp:132
int copy(String &s) const
Definition string.cpp:64
virtual ~String()
Definition string.cpp:44
int clear()
Definition string.cpp:92
static String * createWithFormat(const char *format,...)
Definition string.cpp:34
size_t length() const
Definition string.cpp:123
int readFromFile(const char *file)
Definition string.cpp:54
int remChar()
Definition string.cpp:80
bool operator!=(const String &s)
Definition string.cpp:107
char * cStringCopy() const
Definition string.cpp:50
Definition array.hpp:18