flutter_flutter/shell/platform/darwin/common/string_conversions.mm
Adam Barth b1c0ea79ca Switch engine over to platform messages (#3153)
This patch removes the use of the host messages mojom and switch all
message routing over to platform messages.
2016-10-19 22:36:00 -07:00

26 lines
892 B
Plaintext

// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/darwin/common/string_conversions.h"
namespace shell {
std::vector<uint8_t> GetVectorFromNSString(NSString* string) {
if (!string.length)
return std::vector<uint8_t>();
const char* chars = string.UTF8String;
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(chars);
return std::vector<uint8_t>(bytes, bytes + strlen(chars));
}
NSString* GetNSStringFromVector(const std::vector<uint8_t>& buffer) {
NSString* string = [[NSString alloc] initWithBytes:buffer.data()
length:buffer.size()
encoding:NSUTF8StringEncoding];
[string autorelease];
return string;
}
} // namespace shell