Skip to content

Commit 3198752

Browse files
chore: added trim extension function to String
1 parent a5c56ea commit 3198752

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Sources/Core/EthereumABI/ABIElements.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public extension ABI {
7777
public let type: ParameterType
7878

7979
public init(name: String, type: ParameterType) {
80-
self.name = name
80+
self.name = name.trim()
8181
self.type = type
8282
}
8383
}
@@ -91,7 +91,7 @@ public extension ABI {
9191
public let payable: Bool
9292

9393
public init(name: String?, inputs: [InOut], outputs: [InOut], constant: Bool, payable: Bool) {
94-
self.name = name
94+
self.name = name?.trim()
9595
self.inputs = inputs
9696
self.outputs = outputs
9797
self.constant = constant
@@ -103,6 +103,7 @@ public extension ABI {
103103
public let inputs: [InOut]
104104
public let constant: Bool
105105
public let payable: Bool
106+
106107
public init(inputs: [InOut], constant: Bool, payable: Bool) {
107108
self.inputs = inputs
108109
self.constant = constant
@@ -126,7 +127,7 @@ public extension ABI {
126127
public let anonymous: Bool
127128

128129
public init(name: String, inputs: [Input], anonymous: Bool) {
129-
self.name = name
130+
self.name = name.trim()
130131
self.inputs = inputs
131132
self.anonymous = anonymous
132133
}
@@ -137,7 +138,7 @@ public extension ABI {
137138
public let indexed: Bool
138139

139140
public init(name: String, type: ParameterType, indexed: Bool) {
140-
self.name = name
141+
self.name = name.trim()
141142
self.type = type
142143
self.indexed = indexed
143144
}

Sources/Core/Utility/String+Extension.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ extension String {
130130
return Int(s[s.startIndex].value)
131131
}
132132
}
133+
134+
/// Strips whitespaces and newlines on both ends.
135+
func trim() -> String {
136+
trimmingCharacters(in: .whitespacesAndNewlines)
137+
}
133138
}
134139

135140
extension Character {

0 commit comments

Comments
 (0)