Commit 22598482 authored by Max Kellermann's avatar Max Kellermann

lib/icu/Win32: use std::unique_ptr

parent 01b68db3
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "Win32.hxx" #include "Win32.hxx"
#include "util/AllocatedString.hxx" #include "util/AllocatedString.hxx"
#include <memory>
#include <windows.h> #include <windows.h>
AllocatedString<char> AllocatedString<char>
...@@ -31,15 +33,14 @@ WideCharToMultiByte(unsigned code_page, const wchar_t *src) ...@@ -31,15 +33,14 @@ WideCharToMultiByte(unsigned code_page, const wchar_t *src)
if (length <= 0) if (length <= 0)
return nullptr; return nullptr;
char *buffer = new char[length]; std::unique_ptr<char[]> buffer(new char[length]);
length = WideCharToMultiByte(code_page, 0, src, -1, buffer, length, length = WideCharToMultiByte(code_page, 0, src, -1,
buffer.get(), length,
nullptr, nullptr); nullptr, nullptr);
if (length <= 0) { if (length <= 0)
delete[] buffer;
return nullptr; return nullptr;
}
return AllocatedString<char>::Donate(buffer); return AllocatedString<char>::Donate(buffer.release());
} }
AllocatedString<wchar_t> AllocatedString<wchar_t>
...@@ -49,12 +50,11 @@ MultiByteToWideChar(unsigned code_page, const char *src) ...@@ -49,12 +50,11 @@ MultiByteToWideChar(unsigned code_page, const char *src)
if (length <= 0) if (length <= 0)
return nullptr; return nullptr;
wchar_t *buffer = new wchar_t[length]; std::unique_ptr<wchar_t[]> buffer(new wchar_t[length]);
length = MultiByteToWideChar(code_page, 0, src, -1, buffer, length); length = MultiByteToWideChar(code_page, 0, src, -1,
if (length <= 0) { buffer.get(), length);
delete[] buffer; if (length <= 0)
return nullptr; return nullptr;
}
return AllocatedString<wchar_t>::Donate(buffer); return AllocatedString<wchar_t>::Donate(buffer.release());
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment