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
a81c9bfb
Commit
a81c9bfb
authored
Jan 14, 2021
by
Max Kellermann
Committed by
Max Kellermann
Jan 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/AllocatedString: add string_view constructor
Replaces the static Duplicate() method.
parent
1caf5764
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
14 deletions
+18
-14
SidplayDecoderPlugin.cxx
src/decoder/plugins/SidplayDecoderPlugin.cxx
+1
-1
CaseFold.cxx
src/lib/icu/CaseFold.cxx
+3
-3
Compare.cxx
src/lib/icu/Compare.cxx
+1
-1
Converter.cxx
src/lib/icu/Converter.cxx
+2
-2
AllocatedString.hxx
src/util/AllocatedString.hxx
+11
-7
No files found.
src/decoder/plugins/SidplayDecoderPlugin.cxx
View file @
a81c9bfb
...
...
@@ -469,7 +469,7 @@ Windows1252ToUTF8(const char *s) noexcept
* Fallback to not transcoding windows-1252 to utf-8, that may result
* in invalid utf-8 unless nonprintable characters are replaced.
*/
auto
t
=
AllocatedString
::
Duplicate
(
s
);
AllocatedString
t
(
s
);
for
(
size_t
i
=
0
;
t
[
i
]
!=
AllocatedString
::
SENTINEL
;
i
++
)
if
(
!
IsPrintableASCII
(
t
[
i
]))
...
...
src/lib/icu/CaseFold.cxx
View file @
a81c9bfb
...
...
@@ -44,7 +44,7 @@ try {
#ifdef HAVE_ICU
const
auto
u
=
UCharFromUTF8
(
src
);
if
(
u
.
IsNull
())
return
AllocatedString
::
Duplicate
(
src
);
return
AllocatedString
(
src
);
AllocatedArray
<
UChar
>
folded
(
u
.
size
()
*
2U
);
...
...
@@ -54,7 +54,7 @@ try {
U_FOLD_CASE_DEFAULT
,
&
error_code
);
if
(
folded_length
==
0
||
error_code
!=
U_ZERO_ERROR
)
return
AllocatedString
::
Duplicate
(
src
);
return
AllocatedString
(
src
);
folded
.
SetSize
(
folded_length
);
return
UCharToUTF8
({
folded
.
begin
(),
folded
.
size
()});
...
...
@@ -63,7 +63,7 @@ try {
#error not implemented
#endif
}
catch
(...)
{
return
AllocatedString
::
Duplicate
(
src
);
return
AllocatedString
(
src
);
}
#endif
/* HAVE_ICU_CASE_FOLD */
src/lib/icu/Compare.cxx
View file @
a81c9bfb
...
...
@@ -46,7 +46,7 @@ IcuCompare::IcuCompare(std::string_view _needle) noexcept
#else
IcuCompare
::
IcuCompare
(
std
::
string_view
_needle
)
noexcept
:
needle
(
AllocatedString
::
Duplicate
(
_needle
)
)
{}
:
needle
(
_needle
)
{}
#endif
...
...
src/lib/icu/Converter.cxx
View file @
a81c9bfb
...
...
@@ -95,7 +95,7 @@ DoConvert(iconv_t conv, std::string_view src)
if
(
in_left
>
0
)
throw
std
::
runtime_error
(
"Charset conversion failed"
);
return
AllocatedString
::
Duplicate
({
buffer
,
sizeof
(
buffer
)
-
out_left
});
return
AllocatedString
({
buffer
,
sizeof
(
buffer
)
-
out_left
});
}
#endif
...
...
@@ -151,7 +151,7 @@ IcuConverter::FromUTF8(std::string_view s) const
throw
std
::
runtime_error
(
FormatString
(
"Failed to convert from Unicode: %s"
,
u_errorName
(
code
)).
c_str
());
return
AllocatedString
::
Duplicate
({
buffer
,
size_t
(
target
-
buffer
)});
return
AllocatedString
({
buffer
,
size_t
(
target
-
buffer
)});
#elif defined(HAVE_ICONV)
return
DoConvert
(
from_utf8
,
s
);
...
...
src/util/AllocatedString.hxx
View file @
a81c9bfb
...
...
@@ -65,6 +65,9 @@ public:
BasicAllocatedString
(
std
::
nullptr_t
n
)
noexcept
:
value
(
n
)
{}
explicit
BasicAllocatedString
(
string_view
src
)
noexcept
:
value
(
Duplicate
(
src
))
{}
BasicAllocatedString
(
BasicAllocatedString
&&
src
)
noexcept
:
value
(
src
.
Steal
())
{}
...
...
@@ -86,12 +89,6 @@ public:
return
Donate
(
p
);
}
static
BasicAllocatedString
Duplicate
(
string_view
src
)
{
auto
p
=
new
value_type
[
src
.
size
()
+
1
];
*
std
::
copy_n
(
src
.
data
(),
src
.
size
(),
p
)
=
SENTINEL
;
return
Donate
(
p
);
}
BasicAllocatedString
&
operator
=
(
BasicAllocatedString
&&
src
)
noexcept
{
std
::
swap
(
value
,
src
.
value
);
return
*
this
;
...
...
@@ -138,7 +135,14 @@ public:
}
BasicAllocatedString
Clone
()
const
{
return
Duplicate
(
*
this
);
return
BasicAllocatedString
(
Duplicate
(
*
this
));
}
private
:
static
pointer
Duplicate
(
string_view
src
)
{
auto
p
=
new
value_type
[
src
.
size
()
+
1
];
*
std
::
copy_n
(
src
.
data
(),
src
.
size
(),
p
)
=
SENTINEL
;
return
p
;
}
};
...
...
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