scoped_hstring.cc 895 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2015 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-CHROMIUM file.
  4. #include "shell/browser/win/scoped_hstring.h"
  5. #include <winstring.h>
  6. namespace electron {
  7. ScopedHString::ScopedHString(const wchar_t* source) {
  8. Reset(source);
  9. }
  10. ScopedHString::ScopedHString(const std::wstring& source) {
  11. Reset(source);
  12. }
  13. ScopedHString::ScopedHString() = default;
  14. ScopedHString::~ScopedHString() {
  15. Reset();
  16. }
  17. void ScopedHString::Reset() {
  18. if (str_) {
  19. WindowsDeleteString(str_);
  20. str_ = nullptr;
  21. }
  22. }
  23. void ScopedHString::Reset(const wchar_t* source) {
  24. Reset();
  25. WindowsCreateString(source, wcslen(source), &str_);
  26. }
  27. void ScopedHString::Reset(const std::wstring& source) {
  28. Reset();
  29. WindowsCreateString(source.c_str(), source.length(), &str_);
  30. }
  31. } // namespace electron