2015-11-10 11:50:38 +00:00
|
|
|
// Copyright (c) 2015 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-CHROMIUM file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/win/scoped_hstring.h"
|
2015-11-10 11:50:38 +00:00
|
|
|
|
|
|
|
#include <winstring.h>
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-10-24 10:49:10 +00:00
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
ScopedHString::ScopedHString(const wchar_t* source) {
|
2015-11-24 07:11:43 +00:00
|
|
|
Reset(source);
|
2015-11-10 11:50:38 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
ScopedHString::ScopedHString(const std::wstring& source) {
|
2015-11-24 07:11:43 +00:00
|
|
|
Reset(source);
|
2015-11-10 12:07:12 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
ScopedHString::ScopedHString() {}
|
2015-11-10 11:50:38 +00:00
|
|
|
|
|
|
|
ScopedHString::~ScopedHString() {
|
2015-11-24 07:11:43 +00:00
|
|
|
Reset();
|
2015-11-10 11:50:38 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 07:11:43 +00:00
|
|
|
void ScopedHString::Reset() {
|
2015-11-10 11:50:38 +00:00
|
|
|
if (str_) {
|
|
|
|
WindowsDeleteString(str_);
|
|
|
|
str_ = nullptr;
|
|
|
|
}
|
2015-11-24 07:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScopedHString::Reset(const wchar_t* source) {
|
|
|
|
Reset();
|
2015-11-10 11:50:38 +00:00
|
|
|
WindowsCreateString(source, wcslen(source), &str_);
|
|
|
|
}
|
2015-11-24 07:11:43 +00:00
|
|
|
|
|
|
|
void ScopedHString::Reset(const std::wstring& source) {
|
|
|
|
Reset();
|
|
|
|
WindowsCreateString(source.c_str(), source.length(), &str_);
|
|
|
|
}
|
2018-10-24 10:49:10 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|