Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
f529afa6
Unverified
Commit
f529afa6
authored
Jun 30, 2019
by
Charles Milette
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use stack allocated space when possible
parent
3bcd3cef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
12 deletions
+20
-12
include/spdlog/details/os-inl.h
include/spdlog/details/os-inl.h
+15
-9
include/spdlog/details/os.h
include/spdlog/details/os.h
+1
-1
include/spdlog/logger.h
include/spdlog/logger.h
+4
-2
No files found.
include/spdlog/details/os-inl.h
View file @
f529afa6
...
...
@@ -348,7 +348,9 @@ SPDLOG_INLINE void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
SPDLOG_INLINE
std
::
string
filename_to_str
(
const
filename_t
&
filename
)
{
return
wstr_to_str
(
filename
);
fmt
::
memory_buffer
buf
;
wstr_to_utf8buf
(
filename
,
buf
);
return
fmt
::
to_string
(
buf
);
}
#else
SPDLOG_INLINE
std
::
string
filename_to_str
(
const
filename_t
&
filename
)
...
...
@@ -402,7 +404,7 @@ SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
}
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
SPDLOG_INLINE
std
::
string
wstr_to_str
(
basic_string_view_t
<
wchar_t
>
wstr
)
SPDLOG_INLINE
void
wstr_to_utf8buf
(
basic_string_view_t
<
wchar_t
>
wstr
,
fmt
::
memory_buffer
&
target
)
{
if
(
wstr
.
size
()
>
static_cast
<
size_t
>
(
std
::
numeric_limits
<
int
>::
max
()))
{
...
...
@@ -412,21 +414,25 @@ SPDLOG_INLINE std::string wstr_to_str(basic_string_view_t<wchar_t> wstr)
int
wstr_size
=
static_cast
<
int
>
(
wstr
.
size
());
if
(
wstr_size
==
0
)
{
return
{
};
target
.
resize
(
0
);
return
;
}
int
result_size
=
::
WideCharToMultiByte
(
CP_UTF8
,
0
,
wstr
.
data
(),
wstr_size
,
NULL
,
0
,
NULL
,
NULL
);
int
result_size
=
target
.
capacity
();
if
((
wstr_size
+
1
)
*
2
>
result_size
)
{
result_size
=
::
WideCharToMultiByte
(
CP_UTF8
,
0
,
wstr
.
data
(),
wstr_size
,
NULL
,
0
,
NULL
,
NULL
);
}
if
(
result_size
>
0
)
{
std
::
string
result
;
result
.
resize
(
result_size
);
result_size
=
::
WideCharToMultiByte
(
CP_UTF8
,
0
,
wstr
.
data
(),
wstr_size
,
&
result
[
0
],
result_size
,
NULL
,
NULL
);
target
.
resize
(
result_size
);
result_size
=
::
WideCharToMultiByte
(
CP_UTF8
,
0
,
wstr
.
data
(),
wstr_size
,
target
.
data
(),
result_size
,
NULL
,
NULL
);
if
(
result_size
>
0
)
{
resul
t
.
resize
(
result_size
);
return
result
;
targe
t
.
resize
(
result_size
);
return
;
}
}
...
...
include/spdlog/details/os.h
View file @
f529afa6
...
...
@@ -81,7 +81,7 @@ bool is_color_terminal() SPDLOG_NOEXCEPT;
bool
in_terminal
(
FILE
*
file
)
SPDLOG_NOEXCEPT
;
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
std
::
string
wstr_to_str
(
basic_string_view_t
<
wchar_t
>
wstr
);
void
wstr_to_utf8buf
(
basic_string_view_t
<
wchar_t
>
wstr
,
fmt
::
memory_buffer
&
target
);
#endif
}
// namespace os
...
...
include/spdlog/logger.h
View file @
f529afa6
...
...
@@ -244,8 +244,10 @@ public:
fmt
::
wmemory_buffer
wbuf
;
fmt
::
format_to
(
wbuf
,
fmt
,
args
...);
const
auto
payload
=
details
::
os
::
wstr_to_str
({
wbuf
.
data
(),
wbuf
.
size
()
});
details
::
log_msg
log_msg
(
source
,
name_
,
lvl
,
payload
);
fmt
::
memory_buffer
buf
;
details
::
os
::
wstr_to_utf8buf
(
basic_string_view_t
<
wchar_t
>
(
wbuf
.
data
(),
wbuf
.
size
()),
buf
);
details
::
log_msg
log_msg
(
source
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
sink_it_
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment