Porting code to Linux: issue with Scanner

Hello,

I am porting so Swift library code to Linux and I have issue with Scanner.scanUpTo.

It seems that some form of this method (without into: parameter) is available in Swift corelibs foundation: swift-corelibs-foundation/Scanner.swift at f5a076deb72b63896433d2dcd2af0d3b48ac2ae8 · apple/swift-corelibs-foundation · GitHub

However, I am not sure how to leverage this and make the code multiplatform.
Importing Foundation on Linux is not enough to make it available.

Any tips ?

Thanks !

@Tony_Parker, is this a missing method in corelibs-foundation?

@millenomi is looking into this.

Indeed! Stay tuned.

1 Like

Hi,

I am not yet sure why it is needed, but I could wrap the difference between ScanUpTo on MacOS and Linux as follow:

fileprivate extension Scanner {
    func scanUpToWrap(string: String) -> String? {
        #if canImport(Darwin)
        var result: NSString?
        guard scanUpTo(string, into: &result) != false else { return nil }
        return result as String?
        #else
        return scanUpToString(string)
        #endif
    }
}