digitalmars.D - [patch] std.string: add os-dependant newline constants and wrap()
- Ameer Armaly (36/36) Aug 04 2005 --- string.d 2005-08-04 16:40:30.000000000 -0400
--- string.d 2005-08-04 16:40:30.000000000 -0400
+++ string.new 2005-08-04 16:42:14.000000000 -0400
-65,7 +65,10
}
/************** Constants ****************/
-
+version(Win32)
+const char[2] newline="\r\n";
+else version(linux)
+const char[1] newline="\n";
const char[16] hexdigits = "0123456789ABCDEF";
const char[10] digits = "0123456789";
const char[8] octdigits = "01234567";
-2946,3 +2949,22
r = tr("Abc", "AAA", "XYZ");
assert(r == "Xbc");
}
+//wraps a string after a certain length by inserting the system-specific
newline,
+char[] wrap(char[] s, uint endline)
+ {
+char[] n;
+ int i=endline;
+ while(true)
+ {
+ if(i>=s.length)
+ break;
+ //if we don't have enough room for a complete line, we tack on what's left
and exit out
+ if(i<s.length&&s.length-i<newline)
+ {
+ n~=s[i..length-1];
+ break;
+ }
+ n~=s[0..i-1]~newline;
+}
+return n;
+}
Aug 04 2005








Ameer Armaly <ameer bellsouth.net>