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
77b32add
Commit
77b32add
authored
Jan 03, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag: revert g_strescape() patch
Don't use g_strescape(), because it escapes all non-ASCII characters. Add a new function which clears all non-printable characters, not just "newline".
parent
6d2e4f4e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
7 deletions
+56
-7
tag.c
src/tag.c
+56
-7
No files found.
src/tag.c
View file @
77b32add
...
...
@@ -411,19 +411,64 @@ void tag_end_add(struct tag *tag)
#endif
}
static
bool
char_is_non_printable
(
unsigned
char
ch
)
{
return
ch
<
0x20
;
}
static
const
char
*
find_non_printable
(
const
char
*
p
,
size_t
length
)
{
for
(
size_t
i
=
0
;
i
<
length
;
++
i
)
if
(
char_is_non_printable
(
p
[
i
]))
return
p
+
i
;
return
NULL
;
}
/**
* Clears all non-printable characters, convert them to space.
* Returns NULL if nothing needs to be cleared.
*/
static
char
*
clear_non_printable
(
const
char
*
p
,
size_t
length
)
{
const
char
*
first
=
find_non_printable
(
p
,
length
);
char
*
dest
;
if
(
first
==
NULL
)
return
NULL
;
/* duplicate and null-terminate the string */
dest
=
g_memdup
(
p
,
length
);
dest
[
length
]
=
0
;
for
(
size_t
i
=
first
-
p
;
i
<
length
;
++
i
)
if
(
char_is_non_printable
(
dest
[
i
]))
dest
[
i
]
=
' '
;
return
dest
;
}
static
char
*
fix_tag_value
(
const
char
*
p
,
size_t
length
)
{
char
*
utf8
,
*
escap
ed
;
char
*
utf8
,
*
clear
ed
;
utf8
=
fix_utf8
(
p
,
length
);
if
(
utf8
==
NULL
)
utf8
=
g_strndup
(
p
,
length
);
if
(
utf8
!=
NULL
)
{
p
=
utf8
;
length
=
strlen
(
p
);
}
escaped
=
g_strescape
(
utf8
,
NULL
);
g_free
(
utf8
);
cleared
=
clear_non_printable
(
p
,
length
);
if
(
cleared
==
NULL
)
cleared
=
utf8
;
else
g_free
(
utf8
);
return
escap
ed
;
return
clear
ed
;
}
static
void
appendToTagItems
(
struct
tag
*
tag
,
enum
tag_type
type
,
...
...
@@ -433,6 +478,10 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
char
*
p
;
p
=
fix_tag_value
(
value
,
len
);
if
(
p
!=
NULL
)
{
value
=
p
;
len
=
strlen
(
value
);
}
tag
->
numOfItems
++
;
...
...
@@ -449,7 +498,7 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
}
g_mutex_lock
(
tag_pool_lock
);
tag
->
items
[
i
]
=
tag_pool_get_item
(
type
,
p
,
strlen
(
p
)
);
tag
->
items
[
i
]
=
tag_pool_get_item
(
type
,
value
,
len
);
g_mutex_unlock
(
tag_pool_lock
);
g_free
(
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