-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLuaUtils.pas
More file actions
43 lines (34 loc) · 800 Bytes
/
Copy pathLuaUtils.pas
File metadata and controls
43 lines (34 loc) · 800 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Unit LuaUtils;
{$mode ObjFPC}{$H+}
Interface
Uses
SysUtils;
Function EscapeString(Const S: AnsiString): AnsiString;
Implementation
Function EscapeString(Const S: AnsiString): AnsiString;
Var
i: Integer;
Function ByteEscape(B: Byte): AnsiString;
Begin
Result := '\' +
Chr(Ord('0') + (B div 100)) +
Chr(Ord('0') + ((B div 10) mod 10)) +
Chr(Ord('0') + (B mod 10));
End;
Begin
Result := '';
For i := 1 To Length(S) Do
Case S[i] Of
#10: Result += '\n';
#13: Result += '\r';
#9: Result += '\t';
'\': Result += '\\';
'"': Result += '\"';
Else
If (Ord(S[i]) < 32) Or (Ord(S[i]) > 126) Then
Result += ByteEscape(Ord(S[i]))
Else
Result += S[i];
End;
End;
End.