Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
116d9e6f
Commit
116d9e6f
authored
8 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
chars: use memory on the stack instead of calling malloc() and free()
parent
6620acbf
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/chars.c
+12
-23
src/chars.c
with
12 additions
and
23 deletions
+12
-23
src/chars.c
View file @
116d9e6f
...
...
@@ -208,15 +208,11 @@ bool is_word_mbchar(const char *c, bool allow_punct)
return
TRUE
;
if
(
word_chars
!=
NULL
&&
*
word_chars
!=
'\0'
)
{
bool
wordforming
;
char
*
symbol
=
charalloc
(
MB_CUR_MAX
+
1
);
char
symbol
[
mb_cur_max
()
+
1
];
int
symlen
=
parse_mbchar
(
c
,
symbol
,
NULL
);
symbol
[
symlen
]
=
'\0'
;
wordforming
=
(
strstr
(
word_chars
,
symbol
)
!=
NULL
);
free
(
symbol
);
return
wordforming
;
return
(
strstr
(
word_chars
,
symbol
)
!=
NULL
);
}
return
(
allow_punct
&&
is_punct_mbchar
(
c
));
...
...
@@ -708,7 +704,7 @@ char *mbstrchr(const char *s, const char *c)
#ifdef ENABLE_UTF8
if
(
use_utf8
)
{
bool
bad_s_mb
=
FALSE
,
bad_c_mb
=
FALSE
;
char
*
s_mb
=
charalloc
(
MB_CUR_MAX
)
;
char
symbol
[
MB_CUR_MAX
]
;
const
char
*
q
=
s
;
wchar_t
ws
,
wc
;
...
...
@@ -719,9 +715,9 @@ char *mbstrchr(const char *s, const char *c)
}
while
(
*
s
!=
'\0'
)
{
int
s
_mb
_len
=
parse_mbchar
(
s
,
s
_
mb
,
NULL
);
int
s
ym
_len
=
parse_mbchar
(
s
,
s
y
mb
ol
,
NULL
);
if
(
mbtowc
(
&
ws
,
s
_
mb
,
s
_mb
_len
)
<
0
)
{
if
(
mbtowc
(
&
ws
,
s
y
mb
ol
,
s
ym
_len
)
<
0
)
{
mbtowc_reset
();
ws
=
(
unsigned
char
)
*
s
;
bad_s_mb
=
TRUE
;
...
...
@@ -730,12 +726,10 @@ char *mbstrchr(const char *s, const char *c)
if
(
bad_s_mb
==
bad_c_mb
&&
ws
==
wc
)
break
;
s
+=
s
_mb
_len
;
q
+=
s
_mb
_len
;
s
+=
s
ym
_len
;
q
+=
s
ym
_len
;
}
free
(
s_mb
);
if
(
*
s
==
'\0'
)
q
=
NULL
;
...
...
@@ -834,21 +828,16 @@ bool has_blank_mbchars(const char *s)
{
#ifdef ENABLE_UTF8
if
(
use_utf8
)
{
bool
retval
=
FALSE
;
char
*
chr_mb
=
charalloc
(
MB_CUR_MAX
);
char
symbol
[
MB_CUR_MAX
];
for
(;
*
s
!=
'\0'
;
s
+=
move_mbright
(
s
,
0
))
{
parse_mbchar
(
s
,
chr_mb
,
NULL
);
parse_mbchar
(
s
,
symbol
,
NULL
);
if
(
is_blank_mbchar
(
chr_mb
))
{
retval
=
TRUE
;
break
;
}
if
(
is_blank_mbchar
(
symbol
))
return
TRUE
;
}
free
(
chr_mb
);
return
retval
;
return
FALSE
;
}
else
#endif
return
has_blank_chars
(
s
);
...
...
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
Menu
Projects
Groups
Snippets
Help