Skip to content

Commit 10f1453

Browse files
committed
fix: System.Text.fs StringBuilders for Rust and Dart
1 parent 959928c commit 10f1453

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

src/fable-library-dart/System.Text.fs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,35 +101,35 @@ type StringBuilder(value: string, capacity: int) =
101101

102102
with get (index: int) =
103103
let mutable len = 0
104-
let mutable i = -1
104+
let mutable i = 0
105105

106-
while i + 1 < buf.Count && len < index do
107-
i <- i + 1
106+
while i < buf.Count && len + buf[i].Length <= index do
108107
len <- len + buf[i].Length
108+
i <- i + 1
109109

110-
if index < 0 || i < 0 || i >= buf.Count then
110+
if index < 0 || i >= buf.Count then
111111
failwith "Index was outside the bounds of the array"
112112
else
113-
let pos = len - index - 1
113+
let pos = index - len
114114
buf[i][pos]
115115

116116
and set (index: int) (value: char) =
117117
let mutable len = 0
118-
let mutable i = -1
118+
let mutable i = 0
119119

120-
while i + 1 < buf.Count && len < index do
121-
i <- i + 1
120+
while i < buf.Count && len + buf[i].Length <= index do
122121
len <- len + buf[i].Length
122+
i <- i + 1
123123

124-
if index < 0 || i < 0 || i >= buf.Count then
124+
if index < 0 || i >= buf.Count then
125125
failwith "Index was outside the bounds of the array"
126126
else
127-
let pos = len - index - 1
128-
buf[i] <- buf[i][0 .. (pos - 1)] + (string value) + buf[i][(pos + 1) ..]
127+
let pos = index - len
128+
buf[i] <- buf[i][0 .. (pos - 1)] + (string<char> value) + buf[i][(pos + 1) ..]
129129

130130
member x.Replace(oldValue: char, newValue: char) =
131-
let oldValue = string oldValue
132-
let newValue = string newValue
131+
let oldValue = string<char> oldValue
132+
let newValue = string<char> newValue
133133

134134
for i = buf.Count - 1 downto 0 do
135135
buf[i] <- buf[i].Replace(oldValue, newValue)

src/fable-library-rust/src/System.Text.fs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ type StringBuilder(value: string, capacity: int) =
1717
buf.Add(s)
1818
x
1919

20-
member x.Append(o: bool) = x.Append(string o)
21-
member x.Append(c: char) = x.Append(string c)
20+
member x.Append(o: bool) = x.Append(string<bool> o)
21+
member x.Append(c: char) = x.Append(string<char> c)
2222

2323
member x.Append(c: char, repeatCount: int) =
2424
let s = String.replicate repeatCount (string<char> c)
2525
buf.Add(s)
2626
x
2727

28-
member x.Append(o: int8) = x.Append(string o)
29-
member x.Append(o: byte) = x.Append(string o)
30-
member x.Append(o: int16) = x.Append(string o)
31-
member x.Append(o: uint16) = x.Append(string o)
32-
member x.Append(o: int32) = x.Append(string o)
33-
member x.Append(o: uint32) = x.Append(string o)
34-
member x.Append(o: int64) = x.Append(string o)
35-
member x.Append(o: uint64) = x.Append(string o)
36-
member x.Append(o: float32) = x.Append(string o)
37-
member x.Append(o: float) = x.Append(string o)
28+
member x.Append(o: int8) = x.Append(string<int8> o)
29+
member x.Append(o: byte) = x.Append(string<byte> o)
30+
member x.Append(o: int16) = x.Append(string<int16> o)
31+
member x.Append(o: uint16) = x.Append(string<uint16> o)
32+
member x.Append(o: int32) = x.Append(string<int32> o)
33+
member x.Append(o: uint32) = x.Append(string<uint32> o)
34+
member x.Append(o: int64) = x.Append(string<int64> o)
35+
member x.Append(o: uint64) = x.Append(string<uint64> o)
36+
member x.Append(o: float32) = x.Append(string<float32> o)
37+
member x.Append(o: float) = x.Append(string<float> o)
3838

3939
member x.Append(s: string, index: int, count: int) = x.Append(s.Substring(index, count))
4040

@@ -57,31 +57,31 @@ type StringBuilder(value: string, capacity: int) =
5757

5858
with get (index: int) =
5959
let mutable len = 0
60-
let mutable i = -1
60+
let mutable i = 0
6161

62-
while i + 1 < buf.Count && len < index do
63-
i <- i + 1
62+
while i < buf.Count && len + buf[i].Length <= index do
6463
len <- len + buf[i].Length
64+
i <- i + 1
6565

66-
if index < 0 || i < 0 || i >= buf.Count then
66+
if index < 0 || i >= buf.Count then
6767
failwith "Index was outside the bounds of the array"
6868
else
69-
let pos = len - index - 1
69+
let pos = index - len
7070
buf[i][pos]
7171

7272
and set (index: int) (value: char) =
7373
let mutable len = 0
74-
let mutable i = -1
74+
let mutable i = 0
7575

76-
while i + 1 < buf.Count && len < index do
77-
i <- i + 1
76+
while i < buf.Count && len + buf[i].Length <= index do
7877
len <- len + buf[i].Length
78+
i <- i + 1
7979

80-
if index < 0 || i < 0 || i >= buf.Count then
80+
if index < 0 || i >= buf.Count then
8181
failwith "Index was outside the bounds of the array"
8282
else
83-
let pos = len - index - 1
84-
buf[i] <- buf[i][0 .. (pos - 1)] + (string value) + buf[i][(pos + 1) ..]
83+
let pos = index - len
84+
buf[i] <- buf[i][0 .. (pos - 1)] + (string<char> value) + buf[i][(pos + 1) ..]
8585

8686
member x.Length =
8787
let mutable len = 0
@@ -92,8 +92,8 @@ type StringBuilder(value: string, capacity: int) =
9292
len
9393

9494
member x.Replace(oldValue: char, newValue: char) =
95-
let oldValue = string oldValue
96-
let newValue = string newValue
95+
let oldValue = string<char> oldValue
96+
let newValue = string<char> newValue
9797

9898
for i = buf.Count - 1 downto 0 do
9999
buf[i] <- buf[i].Replace(oldValue, newValue)

0 commit comments

Comments
 (0)