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
8e71130e
Commit
8e71130e
authored
Oct 13, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag/FixString: use class AllocatedArray
parent
ed7baf3a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
25 deletions
+21
-25
Builder.cxx
src/tag/Builder.cxx
+2
-4
FixString.cxx
src/tag/FixString.cxx
+17
-19
FixString.hxx
src/tag/FixString.hxx
+2
-2
No files found.
src/tag/Builder.cxx
View file @
8e71130e
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
#include "Pool.hxx"
#include "Pool.hxx"
#include "FixString.hxx"
#include "FixString.hxx"
#include "Tag.hxx"
#include "Tag.hxx"
#include "util/
WritableBuffer
.hxx"
#include "util/
AllocatedArray
.hxx"
#include "util/StringView.hxx"
#include "util/StringView.hxx"
#include <algorithm>
#include <algorithm>
...
@@ -217,11 +217,9 @@ TagBuilder::AddItemInternal(TagType type, StringView value) noexcept
...
@@ -217,11 +217,9 @@ TagBuilder::AddItemInternal(TagType type, StringView value) noexcept
auto
f
=
FixTagString
(
value
);
auto
f
=
FixTagString
(
value
);
if
(
!
f
.
IsNull
())
if
(
!
f
.
IsNull
())
value
=
{
f
.
data
,
f
.
size
};
value
=
{
f
.
data
(),
f
.
size
()
};
AddItemUnchecked
(
type
,
value
);
AddItemUnchecked
(
type
,
value
);
free
(
f
.
data
);
}
}
void
void
...
...
src/tag/FixString.cxx
View file @
8e71130e
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
*/
*/
#include "FixString.hxx"
#include "FixString.hxx"
#include "util/Alloc.hxx"
#include "util/Alloc
atedArray
.hxx"
#include "util/CharUtil.hxx"
#include "util/CharUtil.hxx"
#include "util/WritableBuffer.hxx"
#include "util/WritableBuffer.hxx"
#include "util/StringView.hxx"
#include "util/StringView.hxx"
...
@@ -55,15 +55,15 @@ FindInvalidUTF8(const char *p, const char *const end) noexcept
...
@@ -55,15 +55,15 @@ FindInvalidUTF8(const char *p, const char *const end) noexcept
/**
/**
* Replace invalid sequences with the question mark.
* Replace invalid sequences with the question mark.
*/
*/
static
WritableBuffer
<
char
>
static
AllocatedArray
<
char
>
patch_utf8
(
StringView
src
,
const
char
*
_invalid
)
patch_utf8
(
StringView
src
,
const
char
*
_invalid
)
{
{
/* duplicate the string, and replace invalid bytes in that
/* duplicate the string, and replace invalid bytes in that
buffer */
buffer */
char
*
dest
=
(
char
*
)
xmemdup
(
src
.
data
,
src
.
size
)
;
AllocatedArray
<
char
>
dest
{
src
}
;
char
*
const
end
=
dest
+
src
.
size
;
char
*
const
end
=
dest
.
data
()
+
src
.
size
;
char
*
invalid
=
dest
+
(
_invalid
-
src
.
data
);
char
*
invalid
=
dest
.
data
()
+
(
_invalid
-
src
.
data
);
do
{
do
{
*
invalid
=
'?'
;
*
invalid
=
'?'
;
...
@@ -71,10 +71,10 @@ patch_utf8(StringView src, const char *_invalid)
...
@@ -71,10 +71,10 @@ patch_utf8(StringView src, const char *_invalid)
invalid
=
const_cast
<
char
*>
(
__invalid
);
invalid
=
const_cast
<
char
*>
(
__invalid
);
}
while
(
invalid
!=
nullptr
);
}
while
(
invalid
!=
nullptr
);
return
{
dest
,
src
.
size
}
;
return
dest
;
}
}
static
WritableBuffer
<
char
>
static
AllocatedArray
<
char
>
fix_utf8
(
StringView
p
)
fix_utf8
(
StringView
p
)
{
{
/* check if the string is already valid UTF-8 */
/* check if the string is already valid UTF-8 */
...
@@ -100,20 +100,20 @@ find_non_printable(StringView p)
...
@@ -100,20 +100,20 @@ find_non_printable(StringView p)
* Clears all non-printable characters, convert them to space.
* Clears all non-printable characters, convert them to space.
* Returns nullptr if nothing needs to be cleared.
* Returns nullptr if nothing needs to be cleared.
*/
*/
static
WritableBuffer
<
char
>
static
AllocatedArray
<
char
>
clear_non_printable
(
StringView
src
)
clear_non_printable
(
StringView
src
)
{
{
const
char
*
first
=
find_non_printable
(
src
);
const
char
*
first
=
find_non_printable
(
src
);
if
(
first
==
nullptr
)
if
(
first
==
nullptr
)
return
nullptr
;
return
nullptr
;
char
*
dest
=
(
char
*
)
xmemdup
(
src
.
data
,
src
.
size
)
;
AllocatedArray
<
char
>
dest
{
src
}
;
for
(
size_t
i
=
first
-
src
.
data
;
i
<
src
.
size
;
++
i
)
for
(
size_t
i
=
first
-
src
.
data
;
i
<
src
.
size
;
++
i
)
if
(
IsNonPrintableASCII
(
dest
[
i
]))
if
(
IsNonPrintableASCII
(
dest
[
i
]))
dest
[
i
]
=
' '
;
dest
[
i
]
=
' '
;
return
{
dest
,
src
.
size
}
;
return
dest
;
}
}
[[
gnu
::
pure
]]
[[
gnu
::
pure
]]
...
@@ -126,7 +126,7 @@ IsSafe(StringView s) noexcept
...
@@ -126,7 +126,7 @@ IsSafe(StringView s) noexcept
});
});
}
}
WritableBuffer
<
char
>
AllocatedArray
<
char
>
FixTagString
(
StringView
p
)
FixTagString
(
StringView
p
)
{
{
if
(
IsSafe
(
p
))
if
(
IsSafe
(
p
))
...
@@ -134,14 +134,12 @@ FixTagString(StringView p)
...
@@ -134,14 +134,12 @@ FixTagString(StringView p)
return
nullptr
;
return
nullptr
;
auto
utf8
=
fix_utf8
(
p
);
auto
utf8
=
fix_utf8
(
p
);
if
(
!
utf8
.
IsNull
())
if
(
utf8
!=
nullptr
)
p
=
{
utf8
.
data
,
utf8
.
size
};
p
=
{
utf8
.
data
(),
utf8
.
size
()};
WritableBuffer
<
char
>
cleared
=
clear_non_printable
(
p
);
auto
cleared
=
clear_non_printable
(
p
);
if
(
cleared
.
IsNull
())
if
(
cleared
==
nullptr
)
cleared
=
utf8
;
cleared
=
std
::
move
(
utf8
);
else
free
(
utf8
.
data
);
return
cleared
;
return
cleared
;
}
}
src/tag/FixString.hxx
View file @
8e71130e
...
@@ -21,9 +21,9 @@
...
@@ -21,9 +21,9 @@
#define MPD_TAG_STRING_HXX
#define MPD_TAG_STRING_HXX
struct
StringView
;
struct
StringView
;
template
<
typename
T
>
struct
WritableBuffer
;
template
<
typename
T
>
class
AllocatedArray
;
WritableBuffer
<
char
>
AllocatedArray
<
char
>
FixTagString
(
StringView
p
);
FixTagString
(
StringView
p
);
#endif
#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