Skip to content

Commit 301347c

Browse files
committed
Rename and rearrange some internal vs SPI methods
1 parent f75d91a commit 301347c

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

Sources/FoundationEssentials/Decimal/Decimal+Compatibility.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public func _NSDecimalCompact(_ number: UnsafeMutablePointer<Decimal>) {
410410
_ locale: Any? = nil
411411
) -> String {
412412
let useLocale = locale as? Locale
413-
return decimal.pointee.toString(with: useLocale)
413+
return decimal.pointee._toString(with: useLocale)
414414
}
415415

416416
#if FOUNDATION_FRAMEWORK
@@ -431,7 +431,7 @@ internal func __NSStringToDecimal(
431431
processedLength: UnsafeMutablePointer<Int>,
432432
result: UnsafeMutablePointer<Decimal>
433433
) {
434-
let parsed = Decimal.decimal(
434+
let parsed = Decimal._decimal(
435435
from: string.utf8,
436436
decimalSeparator: ".".utf8,
437437
matchEntireString: false

Sources/FoundationEssentials/Decimal/Decimal+Conformances.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ internal import _ForSwiftFoundation
142142
extension Decimal : CustomStringConvertible {
143143
public init?(string: __shared String, locale: __shared Locale? = nil) {
144144
let decimalSeparator = locale?.decimalSeparator ?? "."
145-
guard let value = Decimal.decimal(
145+
guard let value = Decimal._decimal(
146146
from: string.utf8,
147147
decimalSeparator: decimalSeparator.utf8,
148148
matchEntireString: false
@@ -153,7 +153,7 @@ extension Decimal : CustomStringConvertible {
153153
}
154154

155155
public var description: String {
156-
return self.toString()
156+
return self._toString()
157157
}
158158
}
159159

Sources/FoundationEssentials/Decimal/Decimal.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,23 @@ extension Decimal {
183183

184184
// MARK: - String
185185
extension Decimal {
186+
#if FOUNDATION_FRAMEWORK
187+
#else
186188
@_spi(SwiftCorelibsFoundation)
187189
public func toString(with locale: Locale? = nil) -> String {
190+
_toString(with: locale)
191+
}
192+
193+
@_spi(SwiftCorelibsFoundation)
194+
public static func decimal(
195+
from stringView: String.UTF8View,
196+
decimalSeparator: String.UTF8View,
197+
matchEntireString: Bool
198+
) -> (result: Decimal?, processedLength: Int) {
199+
_decimal(from: stringView, decimalSeparator: decimalSeparator, matchEntireString: matchEntireString)
200+
}
201+
#endif
202+
internal func _toString(with locale: Locale? = nil) -> String {
188203
if self.isNaN {
189204
return "NaN"
190205
}
@@ -235,8 +250,7 @@ extension Decimal {
235250
return String(buffer.reversed())
236251
}
237252

238-
@_spi(SwiftCorelibsFoundation)
239-
public static func decimal(
253+
internal static func _decimal(
240254
from stringView: String.UTF8View,
241255
decimalSeparator: String.UTF8View,
242256
matchEntireString: Bool

Sources/FoundationEssentials/JSON/JSONDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ extension FixedWidthInteger {
10741074

10751075
extension Decimal {
10761076
init?(entire string: String) {
1077-
guard let value = Decimal.decimal(
1077+
guard let value = Decimal._decimal(
10781078
from: string.utf8,
10791079
decimalSeparator: ".".utf8,
10801080
matchEntireString: true

Tests/FoundationEssentialsTests/DecimalTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ final class DecimalTests : XCTestCase {
112112

113113
func test_DescriptionWithLocale() {
114114
let decimal = Decimal(string: "-123456.789")!
115-
XCTAssertEqual(decimal.toString(with: nil), "-123456.789")
116-
let en = decimal.toString(with: Locale(identifier: "en_GB"))
115+
XCTAssertEqual(decimal._toString(with: nil), "-123456.789")
116+
let en = decimal._toString(with: Locale(identifier: "en_GB"))
117117
XCTAssertEqual(en, "-123456.789")
118-
let fr = decimal.toString(with: Locale(identifier: "fr_FR"))
118+
let fr = decimal._toString(with: Locale(identifier: "fr_FR"))
119119
XCTAssertEqual(fr, "-123456,789")
120120
}
121121

0 commit comments

Comments
 (0)