PageSourceSearch

https://jvbib.com/js/base.js

js jvbib.com collected 2026-10-05 00:39:44 UTC 4,259 bytes, 150 lines download raw bytes

1var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2var base64DecodeChars = new Array(
3    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
5    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
6    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
7    -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
8    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
9    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
10    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1); 
11
12
13function base64encode(str) {
14    var out, i, len;
15    var c1, c2, c3;
16
17    len = str.length;
18    i = 0;
19    out = "";
20    while(i < len) {
21    c1 = str.charCodeAt(i++) & 0xff;
22    if(i == len)
23    {
24        out += base64EncodeChars.charAt(c1 >> 2);
25        out += base64EncodeChars.charAt((c1 & 0x3) << 4);
26        out += "==";
27        break;
28    }
29    c2 = str.charCodeAt(i++);
30    if(i == len)
31    {
32        out += base64EncodeChars.charAt(c1 >> 2);
33        out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
34        out += base64EncodeChars.charAt((c2 & 0xF) << 2);
35        out += "=";
36        break;
37    }
38    c3 = str.charCodeAt(i++);
39    out += base64EncodeChars.charAt(c1 >> 2);
40    out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
41    out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
42    out += base64EncodeChars.charAt(c3 & 0x3F);
43    }
44    return out;
45}
46
47function base64decode(str) {
48    var c1, c2, c3, c4;
49    var i, len, out;
50
51    len = str.length;
52    i = 0;
53    out = "";
54    while(i < len) {
55    /* c1 */
56    do {
57        c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
58    } while(i < len && c1 == -1);
59    if(c1 == -1)
60        break;
61
62    /* c2 */
63    do {
64        c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
65    } while(i < len && c2 == -1);
66    if(c2 == -1)
67        break;
68
69    out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
70
71    /* c3 */
72    do {
73        c3 = str.charCodeAt(i++) & 0xff;
74        if(c3 == 61)
75        return out;
76        c3 = base64DecodeChars[c3];
77    } while(i < len && c3 == -1);
78    if(c3 == -1)
79        break;
80
81    out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
82
83    /* c4 */
84    do {
85        c4 = str.charCodeAt(i++) & 0xff;
86        if(c4 == 61)
87        return out;
88        c4 = base64DecodeChars[c4];
89    } while(i < len && c4 == -1);
90    if(c4 == -1)
91        break;
92    out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
93    }
94    return out;
95}
96
97function utf16to8(str) {
98    var out, i, len, c;
99
100    out = "";
101    len = str.length;
102    for(i = 0; i < len; i++) {
103    c = str.charCodeAt(i);
104    if ((c >= 0x0001) && (c <= 0x007F)) {
105        out += str.charAt(i);
106    } else if (c > 0x07FF) {
107        out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
108        out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
109        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
110    } else {
111        out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
112        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
113    }
114    }
115    return out;
116}
117
118function utf8to16(str) {
119    var out, i, len, c;
120    var char2, char3;
121
122    out = "";
123    len = str.length;
124    i = 0;
125    while(i < len) {
126    c = str.charCodeAt(i++);
127    switch(c >> 4)
128    {
129      case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
130        // 0xxxxxxx
131        out += str.charAt(i-1);
132        break;
133      case 12: case 13:
134        // 110x xxxx   10xx xxxx
135        char2 = str.charCodeAt(i++);
136        out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
137        break;
138      case 14:
139        // 1110 xxxx 10xx xxxx 10xx xxxx
140        char2 = str.charCodeAt(i++);
141        char3 = str.charCodeAt(i++);
142        out += String.fromCharCode(((c & 0x0F) << 12) |
143                       ((char2 & 0x3F) << 6) |
144                       ((char3 & 0x3F) << 0));
145        break;
146    }
147    }
148
149    return out;
150}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.