forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncode.js
66 lines (53 loc) · 1.48 KB
/
Encode.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
if (WScript.arguments.length != 2) {
WScript.Echo("ERROR: Invalid number of argument");
WScript.Quit(-1);
}
var input = WScript.arguments(0);
var output = WScript.arguments(1);
var fso = WScript.CreateObject("Scripting.FileSystemObject");
try {
var f = fso.OpenTextFile(input, 1);
}
catch (e) {
WScript.Echo("ERROR: unable to open input file " + input);
WScript.Quit(-1);
}
var str = f.ReadAll();
f.Close();
if (str.length == 0) {
WScript.Echo("ERROR: input file is empty");
WScript.Quit(-1);
}
try {
var out = fso.OpenTextFile(output, 2, true, 0);
}
catch (e) {
WScript.Echo("ERROR: unable to open output file " + output);
WScript.Quit(-1);
}
function writeChar(c) {
var line = false;
if (c == "\\") {
c = "\\\\";
} else if (c == "'" || c == "\"") {
c = "\\" + c;
} else if (c == "\r") {
c = "\\r";
} else if (c == "\n") {
c = "\\n";
line = true;
}
out.Write("L'" + c + "'");
out.Write(",");
if (line) {
out.WriteLine("");
}
}
for (var i = 0; i < str.length; i++) {
writeChar(str.charAt(i));
}
out.Close();