- Added AsciiCharset for matching ascii characters quickly.

- Added `String.trim_charset`.
This commit is contained in:
Christoffer Lerno
2025-08-21 02:57:17 +02:00
parent 2e1f7c95ce
commit 6ab7198f2f
3 changed files with 44 additions and 2 deletions

View File

@@ -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.