forked from client9/stringencoders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodp_bjavascript_gen.c
58 lines (49 loc) · 1.36 KB
/
modp_bjavascript_gen.c
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
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
/* vi: set expandtab shiftwidth=4 tabstop=4: */
#include "arraytoc.h"
void hexencodemap()
{
static const char sHexChars[] = "0123456789ABCDEF";
int i;
char hexEncode1[256];
char hexEncode2[256];
for (i = 0; i < 256; ++i) {
hexEncode1[i] = sHexChars[i >> 4];
hexEncode2[i] = sHexChars[i & 0x0f];
}
char_array_to_c(hexEncode1, 256, "gsHexEncodeMap1");
char_array_to_c(hexEncode2, 256, "gsHexEncodeMap2");
}
void jsencodemap()
{
int i;
char jsEncodeMap[256];
// set everything to "as is"
for (i = 0; i < 256; ++i) {
jsEncodeMap[i] = 0;
}
// chars that need hex escaping
for (i = 0; i < 32; ++i) {
jsEncodeMap[i] = 'A';
}
for (i = 127; i < 256; ++i) {
jsEncodeMap[i] = 'A';
}
// items that have special escaping
jsEncodeMap[0x08] = 'b';
jsEncodeMap[0x09] = 't';
jsEncodeMap[0x0a] = 'n';
jsEncodeMap[0x0b] = 'v';
jsEncodeMap[0x0c] = 'f';
jsEncodeMap[0x0d] = 'r';
jsEncodeMap[0x5c] = '\\'; /* blackslash gets escaped */
jsEncodeMap[0x22] = '"'; /* dquote gets escaped */
jsEncodeMap[0x27] = '\''; /* squote gets escaped */
char_array_to_c(jsEncodeMap, 256, "gsJavascriptEncodeMap");
};
int main()
{
jsencodemap();
hexencodemap();
return 0;
}