Skip to content

Commit

Permalink
Merge branch 'c3lang:master' into trig-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MendocinoWhiteDeer authored Dec 20, 2024
2 parents 0ba866e + 16bbc5a commit 9893ee6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lib/std/core/string.c3
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,21 @@ fn float! String.to_float(s) => s.to_real(float);

fn Splitter String.splitter(self, String split)
{
return Splitter { self, split, 0 };
return { .string = self, .split = split };
}

fn Splitter String.tokenize(self, String split)
{
return { .string = self, .split = split, .tokenize = true };
}

struct Splitter
{
String string;
String split;
usz current;
bool tokenize;
int last_index;
}

fn void Splitter.reset(&self)
Expand All @@ -736,18 +743,22 @@ fn void Splitter.reset(&self)

fn String! Splitter.next(&self)
{
usz len = self.string.len;
usz current = self.current;
if (current >= len) return IteratorResult.NO_MORE_ELEMENT?;
String remaining = self.string[current..];
usz! next = remaining.index_of(self.split);
if (try next)
while (true)
{
defer self.current = current + next + self.split.len;
return remaining[:next];
usz len = self.string.len;
usz current = self.current;
if (current >= len) return IteratorResult.NO_MORE_ELEMENT?;
String remaining = self.string[current..];
usz! next = remaining.index_of(self.split);
if (try next)
{
self.current = current + next + self.split.len;
if (!next && self.tokenize) continue;
return remaining[:next];
}
self.current = len;
return remaining;
}
self.current = len;
return remaining;
}

macro String new_struct_to_str(x, Allocator allocator = allocator::heap())
Expand Down
2 changes: 2 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ None
- Fix case trying to initialize a `char[*]*` from a String.
- Fix Map & HashMap `put_all_for_create` not copying all elements, causing `init_from_map` to create incomplete copy.
- Fix bug when a macro calling an extern function was called in another module also declaring and calling the same function. #1690

### Stdlib changes
- Increase BitWriter.write_bits limit up to 32 bits.
- Updates to `Slice2d`, like `get_xy` and others.
- Added `iter()` `value_iter()` and `key_iter()` to HashMap.
- Add "tokenizer" to String.

## 0.6.5 Change list

Expand Down

0 comments on commit 9893ee6

Please sign in to comment.