mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
- Added AsciiCharset for matching ascii characters quickly.
- Added `String.trim_charset`.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
module std::core::string;
|
||||
import std::io;
|
||||
import std::core::mem::allocator;
|
||||
import std::io, std::ascii;
|
||||
|
||||
|
||||
typedef String @if(!$defined(String)) = inline char[];
|
||||
@@ -219,6 +218,23 @@ fn String String.trim(self, String to_trim = "\t\n\r ")
|
||||
return self.trim_left(to_trim).trim_right(to_trim);
|
||||
}
|
||||
|
||||
<*
|
||||
Remove characters from the front and end of a string.
|
||||
|
||||
@param [in] self : `The string to trim`
|
||||
@param to_trim : `The set of characters to trim, defaults to whitespace`
|
||||
@pure
|
||||
@return `a substring of the string passed in`
|
||||
*>
|
||||
fn String String.trim_charset(self, AsciiCharset to_trim = ascii::WHITESPACE_SET)
|
||||
{
|
||||
usz start = 0;
|
||||
usz len = self.len;
|
||||
while (start < len && to_trim.contains(self[start])) start++;
|
||||
while (len > start && to_trim.contains(self[len - 1])) len--;
|
||||
return self[start..len - 1];
|
||||
}
|
||||
|
||||
<*
|
||||
Remove characters from the front of a string.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user