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> | 5 #include <stdint.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ios/web/navigation/nscoder_util.h" | 9 #import "ios/web/navigation/nscoder_util.h" |
10 | 10 |
11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
12 #error "This file requires ARC support." | 12 #error "This file requires ARC support." |
13 #endif | 13 #endif |
14 | 14 |
15 namespace web { | 15 namespace web { |
16 namespace nscoder_util { | 16 namespace nscoder_util { |
17 | 17 |
18 void EncodeString(NSCoder* coder, NSString* key, const std::string& string) { | 18 void EncodeString(NSCoder* coder, NSString* key, const std::string& string) { |
19 [coder encodeBytes:reinterpret_cast<const uint8_t*>(string.data()) | 19 [coder encodeBytes:reinterpret_cast<const uint8_t*>(string.data()) |
20 length:string.size() | 20 length:string.size() |
21 forKey:key]; | 21 forKey:key]; |
22 } | 22 } |
23 | 23 |
24 std::string DecodeString(NSCoder* decoder, NSString* key) { | 24 std::string DecodeString(NSCoder* decoder, NSString* key) { |
25 NSUInteger length = 0; | 25 NSUInteger length = 0; |
26 const uint8_t* bytes = [decoder decodeBytesForKey:key returnedLength:&length]; | 26 const uint8_t* bytes = [decoder decodeBytesForKey:key returnedLength:&length]; |
27 return std::string(reinterpret_cast<const char*>(bytes), length); | 27 return std::string(reinterpret_cast<const char*>(bytes), length); |
28 } | 28 } |
29 | 29 |
30 } // namespace nscoder_util | 30 } // namespace nscoder_util |
31 } // namespace web | 31 } // namespace web |
OLD | NEW |