mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-01-22 19:36:32 +08:00
Add xy_str_strip()
This commit is contained in:
parent
84a9e7338f
commit
76ac8dc3ca
26
xy.h
26
xy.h
|
@ -7,6 +7,8 @@
|
|||
* xy:
|
||||
*
|
||||
* y = f(x)
|
||||
*
|
||||
* Corss-Platform C utilities in Ruby flavor
|
||||
* -------------------------------------------------------------*/
|
||||
|
||||
#ifndef XY_H
|
||||
|
@ -348,4 +350,28 @@ xy_str_delete_suffix (const char* str, const char* suffix)
|
|||
return new;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
xy_str_strip (const char* str)
|
||||
{
|
||||
const char* lf = "\n";
|
||||
const char* crlf = "\r\n";
|
||||
|
||||
char* new = xy_strdup(str);
|
||||
|
||||
while (xy_str_start_with(new, lf)) {
|
||||
new = xy_str_delete_prefix(new, lf);
|
||||
}
|
||||
while (xy_str_start_with(new, crlf)) {
|
||||
new = xy_str_delete_prefix(new, crlf);
|
||||
}
|
||||
while (xy_str_end_with(new, lf)) {
|
||||
new = xy_str_delete_suffix(new, lf);
|
||||
}
|
||||
while (xy_str_end_with(new, crlf)) {
|
||||
new = xy_str_delete_suffix(new, crlf);
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user