Skip to content

Commit 4cc8934

Browse files
committed
Fix System.Text.fs for Python
1 parent 10f1453 commit 4cc8934

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/fable-library-py/fable_library/System.Text.fs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ type StringBuilder(value: string, capacity: int) =
1515
new() = StringBuilder("", 16)
1616

1717
member x.Append(s: string | null) =
18-
buf.Add(string s)
18+
buf.Add(string<string | null> s)
1919
x
2020

2121
member x.Append(s: string | null, startIndex: int, count: int) =
22-
buf.Add((string s).Substring(startIndex, count))
22+
buf.Add((string<string | null> s).Substring(startIndex, count))
2323
x
2424

2525
member x.Append(c: char) =
@@ -104,31 +104,31 @@ type StringBuilder(value: string, capacity: int) =
104104

105105
with get (index: int) =
106106
let mutable len = 0
107-
let mutable i = -1
107+
let mutable i = 0
108108

109-
while i + 1 < buf.Count && len < index do
110-
i <- i + 1
109+
while i < buf.Count && len + buf[i].Length <= index do
111110
len <- len + buf[i].Length
111+
i <- i + 1
112112

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

119119
and set (index: int) (value: char) =
120120
let mutable len = 0
121-
let mutable i = -1
121+
let mutable i = 0
122122

123-
while i + 1 < buf.Count && len < index do
124-
i <- i + 1
123+
while i < buf.Count && len + buf[i].Length <= index do
125124
len <- len + buf[i].Length
125+
i <- i + 1
126126

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

133133
member x.Replace(oldValue: char, newValue: char) =
134134
for i = buf.Count - 1 downto 0 do

0 commit comments

Comments
 (0)