mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-01-22 13:02:58 +08:00
Refactor xy_str_strip()
This commit is contained in:
parent
236e5e74ac
commit
bd6f35c1a4
25
xy.h
25
xy.h
|
@ -431,22 +431,21 @@ xy_str_delete_suffix (const char* str, const char* suffix)
|
||||||
static char*
|
static char*
|
||||||
xy_str_strip (const char* str)
|
xy_str_strip (const char* str)
|
||||||
{
|
{
|
||||||
const char* lf = "\n";
|
|
||||||
const char* crlf = "\r\n";
|
|
||||||
|
|
||||||
char* new = xy_strdup(str);
|
char* new = xy_strdup(str);
|
||||||
|
|
||||||
while (xy_str_start_with(new, lf)) {
|
while (strchr("\n\r\v\t\f ", new[0]))
|
||||||
new = xy_str_delete_prefix(new, lf);
|
{
|
||||||
|
new += 1;
|
||||||
}
|
}
|
||||||
while (xy_str_start_with(new, crlf)) {
|
|
||||||
new = xy_str_delete_prefix(new, crlf);
|
size_t len = strlen(new);
|
||||||
}
|
|
||||||
while (xy_str_end_with(new, lf)) {
|
char* last = new + len - 1;
|
||||||
new = xy_str_delete_suffix(new, lf);
|
|
||||||
}
|
while (strchr("\n\r\v\t\f ", *last))
|
||||||
while (xy_str_end_with(new, crlf)) {
|
{
|
||||||
new = xy_str_delete_suffix(new, crlf);
|
*last = '\0';
|
||||||
|
last -= 1;
|
||||||
}
|
}
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user