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

[SR-6395] 'Substring.SubSequence' (aka 'Substring') has no member 'trimmingCharacters' or 'hasSuffix' #4055

Closed
swift-ci opened this issue Nov 15, 2017 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-6395
Radar rdar://35552237
Original Reporter p_thompson (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Linux w/ Swift 4

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 817ca51797142c68cbaea3fcdd3f2e76

Issue Description:

I'm trying to do some string processing that looks something like this:

import Foundation

let lines = """
BuildVersion: "123"
ProductType: "SomeProduct1,2"
HWModelStr: "TotallyNotAP"
"""

for line in lines.split(separator: "\n", omittingEmptySubsequences: true) {
var x: String
if line.starts(with: "BuildVersion") {
x = String(line.split(separator: """)[1])
} else if line.starts(with: "ProductType") {
x = line.split(separator: """)[1]
.trimmingCharacters(in: CharacterSet.letters.inverted)
.lowercased()
} else if line.starts(with: "HWModelStr") {
let y = line.split(separator: """)[1]
if y.hasSuffix("AP") {
x = String(y.dropLast(2))
} else {
x = String👍
}
} else {
x = ""
}

print❌
}

Which works in Darwin land,
>>>
123
someproduct
TotallyNot

but on Linux I get errors like

error: terminated(1): /usr/bin/swift-build-tool -f /swift-execution/.build/debug.yaml main
ERROR at line 34, col 40: value of type 'Substring.SubSequence' (aka 'Substring') has no member 'trimmingCharacters'
x = line.split(separator: """)[1]
~~~~~~~~~~~~~~~~~~~~~~~~~~^~
ERROR at line 39, col 12: value of type 'Substring.SubSequence' (aka 'Substring') has no member 'hasSuffix'
if y.hasSuffix("AP") {
^ ~~~~~~~~~

I would expect these functions to work here.

@belkadan
Copy link

cc @airspeedswift in addition to the Foundation people

@spevans
Copy link
Collaborator

spevans commented Aug 24, 2018

This has been fixed in 4.2 branch

$ ~/swift-4.1.3-RELEASE-ubuntu16.04/usr/bin/swift sr_6395.swift 
sr_6395.swift:18:8: error: value of type 'Substring.SubSequence' (aka 'Substring') has no member 'hasSuffix'
    if y.hasSuffix("AP") {
       ^ ~~~~~~~~~
$ ~/swift-4.2-CONVERGENCE-ubuntu16.04/usr/bin/swift sr_6395.swift 
123
someproduct
TotallyNot

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants