summaryrefslogtreecommitdiff
path: root/lib/String.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/String.cc')
-rw-r--r--lib/String.cc28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/String.cc b/lib/String.cc
index 402424c..f24dcca 100644
--- a/lib/String.cc
+++ b/lib/String.cc
@@ -475,6 +475,30 @@ String & String::tolower() {
return *this;
}
-bool compare(String a, String b) {
- return a < b;
+String String::ltrim() const {
+ char * d = (char *) malloc(strlen() + 1), * p, * r;
+ int s;
+
+ r = d;
+
+ for (p = str; *p && *p == ' '; p++);
+ for (s = 0; *p; *(d++) = *(p++), s++);
+ *d = 0;
+
+ return String(s, r);
+}
+
+String String::rtrim() const {
+ char * d = strdup(), * r;
+ int s = strlen();
+
+ r = d;
+
+ for (d += s - 1; s && (*d == ' '); *(d--) = 0, s--);
+
+ return String(s, r);
+}
+
+String String::trim() const {
+ return rtrim().ltrim();
}