Skip to content

corrected find_enum and find_message for keyword identifiers#76

Open
awestlake87 wants to merge 1 commit into
tafia:masterfrom
awestlake87:fix-keyword-suffixes
Open

corrected find_enum and find_message for keyword identifiers#76
awestlake87 wants to merge 1 commit into
tafia:masterfrom
awestlake87:fix-keyword-suffixes

Conversation

@awestlake87
Copy link
Copy Markdown

No description provided.

@tafia
Copy link
Copy Markdown
Owner

tafia commented Oct 10, 2017

First thanks for the PR and sorry for answering this late.

Can you please give more context why it is needed. Could you add a broken test for instance?
As for your fn here is a rustier version of if, (could be enhanced but performance of codegen is really not critical.

pub fn get_ident(ident: &str) -> String { // `&String` is usually replaced with more generic `&str` which both point to the same data
    if !ident.contains('.') {
        if RUST_KEYWORDS.contains(&ident) {
            format!("{}_pb", ident) // this will create a new `String`, probably without new allocation
        }
        else {
            ident.clone()
        }
    }
    else {
        ident.split('.').map(|s| get_ident(s)).collect::<Vec<_>>().join(".") // not pretty but ok!, note that i could remove the `to_string` because I changed the signature to work with `&str`
    }
}

@awestlake87
Copy link
Copy Markdown
Author

Oh, yeah my bad. I made issue #75 when I made the pull request, but i forgot to link it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants