Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substring Value #11

Closed
AlexCreamer opened this issue Mar 30, 2017 · 14 comments
Closed

Substring Value #11

AlexCreamer opened this issue Mar 30, 2017 · 14 comments

Comments

@AlexCreamer
Copy link

Hi, how do I use the following crate to return a string value so that "I like maple apples." Would return "I like maple" on pati: 0, start: 0, end: 11.

@BurntSushi
Copy link
Owner

I don't understand the question. Could you please explain what problem you're trying to solve? What have you tried? Have you looked at the examples in the docs? https://docs.rs/aho-corasick/0.6.3/aho_corasick/

@AlexCreamer
Copy link
Author

I want to be able to do the following

let value = Some(Match {
        pati: 0,
        start: 0,
        end: 11
});

where value would be "I like maple".

@AlexCreamer
Copy link
Author

I've checked the documentation and it seems to be only useful when using assert_eq

@BurntSushi
Copy link
Owner

@AlexCreamer Could you take a look at the second example in the docs here please? https://docs.rs/aho-corasick/0.6.3/aho_corasick/ --- In particular, if you replace this:

let aut = AcAutomaton::new(vec!["apple", "maple"]);

with this:

let aut = AcAutomaton::new(vec!["I like maple"]);

then does that do what you want?

@BurntSushi
Copy link
Owner

If you want the actual text that was matched, then all you need to do is ask AcAutomaton for the pattern at index pati. In particular, the matched text is guaranteed to be byte-for-byte equivalent to at least one of the patterns given to search.

@BurntSushi
Copy link
Owner

Check out the fourth example here: https://docs.rs/aho-corasick/0.6.3/aho_corasick/

@AlexCreamer
Copy link
Author

AlexCreamer commented Mar 30, 2017

What if I don't know the text to match, all I have is index, such as:
pati: 0,
start: 0,
end: 11

@BurntSushi
Copy link
Owner

@AlexCreamer Please, please, please help me help you. Describe the problem you're trying to solve. I don't understand what you're asking. Therefore, I don't know how to help you. Can you show code? Can you say more about what you've tried? Did you actually try running the fourth example? Does it do what you want? If not, what's missing?

@AlexCreamer
Copy link
Author

Here's an example code I'm working on: https://is.gd/zsVtBo

I want the remove_brackets function to remove brackets and anything withint the brackets out of a string. The brackets "()" occur only once and they occur at the end of a string, as such: "Lorem Ipsum (crap)", where I would only keep the string "Lorem Ipsum".

@BurntSushi
Copy link
Owner

Why not just use the regex crate to do this?

@AlexCreamer
Copy link
Author

Coming from a Java background I was hoping for something similar to it's "substring" functionality where I can just input index's. Plus I'm not familiar with the regex crate. I'll look into it, thanks. Feel free to close this issue.

@BurntSushi
Copy link
Owner

@AlexCreamer Sure, you don't need a regex for this. You could do something very simple: https://is.gd/cSkowC

Aho-Corasick definitely seems like the wrong tool for this. It would be helpful to know how you wound up here so we can fix that in the future. Aho-Corasick is a relatively specialized algorithm for efficient multiple pattern search. If you don't need super fast multiple pattern search, then Aho-Corasick isn't something you should be caring about. See more here: https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm

@AlexCreamer
Copy link
Author

I searched for "substring" on crates.io and it was one of the only relevant crates.

@BurntSushi
Copy link
Owner

@AlexCreamer OK, thanks so much, I filed an issue so that this gets improved: rust-lang/book#583

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

No branches or pull requests

2 participants