Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
98ca7e9c
Commit
98ca7e9c
authored
Oct 26, 2008
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolve_xml_special_chars: don't reinvent bsearch()
parent
cc23bbdc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
44 deletions
+28
-44
src/text/strings.c
src/text/strings.c
+28
-44
No files found.
src/text/strings.c
View file @
98ca7e9c
...
...
@@ -236,7 +236,7 @@ static const struct xml_entity_s
{
char
psz_entity
[
8
];
char
psz_char
[
4
];
}
p_
xml_entities
[]
=
{
}
xml_entities
[]
=
{
/* Important: this list has to be in alphabetical order (psz_entity-wise) */
{
"AElig;"
,
"Æ"
},
{
"Aacute;"
,
"Á"
},
...
...
@@ -277,6 +277,8 @@ static const struct xml_entity_s
{
"acute;"
,
"´"
},
{
"aelig;"
,
"æ"
},
{
"agrave;"
,
"à"
},
{
"amp;"
,
"&"
},
{
"apos;"
"'"
},
{
"aring;"
,
"å"
},
{
"atilde;"
,
"ã"
},
{
"auml;"
,
"ä"
},
...
...
@@ -300,6 +302,7 @@ static const struct xml_entity_s
{
"frac12;"
,
"½"
},
{
"frac14;"
,
"¼"
},
{
"frac34;"
,
"¾"
},
{
"gt;"
,
">"
},
{
"hellip;"
,
"…"
},
{
"iacute;"
,
"í"
},
{
"icirc;"
,
"î"
},
...
...
@@ -311,6 +314,7 @@ static const struct xml_entity_s
{
"ldquo;"
,
"“"
},
{
"lsaquo;"
,
"‹"
},
{
"lsquo;"
,
"‘"
},
{
"lt;"
"<"
},
{
"macr;"
,
"¯"
},
{
"mdash;"
,
"—"
},
{
"micro;"
,
"µ"
},
...
...
@@ -332,6 +336,7 @@ static const struct xml_entity_s
{
"permil;"
,
"‰"
},
{
"plusmn;"
,
"±"
},
{
"pound;"
,
"£"
},
{
"quot;"
,
"
\"
"
},
{
"raquo;"
,
"»"
},
{
"rdquo;"
,
"”"
},
{
"reg;"
,
"®"
},
...
...
@@ -359,6 +364,14 @@ static const struct xml_entity_s
{
"yuml;"
,
"ÿ"
},
};
static
int
cmp_entity
(
const
void
*
key
,
const
void
*
elem
)
{
const
struct
xml_entity_s
*
ent
=
elem
;
const
char
*
name
=
key
;
return
strncmp
(
name
,
ent
->
psz_entity
,
strlen
(
ent
->
psz_entity
));
}
/**
* Converts "<", ">" and "&" to "<", ">" and "&"
* \param string to convert
...
...
@@ -371,20 +384,8 @@ void resolve_xml_special_chars( char *psz_value )
{
if
(
*
psz_value
==
'&'
)
{
char
*
psz_value1
=
psz_value
+
1
;
#define TRY_CHAR( src, dst ) \
if( !strncmp( psz_value1, src";", strlen( src";" ) ) ) \
{ \
*p_pos = dst; \
psz_value += strlen( src ) + 2; \
}
TRY_CHAR
(
"lt"
,
'<'
)
else
TRY_CHAR
(
"amp"
,
'&'
)
else
TRY_CHAR
(
"apos"
,
'\''
)
else
TRY_CHAR
(
"gt"
,
'>'
)
else
TRY_CHAR
(
"quot"
,
'"'
)
#undef TRY_CHAR
else
if
(
*
psz_value1
==
'#'
)
const
char
*
psz_value1
=
psz_value
+
1
;
if
(
*
psz_value1
==
'#'
)
{
char
*
psz_end
;
int
i
=
strtol
(
psz_value
+
2
,
&
psz_end
,
10
);
...
...
@@ -411,37 +412,20 @@ void resolve_xml_special_chars( char *psz_value )
}
else
{
const
size_t
i_entities
=
sizeof
(
p_xml_entities
)
/
sizeof
(
p_xml_entities
[
0
]
);
assert
(
i_entities
<
128
);
size_t
step
=
128
>>
1
;
size_t
i
=
step
-
1
;
int
cmp
=
-
1
;
while
(
step
)
const
struct
xml_entity_s
*
ent
;
ent
=
bsearch
(
psz_value1
,
xml_entities
,
sizeof
(
xml_entities
)
/
sizeof
(
*
ent
),
sizeof
(
*
ent
),
cmp_entity
);
if
(
ent
!=
NULL
)
{
size_t
ilen
=
strlen
(
p_xml_entities
[
i
].
psz_entity
);
step
>>=
1
;
if
(
i
>=
i_entities
)
cmp
=
-
1
;
else
cmp
=
strncmp
(
psz_value1
,
/* Skip the & */
p_xml_entities
[
i
].
psz_entity
,
strlen
(
p_xml_entities
[
i
].
psz_entity
)
);
if
(
cmp
==
0
)
{
size_t
olen
=
strlen
(
p_xml_entities
[
i
].
psz_char
);
memcpy
(
p_pos
,
p_xml_entities
[
i
].
psz_char
,
olen
);
p_pos
+=
olen
-
1
;
psz_value
+=
ilen
+
1
;
break
;
}
else
if
(
cmp
<
0
)
i
-=
step
;
else
i
+=
step
;
size_t
olen
=
strlen
(
ent
->
psz_char
);
memcpy
(
p_pos
,
ent
->
psz_char
,
olen
);
p_pos
+=
olen
-
1
;
psz_value
+=
strlen
(
ent
->
psz_entity
)
+
1
;
}
if
(
cmp
!=
0
)
{
else
{
/* No match */
*
p_pos
=
*
psz_value
;
psz_value
++
;
}
...
...
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