Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: pkg/webdriver/base64decoder.dart

Issue 11301046: Restructure pkg/unittest and pkg/webdriver to follow the pub conventions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /**
2 * A simple base64 decoder class, used to decode web browser screenshots
3 * returned by WebDriver.
4 */
5 class Base64Decoder {
6
7 static int getVal(String s, pos) {
8 int code = s.charCodeAt(pos);
9 if (code >= 65 && code < (65+26)) { // 'A'..'Z'
10 return code - 65;
11 } else if (code >= 97 && code < (97+26)) { // 'a'..'z'
12 return code - 97 + 26;
13 } else if (code >= 48 && code < (48+10)) { // '0'..'9'
14 return code - 48 + 52;
15 } else if (code == 43) { // '+'
16 return 62;
17 } else if (code == 47) { // '/'
18 return 63;
19 } else {
20 throw 'Invalid character $s';
21 }
22 }
23
24 static List<int> decode(String s) {
25 var rtn = new List<int>();
26 var pos = 0;
27 while (pos < s.length) {
28 if (s[pos+2] =='=') { // Single byte as two chars.
29 int v = (getVal(s, pos) << 18 ) | (getVal(s, pos+1) << 12 );
30 rtn.add((v >> 16) & 0xff);
31 break;
32 } else if (s[pos+3] == '=') { // Two bytes as 3 chars.
33 int v = (getVal(s, pos) << 18 ) | (getVal(s, pos+1) << 12 ) |
34 (getVal(s, pos + 2) << 6);
35 rtn.add((v >> 16) & 0xff);
36 rtn.add((v >> 8) & 0xff);
37 break;
38 } else { // Three bytes as 4 chars.
39 int v = (getVal(s, pos) << 18 ) | (getVal(s, pos+1) << 12 ) |
40 (getVal(s, pos + 2) << 6) | getVal(s, pos+3);
41 pos += 4;
42 rtn.add((v >> 16 ) & 0xff);
43 rtn.add((v >> 8) & 0xff);
44 rtn.add(v & 0xff);
45 }
46 }
47 return rtn;
48 }
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698