Skip to content

Implement NSTextCheckingResult.range(withName:) #1522

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

Merged
merged 1 commit into from
Feb 13, 2019

Conversation

nevil
Copy link
Contributor

@nevil nevil commented Apr 18, 2018

  • Added the missing range(withName:) and corresponding CF function.
    The implementation relies on uregex_groupNumberFromName which is
    available as a draft API from ICU 55.

  • Added tests related to named capture groups.

@spevans
Copy link
Contributor

spevans commented Apr 18, 2018

@swift-ci please test

@nevil
Copy link
Contributor Author

nevil commented Apr 18, 2018

I realized that I'm not sure what to do with the availability story.
Should I do the following:

  1. add API_AVAILABLE(macosx(10.13), ios(11.0), watchos(4.0), tvos(11.0)) to the CF API
  2. add @available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) to the NSTextCheckingResult API
  3. Condition the unit tests based on availability?

@parkera
Copy link
Contributor

parkera commented Apr 22, 2018

@swift-ci please test

@nevil nevil force-pushed the add-range-withname-support branch from 0aedad0 to e167c45 Compare April 23, 2018 23:30
@nevil
Copy link
Contributor Author

nevil commented Apr 23, 2018

@parkera Seems like the test wasn't run or the result not reported back?

@spevans
Copy link
Contributor

spevans commented Apr 24, 2018

@swift-ci please test

@nevil
Copy link
Contributor Author

nevil commented Apr 24, 2018

The build passed but the from log it seems it was run on a commit that was squashed and no longer exist (0aedad0) even before @spevans requested the build ...
https://ci.swift.org/job/swift-corelibs-foundation-PR-Linux/918/

@nevil
Copy link
Contributor Author

nevil commented Apr 26, 2018

Would a kind soul please rerun the test? :-)

@spevans
Copy link
Contributor

spevans commented Apr 26, 2018

@swift-ci please test

@nevil
Copy link
Contributor Author

nevil commented May 7, 2018

@parkera
Is there anything more I should do for this PR?

Not sure what the normal review time frames are...

Copy link
Contributor

@millenomi millenomi left a comment

Choose a reason for hiding this comment

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

Just one nitpick and then it’s good to merge:

@@ -57,6 +57,7 @@ _CFRegularExpressionRef _Nullable _CFRegularExpressionCreate(CFAllocatorRef allo
void _CFRegularExpressionDestroy(_CFRegularExpressionRef regex);

CFIndex _CFRegularExpressionGetNumberOfCaptureGroups(_CFRegularExpressionRef regex);
CFIndex _CFRegularExpressionGetCaptureGroupNumberWithName(_CFRegularExpressionRef regex, CFStringRef groupName) API_AVAILABLE(macosx(10.13), ios(11.0), watchos(4.0), tvos(11.0));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why availability annotations? Internal calls do not need them, and in this case they would also be inaccurate (this call isn’t on any of the mentioned OSes.)

Just remove them, here and in the Swift code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @millenomi !

I wasn't sure what to do with the annotations so to be safe I made sure to add to all APIs.
Sorry for that.

I removed on internal APIs and only left on the public NSTextCheckingResult.range(withName:).

@nevil nevil force-pushed the add-range-withname-support branch from e167c45 to 4b22b29 Compare May 7, 2018 07:19
@spevans
Copy link
Contributor

spevans commented May 7, 2018

@swift-ci please test

@nevil
Copy link
Contributor Author

nevil commented May 7, 2018

@spevans Thanks for starting the build!
Unfortunately it really looks like the swift CI infrastructure does not like git rebases...
The current commit is 4b22b29 but the build is running on e167c45, which was the commit before the rebase...

https://ci.swift.org/view/Pull%20Request/job/swift-corelibs-foundation-PR-Linux/961/console

@spevans
Copy link
Contributor

spevans commented May 7, 2018

There is just one issue I see with this change and its that Ubuntu 14.04 uses ICU 52 and so doesn't have the uregex_groupNumberFromName function from what I can see (checking the libs on my 14.04 install).

Is it possible to use the U_ICU_VERSION_MAJOR_NUM (defined as 52 on 14.04 and 55 on 16.04) to mark this function as unavailable on the older version (or maybe there is an alternative solution).

I think this will cause problems if merged as it will then break the 14.04 package build (although it is current broken due to a different 14.04/ ICU issue anyway, see #1537)

@spevans
Copy link
Contributor

spevans commented May 7, 2018

@nevil swift-ci looks fine, its just misleading with the first comment.
There is a log entry that says

Commit message: "Merge 4b22b2929e253bf50564498cf4e208443e8559d0 into 55bb988867eb5c8e174d67a0f91a15d9efdd072a"

which means its merging in the correct version.
Rebases and force pushes work fine, I use them all the time without issue.

@nevil
Copy link
Contributor Author

nevil commented May 7, 2018

@spevans You're correct. Looks like the commit hash mismatch is just for the GitHub build status reporting...

I could of course use U_ICU_VERSION_MAJOR_NUM (or some other flag) to conditionally enable the _CFRegularExpressionGetCaptureGroupNumberWithName, but the question is if this is an acceptable workaround until all supported Linux versions use the same ICU library?

It would introduce a version difference that can not be checked through the use of availability annotation checks...

@spevans
Copy link
Contributor

spevans commented May 7, 2018

You could do something like the following:

Define HAS_ICU_GROUP_NUMBER_FROM_NAME based on the ICU version and conditionally compile the support functions, then add:

#if !HAS_ICU_GROUP_NUMBER_FROM_NAME
@available(*, unavailable, message: "Unuspported with this version of ICU")
override func range(withName name: String) -> NSRange {
  NSUnsupported()
}
#else
override func range(withName name: String) -> NSRange {
.
.
.
}
#endif

@nevil nevil force-pushed the add-range-withname-support branch from 4b22b29 to bb56345 Compare May 25, 2018 10:20
@millenomi
Copy link
Contributor

@nevil What do you think about @spevans's suggestion?

@nevil
Copy link
Contributor Author

nevil commented May 26, 2018

@millenomi
I will try to implement something like what he suggested.
Unfortunately I haven't had time to study the build system until now.

@millenomi
Copy link
Contributor

@nevil Are you still interested in chaperoning this patch?

@nevil
Copy link
Contributor Author

nevil commented Oct 11, 2018

@millenomi
My intention was to complete the task ASAP back in May, but I had the problem that my local machine doesn't have enough RAM to do a complete linux build in a VM. I thought I would have access to a better machine soon, but didn't and then time passed quickly...

Sorry for that!
I still have an interest and would like to complete the PR.

Is it best to try to get this in with build time version detection of ICU (as suggested here
#1522 (comment)) or wait for

https://forums.swift.org/t/building-libicu-as-part-of-the-linux-swift-build/16526/8 to settle?
https://bugs.swift.org/browse/SR-8876 .

@spevans
Copy link
Contributor

spevans commented Oct 11, 2018

@nevil The PR to always build the latest version of ICU for linux should hopefully be ready in the next day or so - I just have to fix one LLDB test - so you can probably leave the version detection out now. In fact it will be good to since it should catch builds using the old version since the symbols won't be defined.

@nevil
Copy link
Contributor Author

nevil commented Oct 11, 2018

@spevans Great. Thank you very much!

I will rebase this PR on the latest master branch in preparation for your PR to be merged.

@nevil nevil force-pushed the add-range-withname-support branch from bb56345 to d8ed8a6 Compare October 11, 2018 13:58
@nevil
Copy link
Contributor Author

nevil commented Oct 11, 2018

Nothing had really changed in the touched files so the rebase was straight forward.

@nevil
Copy link
Contributor Author

nevil commented Oct 20, 2018

Waiting for swiftlang/swift#19860

@nevil nevil force-pushed the add-range-withname-support branch from d8ed8a6 to 2772e1a Compare November 5, 2018 01:59
@nevil
Copy link
Contributor Author

nevil commented Nov 5, 2018

@spevans
Now that swiftlang/swift#19860 is merged, my understanding is that we will always use a compatible ICU version.
Is there anything build related I should consider in this PR?

@spevans
Copy link
Contributor

spevans commented Nov 5, 2018

@swift-ci test

@nevil
Copy link
Contributor Author

nevil commented Nov 6, 2018

@millenomi
I think the build passed.
Please review again when you have time.

Thanks!

@nevil nevil force-pushed the add-range-withname-support branch from 2772e1a to 65319df Compare November 26, 2018 11:14
@nevil nevil force-pushed the add-range-withname-support branch from 65319df to 34f3ce5 Compare December 8, 2018 01:44
@nevil nevil force-pushed the add-range-withname-support branch from 34f3ce5 to 8ce01f2 Compare January 17, 2019 07:11
- Added the missing range(withName:) and corresponding CF function.
The implementation relies on uregex_groupNumberFromName which is
available as a draft API from ICU 55.

- Added tests related to named capture groups.

- Add availability checks in the tests to run with DarwinCompatibilityTests.
@nevil nevil force-pushed the add-range-withname-support branch from 8ce01f2 to 35739c9 Compare February 12, 2019 01:50
@nevil
Copy link
Contributor Author

nevil commented Feb 12, 2019

@millenomi
Hi, I understand that you are busy with Swift 5.
Just read the latest https://nshipster.com/swift-regular-expressions/ and noticed that named capture groups are mentioned...

Any chance of reviewing again?

@spevans
Copy link
Contributor

spevans commented Feb 12, 2019

@swift-ci please test

@parkera
Copy link
Contributor

parkera commented Feb 13, 2019

This looks good to me.

@parkera
Copy link
Contributor

parkera commented Feb 13, 2019

Sorry this took so long and thank you for the contribution!

@parkera parkera merged commit 531cca6 into swiftlang:master Feb 13, 2019
@nevil
Copy link
Contributor Author

nevil commented Feb 13, 2019

@parkera
We all have lots of things to do :-)
Thank you for merging!

@nevil nevil deleted the add-range-withname-support branch February 13, 2019 22:24
tomerd added a commit to tomerd/swift-tools-support-core that referenced this pull request May 3, 2021
motivation:
* netrc functionality is useful on all platforms, the regex functionality was added to non-darwin foundation
* see swiftlang/swift-corelibs-foundation#1522

changes: remove platforms restructions where appropriate
tomerd added a commit to tomerd/swift-tools-support-core that referenced this pull request May 3, 2021
motivation:
* netrc functionality is useful on all platforms, the regex functionality was added to non-darwin foundation
* see swiftlang/swift-corelibs-foundation#1522

changes: remove platforms restructions where appropriate
tomerd added a commit to swiftlang/swift-tools-support-core that referenced this pull request May 4, 2021
motivation:
* netrc functionality is useful on all platforms, the regex functionality was added to non-darwin foundation
* see swiftlang/swift-corelibs-foundation#1522

changes: remove platforms restructions where appropriate
tomerd added a commit to tomerd/swift-tools-support-core that referenced this pull request May 4, 2021
motivation:
* netrc functionality is useful on all platforms, the regex functionality was added to non-darwin foundation
* see swiftlang/swift-corelibs-foundation#1522

changes: remove platforms restructions where appropriate
tomerd added a commit to tomerd/swift-tools-support-core that referenced this pull request May 26, 2021
motivation:
* netrc functionality is useful on all platforms, the regex functionality was added to non-darwin foundation
* see swiftlang/swift-corelibs-foundation#1522

changes: remove platforms restructions where appropriate
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.

4 participants