Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
d1d63e35
Commit
d1d63e35
authored
2 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
utf8_utils: use string_view
Change-Id: Ib939740608d112626ccce0228726e758b07d22a3
parent
fe058538
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/sip/sip_utils.cpp
+2
-3
2 additions, 3 deletions
src/sip/sip_utils.cpp
src/utf8_utils.cpp
+5
-7
5 additions, 7 deletions
src/utf8_utils.cpp
src/utf8_utils.h
+3
-6
3 additions, 6 deletions
src/utf8_utils.h
with
10 additions
and
16 deletions
src/sip/sip_utils.cpp
+
2
−
3
View file @
d1d63e35
...
@@ -109,14 +109,13 @@ parseDisplayName(const pjsip_name_addr* sip_name_addr)
...
@@ -109,14 +109,13 @@ parseDisplayName(const pjsip_name_addr* sip_name_addr)
if
(
not
sip_name_addr
->
display
.
ptr
or
not
sip_name_addr
->
display
.
slen
)
if
(
not
sip_name_addr
->
display
.
ptr
or
not
sip_name_addr
->
display
.
slen
)
return
{};
return
{};
std
::
string
displayName
{
sip_name_addr
->
display
.
ptr
,
auto
displayName
=
as_view
(
sip_name_addr
->
display
);
static_cast
<
size_t
>
(
sip_name_addr
->
display
.
slen
)};
// Filter out invalid UTF-8 characters to avoid getting kicked from D-Bus
// Filter out invalid UTF-8 characters to avoid getting kicked from D-Bus
if
(
not
utf8_validate
(
displayName
))
if
(
not
utf8_validate
(
displayName
))
return
utf8_make_valid
(
displayName
);
return
utf8_make_valid
(
displayName
);
return
displayName
;
return
std
::
string
(
displayName
)
;
}
}
std
::
string
std
::
string
...
...
This diff is collapsed.
Click to expand it.
src/utf8_utils.cpp
+
5
−
7
View file @
d1d63e35
...
@@ -237,21 +237,19 @@ utf8_validate_c_str(const char* str, ssize_t max_len, const char** end)
...
@@ -237,21 +237,19 @@ utf8_validate_c_str(const char* str, ssize_t max_len, const char** end)
}
}
bool
bool
utf8_validate
(
const
std
::
string
&
str
)
utf8_validate
(
std
::
string
_view
str
)
{
{
const
char
*
p
;
const
char
*
p
=
fast_validate_len
(
str
.
data
(),
str
.
size
());
p
=
fast_validate
(
str
.
c_str
());
return
(
*
p
==
'\0'
);
return
(
*
p
==
'\0'
);
}
}
std
::
string
std
::
string
utf8_make_valid
(
const
std
::
string
&
name
)
utf8_make_valid
(
std
::
string
_view
name
)
{
{
ssize_t
remaining_bytes
=
name
.
size
();
ssize_t
remaining_bytes
=
name
.
size
();
ssize_t
valid_bytes
;
ssize_t
valid_bytes
;
const
char
*
remainder
=
name
.
c_str
();
const
char
*
remainder
=
name
.
data
();
const
char
*
invalid
;
const
char
*
invalid
;
char
*
str
=
NULL
;
char
*
str
=
NULL
;
char
*
pos
;
char
*
pos
;
...
@@ -289,7 +287,7 @@ utf8_make_valid(const std::string& name)
...
@@ -289,7 +287,7 @@ utf8_make_valid(const std::string& name)
pos
+=
remaining_bytes
;
pos
+=
remaining_bytes
;
std
::
string
answer
(
str
,
pos
-
str
);
std
::
string
answer
(
str
,
pos
-
str
);
assert
(
utf8_validate
_c_str
(
answer
.
c_str
(),
-
1
,
NULL
));
assert
(
utf8_validate
(
answer
));
delete
[]
str
;
delete
[]
str
;
...
...
This diff is collapsed.
Click to expand it.
src/utf8_utils.h
+
3
−
6
View file @
d1d63e35
...
@@ -20,8 +20,7 @@
...
@@ -20,8 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
*/
#ifndef H_UTF8_UTILS
#pragma once
#define H_UTF8_UTILS
#include
<cstdlib>
#include
<cstdlib>
#include
<string>
#include
<string>
...
@@ -41,7 +40,7 @@ namespace jami {
...
@@ -41,7 +40,7 @@ namespace jami {
* Returns: true if the text was valid UTF-8
* Returns: true if the text was valid UTF-8
*/
*/
bool
utf8_validate
(
const
std
::
string
&
str
);
bool
utf8_validate
(
std
::
string
_view
str
);
/**
/**
* utf8_make_valid:
* utf8_make_valid:
...
@@ -53,8 +52,6 @@ bool utf8_validate(const std::string& str);
...
@@ -53,8 +52,6 @@ bool utf8_validate(const std::string& str);
*
*
* Returns: a valid utf8 string.
* Returns: a valid utf8 string.
*/
*/
std
::
string
utf8_make_valid
(
const
std
::
string
&
name
);
std
::
string
utf8_make_valid
(
std
::
string
_view
str
);
}
// namespace jami
}
// namespace jami
#endif // H_UTF8_UTILS
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment