OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkBase64.h" | 10 #include "SkBase64.h" |
11 | 11 |
12 #define DecodePad -2 | 12 #define DecodePad -2 |
13 #define EncodePad 64 | 13 #define EncodePad 64 |
14 | 14 |
15 static const char default_encode[] = | 15 static const char default_encode[] = |
16 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 16 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
17 "abcdefghijklmnopqrstuvwxyz" | 17 "abcdefghijklmnopqrstuvwxyz" |
18 "0123456789+/="; | 18 "0123456789+/="; |
19 | 19 |
20 static const signed char decodeData[] = { | 20 static const signed char decodeData[] = { |
21 62, -1, -1, -1, 63, | 21 62, -1, -1, -1, 63, |
22 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, DecodePad, -1, -1, | 22 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, DecodePad, -1, -1, |
23 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, | 23 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
24 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, | 24 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, |
25 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | 25 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
26 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 | 26 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 |
27 }; | 27 }; |
28 | 28 |
29 SkBase64::SkBase64() : fLength((size_t) -1), fData(NULL) { | 29 SkBase64::SkBase64() : fLength((size_t) -1), fData(nullptr) { |
30 } | 30 } |
31 | 31 |
32 #if defined _WIN32 && _MSC_VER >= 1300 // disable 'two', etc. may be used witho
ut having been initialized | 32 #if defined _WIN32 && _MSC_VER >= 1300 // disable 'two', etc. may be used witho
ut having been initialized |
33 #pragma warning ( push ) | 33 #pragma warning ( push ) |
34 #pragma warning ( disable : 4701 ) | 34 #pragma warning ( disable : 4701 ) |
35 #endif | 35 #endif |
36 | 36 |
37 SkBase64::Error SkBase64::decode(const void* srcPtr, size_t size, bool writeDest
ination) { | 37 SkBase64::Error SkBase64::decode(const void* srcPtr, size_t size, bool writeDest
ination) { |
38 unsigned char* dst = (unsigned char*) fData; | 38 unsigned char* dst = (unsigned char*) fData; |
39 const unsigned char* dstStart = (const unsigned char*) fData; | 39 const unsigned char* dstStart = (const unsigned char*) fData; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 fLength = dst - dstStart; | 104 fLength = dst - dstStart; |
105 return kNoError; | 105 return kNoError; |
106 } | 106 } |
107 | 107 |
108 #if defined _WIN32 && _MSC_VER >= 1300 | 108 #if defined _WIN32 && _MSC_VER >= 1300 |
109 #pragma warning ( pop ) | 109 #pragma warning ( pop ) |
110 #endif | 110 #endif |
111 | 111 |
112 size_t SkBase64::Encode(const void* srcPtr, size_t length, void* dstPtr, const c
har* encodeMap) { | 112 size_t SkBase64::Encode(const void* srcPtr, size_t length, void* dstPtr, const c
har* encodeMap) { |
113 const char* encode; | 113 const char* encode; |
114 if (NULL == encodeMap) { | 114 if (nullptr == encodeMap) { |
115 encode = default_encode; | 115 encode = default_encode; |
116 } else { | 116 } else { |
117 encode = encodeMap; | 117 encode = encodeMap; |
118 } | 118 } |
119 const unsigned char* src = (const unsigned char*) srcPtr; | 119 const unsigned char* src = (const unsigned char*) srcPtr; |
120 unsigned char* dst = (unsigned char*) dstPtr; | 120 unsigned char* dst = (unsigned char*) dstPtr; |
121 if (dst) { | 121 if (dst) { |
122 size_t remainder = length % 3; | 122 size_t remainder = length % 3; |
123 const unsigned char* end = &src[length - remainder]; | 123 const unsigned char* end = &src[length - remainder]; |
124 while (src < end) { | 124 while (src < end) { |
(...skipping 30 matching lines...) Expand all Loading... |
155 | 155 |
156 SkBase64::Error SkBase64::decode(const char* src, size_t len) { | 156 SkBase64::Error SkBase64::decode(const char* src, size_t len) { |
157 Error err = decode(src, len, false); | 157 Error err = decode(src, len, false); |
158 SkASSERT(err == kNoError); | 158 SkASSERT(err == kNoError); |
159 if (err != kNoError) | 159 if (err != kNoError) |
160 return err; | 160 return err; |
161 fData = new char[fLength]; // should use sk_malloc/sk_free | 161 fData = new char[fLength]; // should use sk_malloc/sk_free |
162 decode(src, len, true); | 162 decode(src, len, true); |
163 return kNoError; | 163 return kNoError; |
164 } | 164 } |
OLD | NEW |