str.cxx

changeset 2
bb2c45522eb6
parent 0
8dce9696d62d
child 3
08cab2b67dce
--- a/str.cxx	Fri Jul 13 18:41:40 2012 +0300
+++ b/str.cxx	Fri Jul 13 20:10:08 2012 +0300
@@ -99,6 +99,8 @@
 	
 	delete text;
 	text = new char[len+1];
+	for (unsigned int u = 0; u < len+1; u++)
+		text[u] = 0;
 	strncpy (text, oldtext, len);
 	
 	alloclen = len;
@@ -107,7 +109,7 @@
 // ============================================================================
 void str::dump () {
 	for (unsigned int u = 0; u <= alloclen; u++)
-		printf ("\t%u. %d (%c)\n", u, text[u], text[u]);
+		printf ("\t%u. %u (%c)\n", u, text[u], text[u]);
 }
 
 // ============================================================================
@@ -116,7 +118,6 @@
 	// Out of space, thus resize
 	if (curs == alloclen)
 		resize (alloclen+1);
-	
 	text[curs] = c;
 	curs++;
 }
@@ -348,6 +349,30 @@
 }
 
 // ============================================================================
+str str::tolower () {
+	str n = text;
+	
+	for (uint u = 0; u < len(); u++) {
+		if (n[u] > 'A' && n[u] < 'Z')
+			n.text[u] += ('a' - 'A');
+	}
+	
+	return n;
+}
+
+// ============================================================================
+str str::toupper () {
+	str n = text;
+	
+	for (uint u = 0; u < len(); u++) {
+		if (n[u] > 'a' && n[u] < 'z')
+			n.text[u] -= ('A' - 'a');
+	}
+	
+	return n;
+}
+
+// ============================================================================
 // OPERATORS
 str str::operator + (str& c) {
 	append (c);

mercurial