scoped_hstring.cc 891 B

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