Skip to content

Commit 8f8b901

Browse files
webwarrior-wsknocte
authored andcommitted
Core(Naming): make last test pass
Regarding splitByCaseChange: a more complex case.
1 parent c7c454c commit 8f8b901

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ module QuickFixes =
6969
Some { FromText = ident.idText; FromRange = ident.idRange; ToText = camelCaseIdent })
7070

7171
let splitByCaseChange (name: string) : seq<string> =
72-
let builder = System.Text.StringBuilder()
72+
let partitionPoints =
73+
seq {
74+
yield 0
75+
for (index, (current, next)) in name |> Seq.pairwise |> Seq.indexed do
76+
if (Char.IsUpper next || not (Char.IsLetter next)) && not (Char.IsUpper current) then
77+
yield index + 1
78+
yield name.Length
79+
}
7380
seq {
74-
let isUppercase = Char.IsUpper name.[0]
75-
for char in name do
76-
if isUppercase <> Char.IsUpper char then
77-
yield builder.ToString()
78-
builder.Clear() |> ignore<StringBuilder>
79-
builder.Append char |> ignore<StringBuilder>
80-
if builder.Length > 0 then
81-
yield builder.ToString()
81+
for (start, finish) in Seq.pairwise partitionPoints do
82+
yield name.Substring(start, finish - start)
8283
}
8384

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

0 commit comments

Comments
 (0)