string: fix strip_margin

pull/4042/head
yuyi 2020-03-16 22:46:09 +08:00 committed by GitHub
parent d39dd53998
commit 456c0250b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -244,9 +244,10 @@ pub fn (s string) replace_each(vals []string) string {
} }
// We need to remember both the position in the string, // We need to remember both the position in the string,
// and which rep/with pair it refers to. // and which rep/with pair it refers to.
idxs << RepIndex{ idxs << RepIndex {
idx:idx idx:idx
val_idx:rep_i} val_idx:rep_i
}
idx++ idx++
new_len += with.len - rep.len new_len += with.len - rep.len
} }
@ -1306,14 +1307,15 @@ pub fn (s string) strip_margin(del ...byte) string {
mut count := 0 mut count := 0
for i := 0; i < s.len; i++ { for i := 0; i < s.len; i++ {
if (s[i] in [`\n`, `\r`]) { if (s[i] in [`\n`, `\r`]) {
$if windows { ret[count] = s[i]
ret[count] = `\r` count++
ret[count+1] = `\n` // CRLF
count += 2 if s[i] == `\r` && i < s.len - 1 && s[i+1] == `\n` {
} $else { ret[count] = s[i+1]
ret[count] = s[i]
count++ count++
i++
} }
for s[i] != sep { for s[i] != sep {
i++ i++
if i >= s.len { if i >= s.len {