Skip to content

Commit 1974a4b

Browse files
webwarrior-wsknocte
authored andcommitted
Core(Naming): make last test pass
Regarding splitByCaseChange: a more complex case.
1 parent 871174d commit 1974a4b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/FSharpLint.Core/Rules/Conventions/Naming/NamingHelper.fs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module FSharpLint.Rules.Helper.Naming
22

33
open System
4-
open System.Text
54
open FSharp.Compiler.Syntax
65
open FSharp.Compiler.Text
76
open FSharpLint.Framework
@@ -54,16 +53,17 @@ module QuickFixes =
5453
Some { FromText = ident.idText; FromRange = ident.idRange; ToText = camelCaseIdent })
5554

5655
let splitByCaseChange (name: string) : seq<string> =
57-
let builder = System.Text.StringBuilder()
56+
let partitionPoints =
57+
seq {
58+
yield 0
59+
for (index, (current, next)) in name |> Seq.pairwise |> Seq.indexed do
60+
if (Char.IsUpper next || not (Char.IsLetter next)) && not (Char.IsUpper current) then
61+
yield index + 1
62+
yield name.Length
63+
}
5864
seq {
59-
let isUppercase = Char.IsUpper name.[0]
60-
for char in name do
61-
if isUppercase <> Char.IsUpper char then
62-
yield builder.ToString()
63-
builder.Clear() |> ignore<StringBuilder>
64-
builder.Append char |> ignore<StringBuilder>
65-
if builder.Length > 0 then
66-
yield builder.ToString()
65+
for (start, finish) in Seq.pairwise partitionPoints do
66+
yield name.Substring(start, finish - start)
6767
}
6868

6969
let private convertAllToCase (caseMapping: string -> string) (underscoresConfig: Option<NamingUnderscores>) (ident:Ident) =

0 commit comments

Comments
 (0)