OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <stdint.h> |
| 6 |
5 #include <string> | 7 #include <string> |
6 | 8 |
7 #include "ios/web/navigation/nscoder_util.h" | 9 #include "ios/web/navigation/nscoder_util.h" |
8 | 10 |
9 namespace web { | 11 namespace web { |
10 namespace nscoder_util { | 12 namespace nscoder_util { |
11 | 13 |
12 void EncodeString(NSCoder* coder, NSString* key, const std::string& string) { | 14 void EncodeString(NSCoder* coder, NSString* key, const std::string& string) { |
13 [coder encodeBytes:reinterpret_cast<const uint8_t*>(string.data()) | 15 [coder encodeBytes:reinterpret_cast<const uint8_t*>(string.data()) |
14 length:string.size() | 16 length:string.size() |
15 forKey:key]; | 17 forKey:key]; |
16 } | 18 } |
17 | 19 |
18 std::string DecodeString(NSCoder* decoder, NSString* key) { | 20 std::string DecodeString(NSCoder* decoder, NSString* key) { |
19 NSUInteger length = 0; | 21 NSUInteger length = 0; |
20 const uint8_t* bytes = [decoder decodeBytesForKey:key returnedLength:&length]; | 22 const uint8_t* bytes = [decoder decodeBytesForKey:key returnedLength:&length]; |
21 return std::string(reinterpret_cast<const char*>(bytes), length); | 23 return std::string(reinterpret_cast<const char*>(bytes), length); |
22 } | 24 } |
23 | 25 |
24 } // namespace nscoder_util | 26 } // namespace nscoder_util |
25 } // namespace web | 27 } // namespace web |
OLD | NEW |