Skip to content

Commit 860184a

Browse files
committed
fix stringbuilder with fabel 5.alpha 23
1 parent 66f5687 commit 860184a

File tree

4 files changed

+50
-30
lines changed

4 files changed

+50
-30
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.22.0] - 2026-02-08
11+
### Fixed
12+
- fixed Stringbuilder.Chars in JS by using Fabel 5.0.alpha 23
13+
1014
## [0.21.0] - 2025-12-01
1115
### Added
1216
- Str.addThousandSeparators function.
@@ -24,7 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2428
### Changed
2529
- Rename extension methods on StringBuilder from `.append` to `.Add`
2630
### Added
27-
- better documentation
31+
- better documentation
2832
- .IsEmpty extension method
2933
- .IsNotEmpty extension method
3034
- .IsWhite extension method
@@ -48,7 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4852
- Implementation ported from [FsEx](https://github.com/goswinr/FsEx/blob/main/Src/StringModule.fs)
4953
- Added more tests
5054

51-
[Unreleased]: https://github.com/goswinr/Str/compare/0.21.0...HEAD
55+
[Unreleased]: https://github.com/goswinr/Str/compare/0.22.0...HEAD
56+
[0.22.0]: https://github.com/goswinr/Str/compare/0.21.0...0.22.0
5257
[0.21.0]: https://github.com/goswinr/Str/compare/0.20.0...0.21.0
5358
[0.20.0]: https://github.com/goswinr/Str/compare/0.19.0...0.20.0
5459
[0.19.0]: https://github.com/goswinr/Str/compare/0.18.0...0.19.0

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
![Logo](https://raw.githubusercontent.com/goswinr/Str/main/Docs/img/logo128.png)
2+
23
# Str
34

45
[![Str on nuget.org](https://img.shields.io/nuget/v/Str)](https://www.nuget.org/packages/Str/)

Src/StringBuilder.fs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,47 @@ module AutoOpenExtensionsStringBuilder =
2424
// TODO: add overload with length: sb.IndexOf (c:char, from:int, length:int )
2525

2626
/// Like list.IndexOf but for StringBuilder, returns -1 if not found
27-
/// Throws ArgumentOutOfRangeException if 'from' is out of range
27+
/// Throws ArgumentOutOfRangeException if 'from' is negative.
2828
member sb.IndexOf (c:char, from:int ) : int =
29-
if from < 0 then ArgumentOutOfRangeException("from",$"StringBuilder.IndexOf: from ({from}) must be non-negative") |> raise
29+
if from < 0 then
30+
ArgumentOutOfRangeException("from",$"StringBuilder.IndexOf: from ({from}) must be non-negative") |> raise
3031
let len = sb.Length
31-
if from >= len then ArgumentOutOfRangeException("from",$"StringBuilder.IndexOf: from ({from}) must be less than StringBuilder length ({len})") |> raise
32+
// if from >= len then
33+
// ArgumentOutOfRangeException("from",$"StringBuilder.IndexOf: from ({from}) must be less than StringBuilder length ({len})") |> raise
3234
let rec find i =
33-
if i = len then -1
34-
elif sb.[i] = c then i
35-
else find (i+1)
35+
if i = len then
36+
-1
37+
elif sb.[i] = c then
38+
i
39+
else
40+
find (i+1)
3641
find(from)
3742

3843
/// Like list.IndexOf but for StringBuilder, returns -1 if not found
3944
/// Always uses StringComparison.Ordinal
40-
/// Throws ArgumentOutOfRangeException if 'from' is out of range
45+
/// Throws ArgumentOutOfRangeException if 'from' is negative.
4146
member sb.IndexOf (t:string, from:int) : int =
4247
// could in theory be improved be using a rolling hash value
4348
// see also Array.findArray implementation
4449
// or https://stackoverflow.com/questions/12261344/fastest-search-method-in-stringbuilder
45-
let ls = sb.Length
46-
let lt = t.Length
47-
if from < 0 then ArgumentOutOfRangeException("from",$"StringBuilder.IndexOf: from ({from}) must be non-negative") |> raise
48-
if from >= ls then ArgumentOutOfRangeException("from",$"StringBuilder.IndexOf: from ({from}) must be less than StringBuilder length ({ls})") |> raise
49-
//printfn "sb :%d t:%d" ls lt
50-
let rec find ib it = // index in StringBuilder and index in search string
51-
//printfn "Search at ib:%d %c for it:%d %c" ib sb.[ib] it t.[it]
52-
if ib > ls-lt+it then -1 // not found! not enough chars left in StringBuilder to match remaining search string
53-
elif sb.[ib] = t.[it] then
54-
if it = lt-1 then ib - lt + 1 // found !
55-
else find (ib+1) (it+1)
56-
else find (ib+1-it) 0
50+
let lenBuilder = sb.Length
51+
let lenText = t.Length
52+
if from < 0 then
53+
ArgumentOutOfRangeException("from",$"StringBuilder.IndexOf: from ({from}) must be non-negative") |> raise
54+
55+
// if from >= lenBuilder then
56+
// ArgumentOutOfRangeException("from",$"StringBuilder.IndexOf: from ({from}) must be less than StringBuilder length ({lenBuilder})") |> raise
57+
58+
let rec find idxBuilder idxText = // index in StringBuilder and index in search string
59+
if idxBuilder > lenBuilder-lenText+idxText then
60+
-1 // not found! not enough chars left in StringBuilder to match remaining search string
61+
elif sb.[idxBuilder] = t.[idxText] then
62+
if idxText = lenText-1 then
63+
idxBuilder - lenText + 1 // found !
64+
else
65+
find (idxBuilder+1) (idxText+1)
66+
else
67+
find (idxBuilder+1-idxText) 0
5768
find from 0
5869

5970
/// Like list.IndexOf but for StringBuilder, returns -1 if not found

Tests/package-lock.json

Lines changed: 12 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)