1 people like it.
Like the snippet!
escaping string
escaping string, very terse . Update: a bit more terse, and perf improvement by using .ToCharArray() and Array.iter
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
|
let internal escape_char (c:char) : bool * string =
match c with
| '\r' -> true, "\\r"
| '\n' -> true, "\\n"
| '\t' -> true, "\\t"
| '"' -> true, "\\\""
| _ -> false, null
let internal escape_string (str:string) =
let buf = new StringBuilder(str.Length)
for c in str do
match escape_char c with
| true, s -> buf.Append s |> ignore
| false, _ -> buf.Append c |> ignore
buf.ToString()
|
val internal escape_char : c:char -> bool * string
Full name: Script.escape_char
val c : char
Multiple items
val char : value:'T -> char (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.char
--------------------
type char = System.Char
Full name: Microsoft.FSharp.Core.char
type bool = System.Boolean
Full name: Microsoft.FSharp.Core.bool
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
val internal escape_string : str:string -> string
Full name: Script.escape_string
val str : string
val buf : obj
property System.String.Length: int
val s : string
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
System.Object.ToString() : string
More information