Skip to content

Commit da2947f

Browse files
author
Dave Abrahams
committed
encode(_:output:) => encode(_:into processCodeUnit:)
1 parent b004494 commit da2947f

10 files changed

+45
-44
lines changed

Diff for: stdlib/public/core/Character.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public struct Character :
9292
shift += 8
9393
}
9494

95-
UTF8.encode(scalar, sendingOutputTo: output)
95+
UTF8.encode(scalar, into: output)
9696
asInt |= (~0) << shift
9797
_representation = .small(Builtin.trunc_Int64_Int63(asInt._value))
9898
}
@@ -297,7 +297,7 @@ public struct Character :
297297
_SmallUTF8(u8).makeIterator(),
298298
from: UTF8.self, to: UTF16.self,
299299
stoppingOnError: false,
300-
sendingOutputTo: output)
300+
into: output)
301301
self.data = u16
302302
}
303303

Diff for: stdlib/public/core/StaticString.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public struct StaticString
135135
buffer = buffer | (UInt64($0) << (UInt64(i) * 8))
136136
i += 1
137137
}
138-
UTF8.encode(unicodeScalar, sendingOutputTo: sink)
138+
UTF8.encode(unicodeScalar, into: sink)
139139
return body(UnsafeBufferPointer(
140140
start: UnsafePointer(Builtin.addressof(&buffer)),
141141
count: i))

Diff for: stdlib/public/core/String.swift

+6-5
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ extension String {
468468
Encoding: UnicodeCodec
469469
>(_ encoding: Encoding.Type) -> Int {
470470
var codeUnitCount = 0
471-
let output: (Encoding.CodeUnit) -> Void = { _ in codeUnitCount += 1 }
472-
self._encode(encoding, output: output)
471+
self._encode(encoding, into: { _ in codeUnitCount += 1 })
473472
return codeUnitCount
474473
}
475474

@@ -482,9 +481,11 @@ extension String {
482481
// with unpaired surrogates
483482
func _encode<
484483
Encoding: UnicodeCodec
485-
>(_ encoding: Encoding.Type, output: @noescape (Encoding.CodeUnit) -> Void)
486-
{
487-
return _core.encode(encoding, output: output)
484+
>(
485+
_ encoding: Encoding.Type,
486+
into processCodeUnit: @noescape (Encoding.CodeUnit) -> Void
487+
) {
488+
return _core.encode(encoding, into: processCodeUnit)
488489
}
489490
}
490491

Diff for: stdlib/public/core/StringBuffer.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public struct _StringBuffer {
116116
input.makeIterator(),
117117
from: encoding, to: UTF32.self,
118118
stoppingOnError: true,
119-
sendingOutputTo: sink)
119+
into: sink)
120120
_sanityCheck(!hadError, "string cannot be ASCII if there were decoding errors")
121121
return (result, hadError)
122122
}
@@ -130,7 +130,7 @@ public struct _StringBuffer {
130130
input.makeIterator(),
131131
from: encoding, to: UTF16.self,
132132
stoppingOnError: !repairIllFormedSequences,
133-
sendingOutputTo: sink)
133+
into: sink)
134134
return (result, hadError)
135135
}
136136
}

Diff for: stdlib/public/core/StringCore.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,17 @@ public struct _StringCore {
329329
}
330330

331331
/// Write the string, in the given encoding, to output.
332-
func encode<
333-
Encoding: UnicodeCodec
334-
>(_ encoding: Encoding.Type, output: @noescape (Encoding.CodeUnit) -> Void)
332+
func encode<Encoding: UnicodeCodec>(
333+
_ encoding: Encoding.Type,
334+
into processCodeUnit: @noescape (Encoding.CodeUnit) -> Void)
335335
{
336336
if _fastPath(_baseAddress != nil) {
337337
if _fastPath(elementWidth == 1) {
338338
for x in UnsafeBufferPointer(
339339
start: UnsafeMutablePointer<UTF8.CodeUnit>(_baseAddress!),
340340
count: count
341341
) {
342-
Encoding.encode(UnicodeScalar(UInt32(x)), sendingOutputTo: output)
342+
Encoding.encode(UnicodeScalar(UInt32(x)), into: processCodeUnit)
343343
}
344344
}
345345
else {
@@ -351,7 +351,7 @@ public struct _StringCore {
351351
from: UTF16.self,
352352
to: encoding,
353353
stoppingOnError: true,
354-
sendingOutputTo: output
354+
into: processCodeUnit
355355
)
356356
_sanityCheck(!hadError, "Swift.String with native storage should not have unpaired surrogates")
357357
}
@@ -361,7 +361,7 @@ public struct _StringCore {
361361
_StringCore(
362362
_cocoaStringToContiguous(
363363
source: cocoaBuffer!, range: 0..<count, minimumCapacity: 0)
364-
).encode(encoding, output: output)
364+
).encode(encoding, into: processCodeUnit)
365365
#else
366366
_sanityCheckFailure("encode: non-native string without objc runtime")
367367
#endif

Diff for: stdlib/public/core/Unicode.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public protocol UnicodeCodec {
121121
/// fermata in UTF-8:
122122
///
123123
/// var bytes: [UTF8.CodeUnit] = []
124-
/// UTF8.encode("𝄐", sendingOutputTo: { bytes.append($0) })
124+
/// UTF8.encode("𝄐", into: { bytes.append($0) })
125125
/// print(bytes)
126126
/// // Prints "[240, 157, 132, 144]"
127127
///
@@ -131,7 +131,7 @@ public protocol UnicodeCodec {
131131
/// time.
132132
static func encode(
133133
_ input: UnicodeScalar,
134-
sendingOutputTo processCodeUnit: @noescape (CodeUnit) -> Void
134+
into processCodeUnit: @noescape (CodeUnit) -> Void
135135
)
136136

137137
/// Searches for the first occurrence of a `CodeUnit` that is equal to 0.
@@ -364,7 +364,7 @@ public struct UTF8 : UnicodeCodec {
364364
/// representation. The following code encodes a fermata in UTF-8:
365365
///
366366
/// var bytes: [UTF8.CodeUnit] = []
367-
/// UTF8.encode("𝄐", sendingOutputTo: { bytes.append($0) })
367+
/// UTF8.encode("𝄐", into: { bytes.append($0) })
368368
/// print(bytes)
369369
/// // Prints "[240, 157, 132, 144]"
370370
///
@@ -374,7 +374,7 @@ public struct UTF8 : UnicodeCodec {
374374
/// time.
375375
public static func encode(
376376
_ input: UnicodeScalar,
377-
sendingOutputTo processCodeUnit: @noescape (CodeUnit) -> Void
377+
into processCodeUnit: @noescape (CodeUnit) -> Void
378378
) {
379379
var c = UInt32(input)
380380
var buf3 = UInt8(c & 0xFF)
@@ -555,7 +555,7 @@ public struct UTF16 : UnicodeCodec {
555555
/// representation. The following code encodes a fermata in UTF-16:
556556
///
557557
/// var codeUnits: [UTF16.CodeUnit] = []
558-
/// UTF16.encode("𝄐", sendingOutputTo: { codeUnits.append($0) })
558+
/// UTF16.encode("𝄐", into: { codeUnits.append($0) })
559559
/// print(codeUnits)
560560
/// // Prints "[55348, 56592]"
561561
///
@@ -565,7 +565,7 @@ public struct UTF16 : UnicodeCodec {
565565
/// time.
566566
public static func encode(
567567
_ input: UnicodeScalar,
568-
sendingOutputTo processCodeUnit: @noescape (CodeUnit) -> Void
568+
into processCodeUnit: @noescape (CodeUnit) -> Void
569569
) {
570570
let scalarValue: UInt32 = UInt32(input)
571571

@@ -655,7 +655,7 @@ public struct UTF32 : UnicodeCodec {
655655
/// encodes a fermata in UTF-32:
656656
///
657657
/// var codeUnit: UTF32.CodeUnit = 0
658-
/// UTF32.encode("𝄐", sendingOutputTo: { codeUnit = $0 })
658+
/// UTF32.encode("𝄐", into: { codeUnit = $0 })
659659
/// print(codeUnit)
660660
/// // Prints "119056"
661661
///
@@ -665,7 +665,7 @@ public struct UTF32 : UnicodeCodec {
665665
/// time.
666666
public static func encode(
667667
_ input: UnicodeScalar,
668-
sendingOutputTo processCodeUnit: @noescape (CodeUnit) -> Void
668+
into processCodeUnit: @noescape (CodeUnit) -> Void
669669
) {
670670
processCodeUnit(UInt32(input))
671671
}
@@ -685,7 +685,7 @@ public struct UTF32 : UnicodeCodec {
685685
/// var codeUnits: [UTF32.CodeUnit] = []
686686
/// let sink = { codeUnits.append($0) }
687687
/// transcode(bytes.makeIterator(), from: UTF8.self, to: UTF32.self,
688-
/// stoppingOnError: false, sendingOutputTo: sink)
688+
/// stoppingOnError: false, into: sink)
689689
/// print(codeUnits)
690690
/// // Prints "[70, 101, 114, 109, 97, 116, 97, 32, 119056]"
691691
///
@@ -711,7 +711,7 @@ public func transcode<Input, InputEncoding, OutputEncoding>(
711711
from inputEncoding: InputEncoding.Type,
712712
to outputEncoding: OutputEncoding.Type,
713713
stoppingOnError stopOnError: Bool,
714-
sendingOutputTo processCodeUnit: @noescape (OutputEncoding.CodeUnit) -> Void
714+
into processCodeUnit: @noescape (OutputEncoding.CodeUnit) -> Void
715715
) -> Bool
716716
where
717717
Input : IteratorProtocol,
@@ -730,15 +730,15 @@ public func transcode<Input, InputEncoding, OutputEncoding>(
730730
while true {
731731
switch inputDecoder.decode(&input) {
732732
case .scalarValue(let us):
733-
OutputEncoding.encode(us, sendingOutputTo: processCodeUnit)
733+
OutputEncoding.encode(us, into: processCodeUnit)
734734
case .emptyInput:
735735
break loop
736736
case .error:
737737
hadError = true
738738
if stopOnError {
739739
break loop
740740
}
741-
OutputEncoding.encode("\u{fffd}", sendingOutputTo: processCodeUnit)
741+
OutputEncoding.encode("\u{fffd}", into: processCodeUnit)
742742
}
743743
}
744744
return hadError
@@ -1133,7 +1133,7 @@ extension UnicodeCodec {
11331133
@available(*, unavailable, renamed: "UnicodeCodec")
11341134
public typealias UnicodeCodecType = UnicodeCodec
11351135

1136-
@available(*, unavailable, message: "use 'transcode(_:from:to:stoppingOnError:sendingOutputTo:)'")
1136+
@available(*, unavailable, message: "use 'transcode(_:from:to:stoppingOnError:into:)'")
11371137
public func transcode<Input, InputEncoding, OutputEncoding>(
11381138
_ inputEncoding: InputEncoding.Type, _ outputEncoding: OutputEncoding.Type,
11391139
_ input: Input, _ output: (OutputEncoding.CodeUnit) -> Void,

Diff for: test/1_stdlib/Renames.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func _Unicode() {
469469
func fn<T : UnicodeCodecType>(_: T) {} // expected-error {{'UnicodeCodecType' has been renamed to 'UnicodeCodec'}} {{15-31=UnicodeCodec}} {{none}}
470470
}
471471
func _Unicode<I : IteratorProtocol, E : UnicodeCodec>(i: I, e: E.Type) where I.Element == E.CodeUnit {
472-
_ = transcode(e, e, i, { _ in }, stopOnError: true) // expected-error {{'transcode(_:_:_:_:stopOnError:)' is unavailable: use 'transcode(_:from:to:stoppingOnError:sendingOutputTo:)'}} {{none}}
472+
_ = transcode(e, e, i, { _ in }, stopOnError: true) // expected-error {{'transcode(_:_:_:_:stopOnError:)' is unavailable: use 'transcode(_:from:to:stoppingOnError:into:)'}} {{none}}
473473
_ = UTF16.measure(e, input: i, repairIllFormedSequences: true) // expected-error {{'measure(_:input:repairIllFormedSequences:)' is unavailable: use 'transcodedLength(of:decodedAs:repairingIllFormedSequences:)'}} {{none}}
474474
}
475475

Diff for: validation-test/stdlib/Unicode.swift.gyb

+12-12
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func checkDecodeUTF<Codec : UnicodeCodec>(
101101
from: codec,
102102
to: UTF32.self,
103103
stoppingOnError: true,
104-
sendingOutputTo: output)
104+
into: output)
105105
if expectedHead != decoded {
106106
return assertionFailure()
107107
.withDescription("\n")
@@ -122,7 +122,7 @@ func checkDecodeUTF<Codec : UnicodeCodec>(
122122
from: codec,
123123
to: UTF32.self,
124124
stoppingOnError: false,
125-
sendingOutputTo: output)
125+
into: output)
126126
if expected != decoded {
127127
return assertionFailure()
128128
.withDescription("\n")
@@ -167,7 +167,7 @@ func checkEncodeUTF8(_ expected: [UInt8],
167167
from: UTF32.self,
168168
to: UTF8.self,
169169
stoppingOnError: true,
170-
sendingOutputTo: output)
170+
into: output)
171171
expectFalse(hadError)
172172
if expected != encoded {
173173
return assertionFailure()
@@ -2061,7 +2061,7 @@ UnicodeAPIs.test("transcode/MutableArray") {
20612061
from: UTF16.self,
20622062
to: UTF16.self,
20632063
stoppingOnError: true,
2064-
sendingOutputTo: output)
2064+
into: output)
20652065
expectEqual(input, transcoded)
20662066
}
20672067

@@ -2074,7 +2074,7 @@ UnicodeAPIs.test("transcode/ReferenceTypedArray") {
20742074
from: UTF16.self,
20752075
to: UTF16.self,
20762076
stoppingOnError: true,
2077-
sendingOutputTo: output)
2077+
into: output)
20782078
expectEqual(input, transcoded)
20792079
}
20802080

@@ -2102,7 +2102,7 @@ class NonContiguousNSString : NSString {
21022102
from: UTF8.self,
21032103
to: UTF16.self,
21042104
stoppingOnError: true,
2105-
sendingOutputTo: output)
2105+
into: output)
21062106
expectFalse(hadError)
21072107
self.init(encoded)
21082108
}
@@ -2121,7 +2121,7 @@ class NonContiguousNSString : NSString {
21212121
from: UTF32.self,
21222122
to: UTF16.self,
21232123
stoppingOnError: true,
2124-
sendingOutputTo: output)
2124+
into: output)
21252125
expectFalse(hadError)
21262126
self.init(encoded)
21272127
}
@@ -2182,7 +2182,7 @@ StringCookedViews.test("UTF8ForContiguousUTF16") {
21822182
from: UTF32.self,
21832183
to: UTF16.self,
21842184
stoppingOnError: false,
2185-
sendingOutputTo: output)
2185+
into: output)
21862186

21872187
backingStorage.withUnsafeBufferPointer {
21882188
(ptr) -> Void in
@@ -2208,7 +2208,7 @@ StringCookedViews.test("UTF8ForContiguousUTF16") {
22082208
from: UTF32.self,
22092209
to: UTF8.self,
22102210
stoppingOnError: false,
2211-
sendingOutputTo: output)
2211+
into: output)
22122212

22132213
checkUTF8View(expected, subject, test.loc.withCurrentLoc())
22142214
}
@@ -2259,7 +2259,7 @@ StringCookedViews.test("UTF8ForNonContiguousUTF16") {
22592259
from: UTF32.self,
22602260
to: UTF8.self,
22612261
stoppingOnError: false,
2262-
sendingOutputTo: output)
2262+
into: output)
22632263

22642264
var nss = NonContiguousNSString(test.encoded)
22652265
verifyThatStringIsOpaqueForCoreFoundation(nss)
@@ -2332,7 +2332,7 @@ StringCookedViews.test("UTF16") {
23322332
from: UTF32.self,
23332333
to: UTF16.self,
23342334
stoppingOnError: false,
2335-
sendingOutputTo: output)
2335+
into: output)
23362336

23372337
var nss = NonContiguousNSString(test.scalars)
23382338
checkUTF16View(expected, nss as String, test.loc.withCurrentLoc())
@@ -2349,7 +2349,7 @@ StringCookedViews.test("UTF16") {
23492349
from: UTF32.self,
23502350
to: UTF16.self,
23512351
stoppingOnError: false,
2352-
sendingOutputTo: output)
2352+
into: output)
23532353

23542354
checkUTF16View(expected, subject, test.loc.withCurrentLoc())
23552355
}

Diff for: validation-test/stdlib/UnicodeTrie.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class NonContiguousNSString : NSString {
101101
from: UTF32.self,
102102
to: UTF16.self,
103103
stoppingOnError: true,
104-
sendingOutputTo: output)
104+
into: output)
105105
expectFalse(hadError)
106106
self.init(encoded)
107107
}

Diff for: validation-test/stdlib/UnicodeUTFEncoders.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ final class CodecTest<Codec : TestableUnicodeCodec> {
129129
) { $0 == $1 }
130130

131131
encodeIndex = encodeBuffer.startIndex
132-
Codec.encode(scalar, sendingOutputTo: encodeOutput)
132+
Codec.encode(scalar, into: encodeOutput)
133133
expectEqual(
134134
nsEncoded, encodeBuffer[0..<encodeIndex],
135135
"Decoding failed: \(asHex(nsEncoded)) => " +

0 commit comments

Comments
 (0)