summaryrefslogtreecommitdiff
path: root/core/src/xmake/string/trim.c
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-10 21:00:21 +0800
committerruki <[email protected]>2025-11-10 21:00:21 +0800
commit2c387895657ae13cd717d7f42f5baed5eb028a8e (patch)
tree8f005a8dfc3272e9f027560e5e1b5881a7a8bc70 /core/src/xmake/string/trim.c
parent831447a51da0b094e08bb047247bf269a6e6cf71 (diff)
format more if-else codes in core
Diffstat (limited to 'core/src/xmake/string/trim.c')
-rw-r--r--core/src/xmake/string/trim.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/core/src/xmake/string/trim.c b/core/src/xmake/string/trim.c
index c1dcdad8d..54e6e4b5a 100644
--- a/core/src/xmake/string/trim.c
+++ b/core/src/xmake/string/trim.c
@@ -40,15 +40,18 @@ static tb_void_t xm_string_trim_space(tb_char_t const **psstr, tb_char_t const *
tb_char_t const *e = *pestr;
// trim left?
- if (mode <= 0)
- while (p < e && tb_isspace(*p))
+ if (mode <= 0) {
+ while (p < e && tb_isspace(*p)) {
p++;
+ }
+ }
// trim right
if (mode >= 0) {
e--;
- while (e >= p && tb_isspace(*e))
+ while (e >= p && tb_isspace(*e)) {
e--;
+ }
e++;
}
@@ -64,8 +67,9 @@ static tb_char_t const *xm_string_ltrim(tb_char_t const *sstr,
tb_assert(sstr && estr && ctrim);
tb_char_t const *p = sstr;
- while (p < estr && tb_strnchr(ctrim, ntrim, *p))
+ while (p < estr && tb_strnchr(ctrim, ntrim, *p)) {
p++;
+ }
return p;
}
@@ -76,8 +80,9 @@ static tb_char_t const *xm_string_rtrim(tb_char_t const *sstr,
tb_assert(sstr && estr && ctrim);
tb_char_t const *p = estr - 1;
- while (p >= sstr && tb_strnchr(ctrim, ntrim, *p))
+ while (p >= sstr && tb_strnchr(ctrim, ntrim, *p)) {
p--;
+ }
return p + 1;
}
@@ -110,14 +115,16 @@ tb_int_t xm_string_trim(lua_State *lua) {
tb_char_t const *const rsstr = sstr;
tb_char_t const *const restr = estr;
- if (ltrim == 0)
+ if (ltrim == 0) {
xm_string_trim_space(&sstr, &estr, trimtype);
- else {
+ } else {
// trim chars
- if (trimtype <= 0)
+ if (trimtype <= 0) {
sstr = xm_string_ltrim(sstr, estr, trimchars, ltrim);
- if (trimtype >= 0)
+ }
+ if (trimtype >= 0) {
estr = xm_string_rtrim(sstr, estr, trimchars, ltrim);
+ }
}
// no trimed chars