Skip to content

Instantly share code, notes, and snippets.

@TrueBrain
Created January 16, 2022 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrueBrain/1fafce9fb04d56b5caaa3c57f1ffc183 to your computer and use it in GitHub Desktop.
Save TrueBrain/1fafce9fb04d56b5caaa3c57f1ffc183 to your computer and use it in GitHub Desktop.
CoPilot remains scary

I wrote:

fn split_whitespace(string: &str) -> Vec<String> {
    let mut line = 1;
    let mut position = 1;

GitHub CoPilot wrote:

    let mut tokens = Vec::new();
    let mut current_token = String::new();

    for c in string.chars() {
        if c == '\n' {
            line += 1;
            position = 1;
        } else {
            position += 1;
        }

        if c.is_whitespace() {
            if !current_token.is_empty() {
                tokens.push(current_token);
                current_token = String::new();
            }
        } else {
            current_token.push(c);
        }
    }

    if !current_token.is_empty() {
        tokens.push(current_token);
    }

    tokens
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment