forked from winsiderss/systeminformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_std.cpp
More file actions
73 lines (62 loc) · 1.98 KB
/
Copy pathformat_std.cpp
File metadata and controls
73 lines (62 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Process Hacker -
* string formatting
*
* Copyright (C) 2020 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include <phbase.h>
#include <charconv>
using namespace std;
_Success_(return)
BOOLEAN PhFormatDoubleToUtf8(
_In_ DOUBLE Value,
_In_ ULONG Type,
_In_ ULONG Precision,
_Out_writes_bytes_opt_(BufferLength) PSTR Buffer,
_In_opt_ SIZE_T BufferLength,
_Out_opt_ PSIZE_T ReturnLength
)
{
chars_format format = chars_format::fixed;
to_chars_result result;
SIZE_T returnLength;
CHAR buffer[_CVTBUFSIZE + 1];
if (Type & FormatStandardForm)
format = chars_format::general;
else if (Type & FormatHexadecimalForm)
format = chars_format::hex;
result = to_chars(
buffer,
end(buffer),
Value,
format,
Precision
);
if (result.ec == errc::value_too_large)
return FALSE;
returnLength = result.ptr - buffer;
if (returnLength == 0)
return FALSE;
// This could be removed in favor of directly passing the input buffer to std:to_chars but
// for now use memcpy so that failures writing a value don't touch the input buffer (dmex)
memcpy_s(Buffer, BufferLength, buffer, returnLength);
Buffer[returnLength] = ANSI_NULL;
if (ReturnLength)
*ReturnLength = returnLength;
return TRUE;
}