Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
2d0798cd
Commit
2d0798cd
authored
Apr 03, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Win32: pass std::string_view
parent
a269fc98
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
12 deletions
+16
-12
CaseFold.cxx
src/lib/icu/CaseFold.cxx
+5
-3
Win32.cxx
src/lib/icu/Win32.cxx
+8
-6
Win32.hxx
src/lib/icu/Win32.hxx
+3
-3
No files found.
src/lib/icu/CaseFold.cxx
View file @
2d0798cd
...
...
@@ -81,13 +81,15 @@ try {
return
AllocatedString
<>::
Duplicate
(
src
);
std
::
unique_ptr
<
wchar_t
[]
>
buffer
(
new
wchar_t
[
size
]);
i
f
(
LCMapStringEx
(
LOCALE_NAME_INVARIANT
,
i
nt
result
=
LCMapStringEx
(
LOCALE_NAME_INVARIANT
,
LCMAP_SORTKEY
|
LINGUISTIC_IGNORECASE
,
u
.
c_str
(),
-
1
,
buffer
.
get
(),
size
,
nullptr
,
nullptr
,
0
)
<=
0
)
nullptr
,
nullptr
,
0
);
if
(
result
<=
0
)
return
AllocatedString
<>::
Duplicate
(
src
);
return
WideCharToMultiByte
(
CP_UTF8
,
buffer
.
get
());
return
WideCharToMultiByte
(
CP_UTF8
,
{
buffer
.
get
(),
size_t
(
result
-
1
)});
#else
#error not implemented
...
...
src/lib/icu/Win32.cxx
View file @
2d0798cd
...
...
@@ -26,15 +26,16 @@
#include <windows.h>
AllocatedString
<
char
>
WideCharToMultiByte
(
unsigned
code_page
,
const
wchar_t
*
src
)
WideCharToMultiByte
(
unsigned
code_page
,
std
::
wstring_view
src
)
{
int
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
,
-
1
,
nullptr
,
0
,
int
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
.
data
(),
src
.
size
(),
nullptr
,
0
,
nullptr
,
nullptr
);
if
(
length
<=
0
)
throw
MakeLastError
(
"Failed to convert from Unicode"
);
std
::
unique_ptr
<
char
[]
>
buffer
(
new
char
[
length
]);
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
,
-
1
,
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
.
data
(),
src
.
size
()
,
buffer
.
get
(),
length
,
nullptr
,
nullptr
);
if
(
length
<=
0
)
...
...
@@ -44,14 +45,15 @@ WideCharToMultiByte(unsigned code_page, const wchar_t *src)
}
AllocatedString
<
wchar_t
>
MultiByteToWideChar
(
unsigned
code_page
,
const
char
*
src
)
MultiByteToWideChar
(
unsigned
code_page
,
std
::
string_view
src
)
{
int
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
,
-
1
,
nullptr
,
0
);
int
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
.
data
(),
src
.
size
(),
nullptr
,
0
);
if
(
length
<=
0
)
throw
MakeLastError
(
"Failed to convert to Unicode"
);
std
::
unique_ptr
<
wchar_t
[]
>
buffer
(
new
wchar_t
[
length
]);
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
,
-
1
,
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
.
data
(),
src
.
size
()
,
buffer
.
get
(),
length
);
if
(
length
<=
0
)
throw
MakeLastError
(
"Failed to convert to Unicode"
);
...
...
src/lib/icu/Win32.hxx
View file @
2d0798cd
...
...
@@ -22,7 +22,7 @@
#include "util/Compiler.h"
#include <
wchar.h
>
#include <
string_view
>
template
<
typename
T
>
class
AllocatedString
;
...
...
@@ -31,13 +31,13 @@ template<typename T> class AllocatedString;
*/
gcc_pure
gcc_nonnull_all
AllocatedString
<
char
>
WideCharToMultiByte
(
unsigned
code_page
,
const
wchar_t
*
src
);
WideCharToMultiByte
(
unsigned
code_page
,
std
::
wstring_view
src
);
/**
* Throws std::system_error on error.
*/
gcc_pure
gcc_nonnull_all
AllocatedString
<
wchar_t
>
MultiByteToWideChar
(
unsigned
code_page
,
const
char
*
src
);
MultiByteToWideChar
(
unsigned
code_page
,
std
::
string_view
src
);
#endif
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