Skip to content

[Test] Remove stdlib/NSStringAPI.swift and some supporting code. #67252

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
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,6 @@ import ObjectiveC
import Foundation
import StdlibUnittest

internal var _temporaryLocaleCurrentLocale: NSLocale?

extension NSLocale {
@objc
public class func __swiftUnittest_currentLocale() -> NSLocale {
return _temporaryLocaleCurrentLocale!
}
}

public func withOverriddenLocaleCurrentLocale<Result>(
_ temporaryLocale: NSLocale,
_ body: () -> Result
) -> Result {
guard let oldMethod = class_getClassMethod(
NSLocale.self, #selector(getter: NSLocale.current)) as Optional
else {
preconditionFailure("Could not find +[Locale currentLocale]")
}

guard let newMethod = class_getClassMethod(
NSLocale.self, #selector(NSLocale.__swiftUnittest_currentLocale)) as Optional
else {
preconditionFailure("Could not find +[Locale __swiftUnittest_currentLocale]")
}

precondition(_temporaryLocaleCurrentLocale == nil,
"Nested calls to withOverriddenLocaleCurrentLocale are not supported")

_temporaryLocaleCurrentLocale = temporaryLocale
method_exchangeImplementations(oldMethod, newMethod)
let result = body()
method_exchangeImplementations(newMethod, oldMethod)
_temporaryLocaleCurrentLocale = nil

return result
}

public func withOverriddenLocaleCurrentLocale<Result>(
_ temporaryLocaleIdentifier: String,
_ body: () -> Result
) -> Result {
precondition(
NSLocale.availableLocaleIdentifiers.contains(temporaryLocaleIdentifier),
"Requested locale \(temporaryLocaleIdentifier) is not available")

return withOverriddenLocaleCurrentLocale(
NSLocale(localeIdentifier: temporaryLocaleIdentifier), body)
}

/// Executes the `body` in an autorelease pool if the platform does not
/// implement the return-autoreleased optimization.
///
Expand Down
Loading