-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSerialize.Text.pq
More file actions
25 lines (25 loc) · 971 Bytes
/
Serialize.Text.pq
File metadata and controls
25 lines (25 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
let
/*
from: https://github.com/microsoft/DataConnectors/blob/master/samples/UnitTesting/UnitTesting.query.pq
*/
Serialize.Text = (x) => let
escapeText = (n as number) as text => "#(#)(" & Text.PadStart(Number.ToText(n, "X", "en-US"), 4, "0") & ")"
in
List.Accumulate(
List.Transform(
Text.ToList(x),
(c) => let n = Character.ToNumber(c) in
if n = 9 then "#(#)(tab)" else
if n = 10 then "#(#)(lf)" else
if n = 13 then "#(#)(cr)" else
if n = 34 then """""" else
if n = 35 then "#(#)(#)" else
if n < 32 then escapeText(n) else
if n < 127 then Character.FromNumber(n) else
escapeText(n)
),
"",
(s, i) => s & i
)
in
Serialize.Text