more code
This commit is contained in:
parent
67ff51521b
commit
a3cf2d87a6
3 changed files with 28 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
|||
namespace Pentole
|
||||
|
||||
/// The initially opened module.
|
||||
[<AutoOpen>]
|
||||
module Pervasives =
|
||||
|
||||
|
@ -7,3 +8,10 @@ module Pervasives =
|
|||
/// The identity function.
|
||||
/// </summary>
|
||||
let identity = id
|
||||
|
||||
/// An active pattern that matches strings starting with a specified prefix.
|
||||
let (|Prefix|_|) (p: string) (s: string) =
|
||||
if s.StartsWith p then
|
||||
s.Substring p.Length |> Some
|
||||
else
|
||||
None
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
module Pentole.String
|
||||
namespace Pentole
|
||||
|
||||
let split (separator: string) (target: string) : string list =
|
||||
if System.String.IsNullOrEmpty separator then
|
||||
[target]
|
||||
else
|
||||
let slen = separator.Length
|
||||
let rec split (acc: string list) (start_idx: int) =
|
||||
match target.IndexOf(separator, start_idx) with
|
||||
| -1 ->
|
||||
if start_idx < target.Length then
|
||||
target.Substring(start_idx) :: acc
|
||||
else acc
|
||||
| index ->
|
||||
let part = target.Substring (start_idx, index - start_idx)
|
||||
split (part :: acc) (index + slen)
|
||||
module String =
|
||||
|
||||
split [] 0 |> List.rev
|
||||
let split (separator: string) (target: string) : string list =
|
||||
if System.String.IsNullOrEmpty separator then
|
||||
[target]
|
||||
else
|
||||
let slen = separator.Length
|
||||
let rec split (acc: string list) (start_idx: int) =
|
||||
match target.IndexOf(separator, start_idx) with
|
||||
| -1 ->
|
||||
if start_idx < target.Length then
|
||||
target.Substring(start_idx) :: acc
|
||||
else acc
|
||||
| index ->
|
||||
let part = target.Substring (start_idx, index - start_idx)
|
||||
split (part :: acc) (index + slen)
|
||||
|
||||
split [] 0 |> List.rev
|
||||
|
|
|
@ -2,6 +2,8 @@ namespace Pentole
|
|||
|
||||
open NUnit.Framework
|
||||
|
||||
type TestAttribute = NUnit.Framework.TestAttribute
|
||||
|
||||
module Assert =
|
||||
let inline okEquals<'ok, 'err> (expected: 'ok) (got: Result<'ok, 'err>) =
|
||||
match got with
|
||||
|
|
Loading…
Reference in a new issue