Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
utils_win.h
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_UTILS_WIN_H_
6#define RUNTIME_BIN_UTILS_WIN_H_
7
8#include <memory>
9#include <utility>
10
11#include "platform/utils.h"
12
13#include "platform/allocation.h"
14
15#define MAX_LONG_PATH 32767
16
17namespace dart {
18namespace bin {
19
20void FormatMessageIntoBuffer(DWORD code, wchar_t* buffer, int buffer_length);
21
22// Convert from milliseconds since the Unix epoch to a FILETIME.
24
25// These string utility functions return strings that have been allocated with
26// Dart_ScopeAllocate(). They should be used only when we are inside an API
27// scope. If a string returned by one of these functions must persist beyond
28// the scope, then copy the results into a suitable buffer that you have
29// allocated.
31 public:
32 static char* WideToUtf8(wchar_t* wide,
33 intptr_t len = -1,
34 intptr_t* result_len = nullptr);
35 static const char* WideToUtf8(const wchar_t* wide,
36 intptr_t len = -1,
37 intptr_t* result_len = nullptr);
38 static wchar_t* Utf8ToWide(char* utf8,
39 intptr_t len = -1,
40 intptr_t* result_len = nullptr);
41 static const wchar_t* Utf8ToWide(const char* utf8,
42 intptr_t len = -1,
43 intptr_t* result_len = nullptr);
44
45 private:
46 DISALLOW_ALLOCATION();
48};
49
50// These scopes provide strings converted as indicated by the scope names.
51// The provided strings are allocated with 'malloc' and have the same lifetime
52// as the scope.
54 public:
55 explicit WideToUtf8Scope(const wchar_t* wide)
56 : utf8_(Utils::CreateCStringUniquePtr(nullptr)) {
57 intptr_t utf8_len =
58 WideCharToMultiByte(CP_UTF8, 0, wide, -1, nullptr, 0, nullptr, nullptr);
59 char* utf8 = reinterpret_cast<char*>(malloc(utf8_len));
60 WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, utf8_len, nullptr, nullptr);
61 length_ = utf8_len;
63 }
64
65 char* utf8() const { return utf8_.get(); }
66 intptr_t length() const { return length_; }
67
68 // Release the ownership of the converted string and return it.
69 Utils::CStringUniquePtr release() { return std::move(utf8_); }
70
71 private:
72 intptr_t length_;
74
75 DISALLOW_ALLOCATION();
77};
78
79std::unique_ptr<wchar_t[]> Utf8ToWideChar(const char* path);
80
81} // namespace bin
82} // namespace dart
83
84#endif // RUNTIME_BIN_UTILS_WIN_H_
static CStringUniquePtr CreateCStringUniquePtr(char *str)
Definition utils.cc:257
std::unique_ptr< char, decltype(std::free) * > CStringUniquePtr
Definition utils.h:644
static const wchar_t * Utf8ToWide(const char *utf8, intptr_t len=-1, intptr_t *result_len=nullptr)
static const char * WideToUtf8(const wchar_t *wide, intptr_t len=-1, intptr_t *result_len=nullptr)
static char * WideToUtf8(wchar_t *wide, intptr_t len=-1, intptr_t *result_len=nullptr)
static wchar_t * Utf8ToWide(char *utf8, intptr_t len=-1, intptr_t *result_len=nullptr)
intptr_t length() const
Definition utils_win.h:66
Utils::CStringUniquePtr release()
Definition utils_win.h:69
WideToUtf8Scope(const wchar_t *wide)
Definition utils_win.h:55
static const uint8_t buffer[]
std::unique_ptr< wchar_t[]> Utf8ToWideChar(const char *path)
FILETIME GetFiletimeFromMillis(int64_t millis)
void FormatMessageIntoBuffer(DWORD code, wchar_t *buffer, int buffer_length)
void * malloc(size_t size)
Definition allocation.cc:19
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition globals.h:593
struct _FILETIME FILETIME
unsigned long DWORD