Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
git_rec_nano
Commits
981b4149
Commit
981b4149
authored
8 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
utils: distinguish between width (columns) and length (bytes)
parent
06b1fcad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/utils.c
+16
-17
src/utils.c
with
16 additions
and
17 deletions
+16
-17
src/utils.c
View file @
981b4149
...
...
@@ -484,38 +484,37 @@ size_t actual_x(const char *s, size_t column)
return
i
;
}
/* A strnlen() with tabs and multicolumn characters factored in, similar
* to xplustabs(). How many columns wide are the first maxlen characters
* of s? */
size_t
strnlenpt
(
const
char
*
s
,
size_t
maxlen
)
/* A strnlen() with tabs and multicolumn characters factored in:
* how many columns wide are the first maxlen bytes of text? */
size_t
strnlenpt
(
const
char
*
text
,
size_t
maxlen
)
{
size_t
len
=
0
;
/* The screen display width to
s[i
]. */
size_t
width
=
0
;
/* The screen display width to
text[maxlen
]. */
if
(
maxlen
==
0
)
return
0
;
assert
(
s
!=
NULL
);
assert
(
text
!=
NULL
);
while
(
*
s
!=
'\0'
)
{
int
s_
len
=
parse_mbchar
(
s
,
NULL
,
&
len
);
while
(
*
text
!=
'\0'
)
{
int
char
len
=
parse_mbchar
(
text
,
NULL
,
&
width
);
s
+=
s_
len
;
text
+=
char
len
;
if
(
maxlen
<=
s_
len
)
if
(
maxlen
<=
char
len
)
break
;
maxlen
-=
s_
len
;
maxlen
-=
char
len
;
}
return
len
;
return
width
;
}
/* A strlen() with tabs and multicolumn characters factored in
, similar
*
to xplustabs(). H
ow many columns wide is
s
? */
size_t
strlenpt
(
const
char
*
s
)
/* A strlen() with tabs and multicolumn characters factored in
:
*
h
ow many columns wide is
text
? */
size_t
strlenpt
(
const
char
*
text
)
{
return
strnlenpt
(
s
,
(
size_t
)
-
1
);
return
strnlenpt
(
text
,
(
size_t
)
-
1
);
}
/* Append a new magicline to filebot. */
...
...
This diff is collapsed.
Click to expand it.
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