Home | History | Annotate | Download | only in mac
      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
      3 // found in the LICENSE file.
      4 
      5 #include <string>
      6 
      7 #include "chrome/common/mac/nscoder_util.h"
      8 
      9 namespace nscoder_util {
     10 
     11 void EncodeString(NSCoder* coder, NSString* key, const std::string& string) {
     12   [coder encodeBytes:reinterpret_cast<const uint8_t*>(string.data())
     13               length:string.size()
     14               forKey:key];
     15 }
     16 
     17 std::string DecodeString(NSCoder* decoder, NSString* key) {
     18   NSUInteger length;
     19   const uint8_t* bytes = [decoder decodeBytesForKey:key
     20                                      returnedLength:&length];
     21   return std::string(reinterpret_cast<const char*>(bytes), length);
     22 }
     23 
     24 }  // namespace nscoder_util
     25