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