Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Illuna-Minetest
illuna-minetest
Commits
3b65a6a3
Commit
3b65a6a3
authored
9 years ago
by
figec
Committed by
est31
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix wrap_rows at inner byte of multibyte sequence
Also fix UTF-8 inner byte bounds and make unittest for case this fixes.
parent
e45ecad3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/unittest/test_utilities.cpp
+17
-7
17 additions, 7 deletions
src/unittest/test_utilities.cpp
src/util/string.h
+11
-3
11 additions, 3 deletions
src/util/string.h
with
28 additions
and
10 deletions
src/unittest/test_utilities.cpp
+
17
−
7
View file @
3b65a6a3
...
...
@@ -243,13 +243,23 @@ void TestUtilities::testWrapRows()
{
UASSERT
(
wrap_rows
(
"12345678"
,
4
)
==
"1234
\n
5678"
);
// test that wrap_rows doesn't wrap inside multibyte sequences
const
unsigned
char
s
[]
=
{
0x2f
,
0x68
,
0x6f
,
0x6d
,
0x65
,
0x2f
,
0x72
,
0x61
,
0x70
,
0x74
,
0x6f
,
0x72
,
0x2f
,
0xd1
,
0x82
,
0xd0
,
0xb5
,
0xd1
,
0x81
,
0xd1
,
0x82
,
0x2f
,
0x6d
,
0x69
,
0x6e
,
0x65
,
0x74
,
0x65
,
0x73
,
0x74
,
0x2f
,
0x62
,
0x69
,
0x6e
,
0x2f
,
0x2e
,
0x2e
,
0
};
std
::
string
str
((
char
*
)
s
);
UASSERT
(
utf8_to_wide
(
wrap_rows
(
str
,
20
))
!=
L"<invalid UTF-8 string>"
);
{
const
unsigned
char
s
[]
=
{
0x2f
,
0x68
,
0x6f
,
0x6d
,
0x65
,
0x2f
,
0x72
,
0x61
,
0x70
,
0x74
,
0x6f
,
0x72
,
0x2f
,
0xd1
,
0x82
,
0xd0
,
0xb5
,
0xd1
,
0x81
,
0xd1
,
0x82
,
0x2f
,
0x6d
,
0x69
,
0x6e
,
0x65
,
0x74
,
0x65
,
0x73
,
0x74
,
0x2f
,
0x62
,
0x69
,
0x6e
,
0x2f
,
0x2e
,
0x2e
,
0
};
std
::
string
str
((
char
*
)
s
);
UASSERT
(
utf8_to_wide
(
wrap_rows
(
str
,
20
))
!=
L"<invalid UTF-8 string>"
);
};
{
const
unsigned
char
s
[]
=
{
0x74
,
0x65
,
0x73
,
0x74
,
0x20
,
0xd1
,
0x82
,
0xd0
,
0xb5
,
0xd1
,
0x81
,
0xd1
,
0x82
,
0x20
,
0xd1
,
0x82
,
0xd0
,
0xb5
,
0xd1
,
0x81
,
0xd1
,
0x82
,
0x20
,
0xd1
,
0x82
,
0xd0
,
0xb5
,
0xd1
,
0x81
,
0xd1
,
0x82
,
0
};
std
::
string
str
((
char
*
)
s
);
UASSERT
(
utf8_to_wide
(
wrap_rows
(
str
,
8
))
!=
L"<invalid UTF-8 string>"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/util/string.h
+
11
−
3
View file @
3b65a6a3
...
...
@@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define TOSTRING(x) STRINGIFY(x)
// Checks whether a byte is an inner byte for an utf-8 multibyte sequence
#define IS_UTF8_MULTB_INNER(x) (((unsigned char)x >= 0x80) && ((unsigned char)x <
=
0xc0))
#define IS_UTF8_MULTB_INNER(x) (((unsigned char)x >= 0x80) && ((unsigned char)x < 0xc0))
typedef
std
::
map
<
std
::
string
,
std
::
string
>
StringMap
;
...
...
@@ -426,12 +426,20 @@ inline std::string wrap_rows(const std::string &from,
{
std
::
string
to
;
bool
need_to_wrap
=
false
;
size_t
character_idx
=
0
;
for
(
size_t
i
=
0
;
i
<
from
.
size
();
i
++
)
{
if
(
character_idx
>
0
&&
character_idx
%
row_len
==
0
)
to
+=
'\n'
;
if
(
!
IS_UTF8_MULTB_INNER
(
from
[
i
]))
need_to_wrap
=
true
;
if
(
!
IS_UTF8_MULTB_INNER
(
from
[
i
]))
{
// Wrap string if needed before next char started
if
(
need_to_wrap
)
{
to
+=
'\n'
;
need_to_wrap
=
false
;
}
character_idx
++
;
}
to
+=
from
[
i
];
}
...
...
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