Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/FSharp.Data.Html.Core/HtmlCssSelectors.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,18 @@ module internal HtmlCssSelectors =
| c -> failwithf "Invalid css selector syntax at: %s" (new String(Array.ofList c))

let (|StartsWith|_|) (s: string) (items: char list) =
let candidates = s.ToCharArray()

if items.Length < candidates.Length then
if items.Length < s.Length then
None
else
let start = items |> Seq.take (candidates.Length) |> Seq.toList
let start = items |> Seq.take s.Length

if (Seq.compareWith (fun a b -> (int a) - (int b)) start candidates) = 0 then
if (Seq.compareWith (fun a b -> (int a) - (int b)) start s) = 0 then
Some(items |> Seq.skip s.Length |> Seq.toList)
else
None

let (|TokenStr|_|) (s: string) x =
let chars = s.ToCharArray() |> Array.toList
let chars = List.ofSeq s

let rec equal x s =
match x, s with
Expand Down Expand Up @@ -208,7 +206,7 @@ module internal HtmlCssSelectors =

member public x.Tokenize(pCssSelector: string) =
cssSelector <- pCssSelector
source <- cssSelector.ToCharArray() |> Array.toList
source <- List.ofSeq cssSelector
charCount <- source.Length
tokenize ()

Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Data.Html.Core/HtmlOperations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ module HtmlNode =
let selectedNodes =
filterByAttr level acc name (fun v ->
let chars =
v.ToCharArray()
v
|> Seq.skipWhile (fun c -> c = '\'')
|> Seq.takeWhile Char.IsLetter
|> Seq.toArray
Expand Down
5 changes: 4 additions & 1 deletion src/FSharp.Data.Html.Core/HtmlParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,10 @@ module internal HtmlParser =
parse' docType elements expectedTagEnd parentTagName (TagEnd expectedTagEnd :: tokens)
| TagEnd name :: rest when
name <> expectedTagEnd
&& (name <> (new String(expectedTagEnd.ToCharArray() |> Array.rev)))
&& (name
<> (new String(
Array.init expectedTagEnd.Length (fun i -> expectedTagEnd.[expectedTagEnd.Length - 1 - i])
)))
->
// ignore this token if not the expected end tag (or it's reverse, eg: <li></il>)
parse' docType elements expectedTagEnd parentTagName rest
Expand Down
13 changes: 8 additions & 5 deletions src/FSharp.Data.Runtime.Utilities/TextConversions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ type TextConversions private () =
// No adorners found, return original string to avoid allocation
value
else
// Adorners found, perform filtering
String(
value.ToCharArray()
|> Array.filter (not << TextConversions.DefaultRemovableAdornerCharacters.Contains)
)
// Adorners found, perform filtering via StringBuilder to avoid ToCharArray allocation
let sb = System.Text.StringBuilder(value.Length)

for c in value do
if not (TextConversions.DefaultRemovableAdornerCharacters.Contains(c)) then
sb.Append(c) |> ignore

sb.ToString()

/// Turns empty or null string value into None, otherwise returns Some
static member AsString str =
Expand Down
Loading