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

Add Regex type #18

Merged
merged 6 commits into from
Apr 22, 2018
Merged

Add Regex type #18

merged 6 commits into from
Apr 22, 2018

Conversation

fredpi
Copy link
Contributor

@fredpi fredpi commented Mar 19, 2018

This is my suggestion for Regex in HandySwift. Please comment on whether this is suitable.

Note: It's not tested and documented yet, I will do that on approval.

Would close #14.

Copy link
Member

@Jeehut Jeehut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API looks good to me. Please consider my feedback and feel free to add documentation, tests and Playground usage examples to make this merge-ready. Thank you for your work!

// Created by Frederick Pietschmann on 19.03.18.
// Copyright © 2018 Flinesoft. All rights reserved.
//
// Taken from https://github.com/sharplet/Regex, then modified to remove some weight.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Originally from: https://... instead. Also place a second whitespace at the beginning to allign with the above.

///
/// - returns: `true` if the regular expression matches, otherwise `false`.
public func matches(_ string: String) -> Bool {
return !matches(in: string).isEmpty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is enough reason to also introduce the firstMatch method and use it here. This implementation will be very slow (even in average) if the underlying text is a long text. Using firstMatch here would improve the average performance a lot for many cases. Please also note that the firstMatch(in:) should be public as I feel like it's needed as often as matches(in:) -> [Match]) is.

@Jeehut
Copy link
Member

Jeehut commented Apr 8, 2018

Any updates on this?

@fredpi
Copy link
Contributor Author

fredpi commented Apr 8, 2018

@Dschee I added the first match interface as suggested, while documentation and tests are yet to be created.

Copy link
Member

@Jeehut Jeehut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good overall. Just found a small commenting problem, probably. Other than that, only tests and docs are missing now.

///
/// - returns: An optional `Match` describing the first match, or `nil`.
///
/// - note: If the match is successful, the result is also stored in `Regex.lastMatch`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is true. You removed the lastMatch, no?

@Jeehut
Copy link
Member

Jeehut commented Apr 20, 2018

Nice, seems like only a new README section is missing, no? Thank you very much for all the work done so far. 👍

@fredpi fredpi changed the title [WIP] Add Regex type Add Regex type Apr 20, 2018
@fredpi
Copy link
Contributor Author

fredpi commented Apr 20, 2018

@Dschee You're welcome. With the readme now being done, this PR is now ready to merge if there aren't any issues / further suggestions.

@Jeehut
Copy link
Member

Jeehut commented Apr 22, 2018

Looks good, merging. 🎉

@Jeehut Jeehut merged commit 9bc62c1 into FlineDev:stable Apr 22, 2018
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.

Add =~ operator for regex check
2 participants