string: fix strip_margin
parent
d39dd53998
commit
456c0250b0
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue