Mercurial > projects > dynamin
comparison dynamin/core/string.d @ 111:8ba1044adc93
Rename Newline.Macintosh/Linux to better names.
CR is not used on Mac since before OS X. And LF is not just used on
Linux, but other Unix systems too.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 19 Jan 2013 20:57:11 -0600 |
parents | 6613b65a6035 |
children |
comparison
equal
deleted
inserted
replaced
110:6613b65a6035 | 111:8ba1044adc93 |
---|---|
215 /// | 215 /// |
216 Lf = 1, | 216 Lf = 1, |
217 /// | 217 /// |
218 Crlf = 2, | 218 Crlf = 2, |
219 /// | 219 /// |
220 Macintosh = 0, | 220 ClassicMacOS = 0, |
221 /// | 221 /// |
222 Linux = 1, | 222 Unix = 1, |
223 /// | 223 /// |
224 Windows = 2 | 224 Windows = 2 |
225 } | 225 } |
226 /** | 226 /** |
227 * Changes every occurrence of a newline in the specified string to the specified newline. | 227 * Changes every occurrence of a newline in the specified string to the specified newline. |
228 * Examples: | 228 * Examples: |
229 * ----- | 229 * ----- |
230 * "\r\n\n\r".convertNewlines(Newline.Lf) == "\n\n\n" | 230 * "\r\n\n\r".convertNewlines(Newline.Lf) == "\n\n\n" |
231 * "\r\n\n\r".convertNewlines(Newline.Windows) == "\r\n\r\n\r\n" | 231 * "\r\n\n\r".convertNewlines(Newline.Windows) == "\r\n\r\n\r\n" |
232 * "\n\r\n".convertNewlines(Newline.Macintosh) == "\r\r" | 232 * "\n\r\n".convertNewlines(Newline.ClassicMacOS) == "\r\r" |
233 * ----- | 233 * ----- |
234 */ | 234 */ |
235 mstring convertNewlines(cstring str, Newline nl, mstring buffer = null) { // TODO: use buffer | 235 mstring convertNewlines(cstring str, Newline nl, mstring buffer = null) { // TODO: use buffer |
236 string lineSep; | 236 string lineSep; |
237 final switch(nl) { | 237 final switch(nl) { |
242 return str.replace([cast(string)"\r\n", "\r", "\n"], lineSep); | 242 return str.replace([cast(string)"\r\n", "\r", "\n"], lineSep); |
243 } | 243 } |
244 unittest { | 244 unittest { |
245 assert("\r\n\n\r".convertNewlines(Newline.Lf) == "\n\n\n"); | 245 assert("\r\n\n\r".convertNewlines(Newline.Lf) == "\n\n\n"); |
246 assert("\r\n\n\r".convertNewlines(Newline.Windows) == "\r\n\r\n\r\n"); | 246 assert("\r\n\n\r".convertNewlines(Newline.Windows) == "\r\n\r\n\r\n"); |
247 assert("\n\r\n".convertNewlines(Newline.Macintosh) == "\r\r"); | 247 assert("\n\r\n".convertNewlines(Newline.ClassicMacOS) == "\r\r"); |
248 } | 248 } |
249 | 249 |
250 /** | 250 /** |
251 * Joins all the strings in the specified array together into one string, putting | 251 * Joins all the strings in the specified array together into one string, putting |
252 * the specified separator between them. | 252 * the specified separator between them. |