c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Update string_iterator.c3 to include extra convenience methods

Open ellipse12 opened this issue 1 year ago • 11 comments

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.

ellipse12 avatar Aug 08 '24 00:08 ellipse12

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)

ellipse12 avatar Aug 08 '24 02:08 ellipse12

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.

lerno avatar Aug 08 '24 11:08 lerno

Ok good to know! Just fixed it.

ellipse12 avatar Aug 08 '24 14:08 ellipse12

Looks like there's still an error?

lerno avatar Aug 08 '24 17:08 lerno

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.

ellipse12 avatar Aug 08 '24 18:08 ellipse12

Thank you for your patience. :)

ellipse12 avatar Aug 08 '24 19:08 ellipse12

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.

lerno avatar Aug 08 '24 20:08 lerno

Ok ill do that.

ellipse12 avatar Aug 08 '24 21:08 ellipse12

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)

ellipse12 avatar Aug 09 '24 00:08 ellipse12

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.

lerno avatar Aug 09 '24 08:08 lerno

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.

lerno avatar Aug 09 '24 08:08 lerno

Thanks for your understanding!

ellipse12 avatar Aug 09 '24 17:08 ellipse12

Thank you!

lerno avatar Aug 09 '24 21:08 lerno