aboutsummaryrefslogtreecommitdiff
path: root/c/wcharptr.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-06 01:27:42 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-06 01:30:21 +0200
commit86a0cec08f11de875d25012e5b251a91739ce06c (patch)
tree85e017eaae5906e12116f0f135455e226a4f936d /c/wcharptr.cpp
parentb6c520120626dc0dd652c05ae19414b1f5393338 (diff)
downloadEpisodeBrowser-86a0cec08f11de875d25012e5b251a91739ce06c.tar.gz
Rearrange source.
Diffstat (limited to 'c/wcharptr.cpp')
-rw-r--r--c/wcharptr.cpp61
1 files changed, 31 insertions, 30 deletions
diff --git a/c/wcharptr.cpp b/c/wcharptr.cpp
index 25ddae1..d1332d5 100644
--- a/c/wcharptr.cpp
+++ b/c/wcharptr.cpp
@@ -4,8 +4,39 @@
#include "wcharptr.h"
#include "win.h"
+WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp)
+{
+ int cbMultiByte = strlen(src)+1;
+ int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, nullptr, 0);
+ wchar_t* dst = new wchar_t[cchWideChar];
+ if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) {
+ delete dst;
+ throw Win32Error();
+ }
+ return dst;
+}
+
+WcharPtr WcharPtr::Copy(const wchar_t* const src)
+{
+ const int cb = wcslen(src)+1;
+ wchar_t* dst = new wchar_t[cb];
+ memcpy(dst, src, cb*sizeof(wchar_t));
+ return dst;
+}
+
+
WcharPtr::WcharPtr() noexcept {}
+WcharPtr::~WcharPtr() noexcept
+{
+ delete m_p;
+}
+
+WcharPtr::operator wchar_t*() noexcept
+{
+ return m_p;
+}
+
WcharPtr::WcharPtr(wchar_t* const s) noexcept : m_p(s) {}
WcharPtr& WcharPtr::operator=(wchar_t* const s) noexcept
@@ -26,39 +57,9 @@ WcharPtr& WcharPtr::operator=(WcharPtr&& other) noexcept
return *this;
}
-WcharPtr::operator wchar_t*() noexcept
-{
- return m_p;
-}
-
wchar_t* WcharPtr::Release() noexcept
{
wchar_t* p2 = m_p;
m_p = nullptr;
return p2;
}
-
-WcharPtr::~WcharPtr() noexcept
-{
- delete m_p;
-}
-
-WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp)
-{
- int cbMultiByte = strlen(src)+1;
- int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, nullptr, 0);
- wchar_t* dst = new wchar_t[cchWideChar];
- if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) {
- delete dst;
- throw Win32Error();
- }
- return dst;
-}
-
-WcharPtr WcharPtr::Copy(const wchar_t* const src)
-{
- const int cb = wcslen(src)+1;
- wchar_t* dst = new wchar_t[cb];
- memcpy(dst, src, cb*sizeof(wchar_t));
- return dst;
-}