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
b7a1954c
Commit
b7a1954c
authored
Oct 10, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TagString: return WritableBuffer<char>
parent
6520589a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
24 deletions
+26
-24
TagBuilder.cxx
src/tag/TagBuilder.cxx
+6
-5
TagString.cxx
src/tag/TagString.cxx
+16
-17
TagString.hxx
src/tag/TagString.hxx
+4
-2
No files found.
src/tag/TagBuilder.cxx
View file @
b7a1954c
...
...
@@ -23,6 +23,7 @@
#include "TagPool.hxx"
#include "TagString.hxx"
#include "Tag.hxx"
#include "util/WritableBuffer.hxx"
#include <assert.h>
#include <string.h>
...
...
@@ -184,17 +185,17 @@ TagBuilder::AddItemInternal(TagType type, const char *value, size_t length)
assert
(
value
!=
nullptr
);
assert
(
length
>
0
);
char
*
p
=
FixTagString
(
value
,
length
);
if
(
p
!=
nullptr
)
{
value
=
p
;
length
=
strlen
(
value
)
;
auto
f
=
FixTagString
(
value
,
length
);
if
(
!
f
.
IsNull
()
)
{
value
=
f
.
data
;
length
=
f
.
size
;
}
tag_pool_lock
.
lock
();
auto
i
=
tag_pool_get_item
(
type
,
value
,
length
);
tag_pool_lock
.
unlock
();
free
(
p
);
free
(
f
.
data
);
items
.
push_back
(
i
);
}
...
...
src/tag/TagString.cxx
View file @
b7a1954c
...
...
@@ -20,6 +20,7 @@
#include "config.h"
#include "TagString.hxx"
#include "util/Alloc.hxx"
#include "util/WritableBuffer.hxx"
#ifdef HAVE_GLIB
#include <glib.h>
...
...
@@ -34,21 +35,21 @@
/**
* Replace invalid sequences with the question mark.
*/
static
char
*
static
WritableBuffer
<
char
>
patch_utf8
(
const
char
*
src
,
size_t
length
,
const
gchar
*
end
)
{
/* duplicate the string, and replace invalid bytes in that
buffer */
char
*
dest
=
xstrn
dup
(
src
,
length
);
char
*
dest
=
(
char
*
)
xmem
dup
(
src
,
length
);
do
{
dest
[
end
-
src
]
=
'?'
;
}
while
(
!
g_utf8_validate
(
end
+
1
,
(
src
+
length
)
-
(
end
+
1
),
&
end
));
return
dest
;
return
{
dest
,
length
}
;
}
static
char
*
static
WritableBuffer
<
char
>
fix_utf8
(
const
char
*
str
,
size_t
length
)
{
const
gchar
*
end
;
...
...
@@ -85,43 +86,41 @@ find_non_printable(const char *p, size_t length)
* Clears all non-printable characters, convert them to space.
* Returns nullptr if nothing needs to be cleared.
*/
static
char
*
static
WritableBuffer
<
char
>
clear_non_printable
(
const
char
*
p
,
size_t
length
)
{
const
char
*
first
=
find_non_printable
(
p
,
length
);
char
*
dest
;
if
(
first
==
nullptr
)
return
nullptr
;
dest
=
xstrn
dup
(
p
,
length
);
char
*
dest
=
(
char
*
)
xmem
dup
(
p
,
length
);
for
(
size_t
i
=
first
-
p
;
i
<
length
;
++
i
)
if
(
char_is_non_printable
(
dest
[
i
]))
dest
[
i
]
=
' '
;
return
dest
;
return
{
dest
,
length
}
;
}
char
*
WritableBuffer
<
char
>
FixTagString
(
const
char
*
p
,
size_t
length
)
{
#ifdef HAVE_GLIB
// TODO: implement without GLib
char
*
utf8
=
fix_utf8
(
p
,
length
);
if
(
utf8
!=
nullptr
)
{
p
=
utf8
;
length
=
strlen
(
p
)
;
auto
utf8
=
fix_utf8
(
p
,
length
);
if
(
!
utf8
.
IsNull
()
)
{
p
=
utf8
.
data
;
length
=
utf8
.
size
;
}
#endif
char
*
cleared
=
clear_non_printable
(
p
,
length
);
WritableBuffer
<
char
>
cleared
=
clear_non_printable
(
p
,
length
);
#ifdef HAVE_GLIB
if
(
cleared
==
nullptr
)
if
(
cleared
.
IsNull
()
)
cleared
=
utf8
;
else
free
(
utf8
);
free
(
utf8
.
data
);
#endif
return
cleared
;
...
...
src/tag/TagString.hxx
View file @
b7a1954c
...
...
@@ -25,8 +25,10 @@
#include <stddef.h>
gcc_malloc
gcc_nonnull_all
char
*
template
<
typename
T
>
struct
WritableBuffer
;
gcc_nonnull_all
WritableBuffer
<
char
>
FixTagString
(
const
char
*
p
,
size_t
length
);
#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