| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of webdriver; | |
| 6 | |
| 7 /** | |
| 8 * A simple base64 decoder class, used to decode web browser screenshots | |
| 9 * returned by WebDriver. | |
| 10 */ | |
| 11 class Base64Decoder { | |
| 12 | |
| 13 static int getVal(String s, pos) { | |
| 14 int code = s.codeUnitAt(pos); | |
| 15 if (code >= 65 && code < (65+26)) { // 'A'..'Z' | |
| 16 return code - 65; | |
| 17 } else if (code >= 97 && code < (97+26)) { // 'a'..'z' | |
| 18 return code - 97 + 26; | |
| 19 } else if (code >= 48 && code < (48+10)) { // '0'..'9' | |
| 20 return code - 48 + 52; | |
| 21 } else if (code == 43) { // '+' | |
| 22 return 62; | |
| 23 } else if (code == 47) { // '/' | |
| 24 return 63; | |
| 25 } else { | |
| 26 throw 'Invalid character $s'; | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 static List<int> decode(String s) { | |
| 31 var rtn = new List<int>(); | |
| 32 var pos = 0; | |
| 33 while (pos < s.length) { | |
| 34 if (s[pos+2] =='=') { // Single byte as two chars. | |
| 35 int v = (getVal(s, pos) << 18 ) | (getVal(s, pos+1) << 12 ); | |
| 36 rtn.add((v >> 16) & 0xff); | |
| 37 break; | |
| 38 } else if (s[pos+3] == '=') { // Two bytes as 3 chars. | |
| 39 int v = (getVal(s, pos) << 18 ) | (getVal(s, pos+1) << 12 ) | | |
| 40 (getVal(s, pos + 2) << 6); | |
| 41 rtn.add((v >> 16) & 0xff); | |
| 42 rtn.add((v >> 8) & 0xff); | |
| 43 break; | |
| 44 } else { // Three bytes as 4 chars. | |
| 45 int v = (getVal(s, pos) << 18 ) | (getVal(s, pos+1) << 12 ) | | |
| 46 (getVal(s, pos + 2) << 6) | getVal(s, pos+3); | |
| 47 pos += 4; | |
| 48 rtn.add((v >> 16 ) & 0xff); | |
| 49 rtn.add((v >> 8) & 0xff); | |
| 50 rtn.add(v & 0xff); | |
| 51 } | |
| 52 } | |
| 53 return rtn; | |
| 54 } | |
| 55 } | |
| OLD | NEW |