diff options
Diffstat (limited to 'src/user/lib/fwik/include')
-rw-r--r-- | src/user/lib/fwik/include/IO/IOStream.h | 4 | ||||
-rw-r--r-- | src/user/lib/fwik/include/IO/Term.h | 5 | ||||
-rw-r--r-- | src/user/lib/fwik/include/String.h | 35 |
3 files changed, 41 insertions, 3 deletions
diff --git a/src/user/lib/fwik/include/IO/IOStream.h b/src/user/lib/fwik/include/IO/IOStream.h index e9ae246..e381cf5 100644 --- a/src/user/lib/fwik/include/IO/IOStream.h +++ b/src/user/lib/fwik/include/IO/IOStream.h @@ -3,6 +3,8 @@ #include "Term.h" +#include <String.h> + class IOStream { public: Term *term; @@ -12,7 +14,7 @@ class IOStream { void print(char* str); void printf(char* fmt, ...); - char* readln(); + String readln(); IOStream &operator<<(char* s) { print(s); diff --git a/src/user/lib/fwik/include/IO/Term.h b/src/user/lib/fwik/include/IO/Term.h index cf90789..4fd9306 100644 --- a/src/user/lib/fwik/include/IO/Term.h +++ b/src/user/lib/fwik/include/IO/Term.h @@ -3,6 +3,7 @@ #include <stdio.h> #include "Node.h" +#include <String.h> #include <readline.h> @@ -22,8 +23,8 @@ class Term : public Node { virtual void print(char *s); virtual void printf(char* fmt, ...); virtual void vprintf(char* fmt, va_list ap); - virtual char* readln(); - char* readline(); + virtual String readln(); + String readline(); virtual Term* as_term() { return this; } }; diff --git a/src/user/lib/fwik/include/String.h b/src/user/lib/fwik/include/String.h index 2a44046..672220d 100644 --- a/src/user/lib/fwik/include/String.h +++ b/src/user/lib/fwik/include/String.h @@ -1,5 +1,40 @@ #ifndef DEF_FWIK_STRING_H #define DEF_FWIK_STRING_H +#include <cpp.h> + +class String { + private: + char *ptr; // zero-terminated for internal purposes. + int len; + + public: + String(); + String(const String& other); + String(char* ptr); + String(char* ptr, int len); + String(char c, int count); + ~String(); + void operator=(const String &string); + void operator=(char* ptr); + + char* c_str(); + + bool operator==(const String& other); + bool operator==(char* other); + bool operator<(const String& other); + char &operator[](int pos); + + int size() { return len; } + operator bool() { return len != 0; } + String substr(int start, int count); + + String operator+(const String& other); + void operator+=(const String& other); + void operator+=(char c); + + static String dec(int i); + static String hex(uint32_t v); +}; #endif |