GitXplorerGitXplorer
5

in-place-string-map

public
3 stars
1 forks
0 issues

Commits

List of commits on branch main.
Unverified
6891e0ee7dac1aee7ceef0c86684993fbb48e7bb

Add contact info to readme, exclude unimportant files from package

55225225 committed 4 years ago
Unverified
3b80a77374328050e6d3d2ba357db1413f27104e

clean up code some more, add license

55225225 committed 4 years ago
Unverified
2bd588ec60aceda67317194f6ebddfbda62763be

getting ready for a release maybe

55225225 committed 4 years ago
Unverified
381376d1db8abfec12d5c70712b4c9098b1260cb

adjust comment

55225225 committed 4 years ago
Unverified
8544346dc8484f652d7f6e19f4ad6e0c37ad4194

Add partial zero optimisation

55225225 committed 4 years ago
Unverified
1f90b2aaa2ef1377ef69d627b80357ae685ec59f

Improve fuzzing, find bugs found through it.

55225225 committed 4 years ago

README

The README file for this repository.

in-place-string-map

Someone said C was better than Rust at in-place string modifications. So I made this.

use in_place_string_map::MapInPlace;

fn decode_percent(s: &mut str) -> &mut str {
    let mut m = MapInPlace::new(s);

    while let Some(c) = m.pop() {
        match c {
            '%' => {
                let num = m.pop_chars(2).expect("not enough chars");
                let n = u8::from_str_radix(num, 16).expect("invalid hex");
                m.push(n as char).expect("no more capacity");
            }
            _ => {
                m.push(c).expect("no more capacity");
            }
        }
    }

    m.into_mapped()
}

The only thing you need to be careful of is to not push more bytes than you have popped so far. Here it's fine since %ff is 2 bytes long (the longest it can be) but took 3 bytes of source text. It's not unsafe to do this of course, you'll just fail to push.

More details about how it works are both in the code (it's somewhat commented) and the blog post.

Bugs / Suggestions?

I have a mirror of the repo over on https://github.com/5225225/in-place-string-map (This is not the canonical URL, that is hosted on my gitea at https://git.5snb.club/5225225/in-place-string-map). Feel free to make issues/pull requests against the github repo. Alternatively, contact me (Email in the authors field, or read the commit emails).