Update string_iterator.c3 to include extra convenience methods
Added peek: returns the next character without incrementing current Added has_next: checks if the iterator has another element Added get: gets the current element (the same one that was returned with the previous call to next). Most of this is to make it easier to keep unicode support with common operations.
Oops! the get function has a bug it should be:
fn Char32! StringIterator.get(&self)
{
usz len = self.utf8.len;
usz current = self.current;
usz read = (len - current < 4 ? len - current : 4);
Char32 res = conv::utf8_to_char32(&self.utf8[current - read > 0 ? current - read : 0], &read)!;
return res;
}
(changed it so that current is clamped to 0 and also gets the correct element)
Just update it and the pull request should update. I always squash pull requests in the end, so it doesn't matter if there are multiple commits.
Ok good to know! Just fixed it.
Looks like there's still an error?
Yeah sorry about that, I'm still trying to setup my environment for c3 so I was editing it in github. It should (hopefully) be fixed now.
Thank you for your patience. :)
Oh, I noticed there were no tests, can you add some tests? You can look into /test/unit/stdlib for examples. Just something to check what happens if each is called in the beginning, in the end and at the end where there is an invalid UTF8 sequence.
Ok ill do that.
Done! Sorry for all of the hassle this is my first PR so thank you for being patient with me. Also just wondering how do you build the Debian binaries? The default Debian package repo does not have llvm-17. (I ended up just using a virtual machine to test with)
I grab the llvm binaries from the LLVM org directly. If you look at this: https://github.com/c3lang/c3c/blob/master/.github/workflows/main.yml
You can scroll down and see exactly the commands that are run to build the compiler for the different targets. You should be able to figure it out even if you don't know how Github defines things, because the actual commands are just direct commands send to the command line for each machine.
Also, the first PR and getting the hang of what's needed is always a bit of a learning experience. Don't worry about it.
Thanks for your understanding!
Thank you!