Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
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-gpu
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
Show 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
...
@@ -236,7 +236,7 @@ static const struct xml_entity_s
{
{
char
psz_entity
[
8
];
char
psz_entity
[
8
];
char
psz_char
[
4
];
char
psz_char
[
4
];
}
p_
xml_entities
[]
=
{
}
xml_entities
[]
=
{
/* Important: this list has to be in alphabetical order (psz_entity-wise) */
/* Important: this list has to be in alphabetical order (psz_entity-wise) */
{
"AElig;"
,
"Æ"
},
{
"AElig;"
,
"Æ"
},
{
"Aacute;"
,
"Á"
},
{
"Aacute;"
,
"Á"
},
...
@@ -277,6 +277,8 @@ static const struct xml_entity_s
...
@@ -277,6 +277,8 @@ static const struct xml_entity_s
{
"acute;"
,
"´"
},
{
"acute;"
,
"´"
},
{
"aelig;"
,
"æ"
},
{
"aelig;"
,
"æ"
},
{
"agrave;"
,
"à"
},
{
"agrave;"
,
"à"
},
{
"amp;"
,
"&"
},
{
"apos;"
"'"
},
{
"aring;"
,
"å"
},
{
"aring;"
,
"å"
},
{
"atilde;"
,
"ã"
},
{
"atilde;"
,
"ã"
},
{
"auml;"
,
"ä"
},
{
"auml;"
,
"ä"
},
...
@@ -300,6 +302,7 @@ static const struct xml_entity_s
...
@@ -300,6 +302,7 @@ static const struct xml_entity_s
{
"frac12;"
,
"½"
},
{
"frac12;"
,
"½"
},
{
"frac14;"
,
"¼"
},
{
"frac14;"
,
"¼"
},
{
"frac34;"
,
"¾"
},
{
"frac34;"
,
"¾"
},
{
"gt;"
,
">"
},
{
"hellip;"
,
"…"
},
{
"hellip;"
,
"…"
},
{
"iacute;"
,
"í"
},
{
"iacute;"
,
"í"
},
{
"icirc;"
,
"î"
},
{
"icirc;"
,
"î"
},
...
@@ -311,6 +314,7 @@ static const struct xml_entity_s
...
@@ -311,6 +314,7 @@ static const struct xml_entity_s
{
"ldquo;"
,
"“"
},
{
"ldquo;"
,
"“"
},
{
"lsaquo;"
,
"‹"
},
{
"lsaquo;"
,
"‹"
},
{
"lsquo;"
,
"‘"
},
{
"lsquo;"
,
"‘"
},
{
"lt;"
"<"
},
{
"macr;"
,
"¯"
},
{
"macr;"
,
"¯"
},
{
"mdash;"
,
"—"
},
{
"mdash;"
,
"—"
},
{
"micro;"
,
"µ"
},
{
"micro;"
,
"µ"
},
...
@@ -332,6 +336,7 @@ static const struct xml_entity_s
...
@@ -332,6 +336,7 @@ static const struct xml_entity_s
{
"permil;"
,
"‰"
},
{
"permil;"
,
"‰"
},
{
"plusmn;"
,
"±"
},
{
"plusmn;"
,
"±"
},
{
"pound;"
,
"£"
},
{
"pound;"
,
"£"
},
{
"quot;"
,
"
\"
"
},
{
"raquo;"
,
"»"
},
{
"raquo;"
,
"»"
},
{
"rdquo;"
,
"”"
},
{
"rdquo;"
,
"”"
},
{
"reg;"
,
"®"
},
{
"reg;"
,
"®"
},
...
@@ -359,6 +364,14 @@ static const struct xml_entity_s
...
@@ -359,6 +364,14 @@ static const struct xml_entity_s
{
"yuml;"
,
"ÿ"
},
{
"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 "&"
* Converts "<", ">" and "&" to "<", ">" and "&"
* \param string to convert
* \param string to convert
...
@@ -371,20 +384,8 @@ void resolve_xml_special_chars( char *psz_value )
...
@@ -371,20 +384,8 @@ void resolve_xml_special_chars( char *psz_value )
{
{
if
(
*
psz_value
==
'&'
)
if
(
*
psz_value
==
'&'
)
{
{
char
*
psz_value1
=
psz_value
+
1
;
const
char
*
psz_value1
=
psz_value
+
1
;
#define TRY_CHAR( src, dst ) \
if
(
*
psz_value1
==
'#'
)
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
==
'#'
)
{
{
char
*
psz_end
;
char
*
psz_end
;
int
i
=
strtol
(
psz_value
+
2
,
&
psz_end
,
10
);
int
i
=
strtol
(
psz_value
+
2
,
&
psz_end
,
10
);
...
@@ -411,37 +412,20 @@ void resolve_xml_special_chars( char *psz_value )
...
@@ -411,37 +412,20 @@ void resolve_xml_special_chars( char *psz_value )
}
}
else
else
{
{
const
size_t
i_entities
=
sizeof
(
p_xml_entities
)
/
const
struct
xml_entity_s
*
ent
;
sizeof
(
p_xml_entities
[
0
]
);
assert
(
i_entities
<
128
);
ent
=
bsearch
(
psz_value1
,
xml_entities
,
size_t
step
=
128
>>
1
;
sizeof
(
xml_entities
)
/
sizeof
(
*
ent
),
size_t
i
=
step
-
1
;
sizeof
(
*
ent
),
cmp_entity
);
int
cmp
=
-
1
;
if
(
ent
!=
NULL
)
while
(
step
)
{
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
);
size_t
olen
=
strlen
(
ent
->
psz_char
);
memcpy
(
p_pos
,
p_xml_entities
[
i
].
psz_char
,
olen
);
memcpy
(
p_pos
,
ent
->
psz_char
,
olen
);
p_pos
+=
olen
-
1
;
p_pos
+=
olen
-
1
;
psz_value
+=
ilen
+
1
;
psz_value
+=
strlen
(
ent
->
psz_entity
)
+
1
;
break
;
}
}
else
if
(
cmp
<
0
)
i
-=
step
;
else
else
i
+=
step
;
{
/* No match */
}
if
(
cmp
!=
0
)
{
*
p_pos
=
*
psz_value
;
*
p_pos
=
*
psz_value
;
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