Skip to content

Commit a7421ca

Browse files
author
Dave Abrahams
committed
encode(_:output:) => encode(_:into processCodeUnit:)
1 parent 74e3050 commit a7421ca

File tree

9 files changed

+44
-43
lines changed

9 files changed

+44
-43
lines changed

stdlib/public/core/Character.swift

Lines changed: 2 additions & 2 deletions
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

stdlib/public/core/StaticString.swift

Lines changed: 1 addition & 1 deletion
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))

stdlib/public/core/String.swift

Lines changed: 6 additions & 5 deletions
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

stdlib/public/core/StringBuffer.swift

Lines changed: 2 additions & 2 deletions
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
}

stdlib/public/core/StringCore.swift

Lines changed: 6 additions & 6 deletions
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

stdlib/public/core/Unicode.swift

Lines changed: 13 additions & 13 deletions
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.
@@ -374,7 +374,7 @@ public struct UTF8 : UnicodeCodec {
374374
/// representation. The following code encodes a fermata in UTF-8:
375375
///
376376
/// var bytes: [UTF8.CodeUnit] = []
377-
/// UTF8.encode("𝄐", sendingOutputTo: { bytes.append($0) })
377+
/// UTF8.encode("𝄐", into: { bytes.append($0) })
378378
/// print(bytes)
379379
/// // Prints "[240, 157, 132, 144]"
380380
///
@@ -384,7 +384,7 @@ public struct UTF8 : UnicodeCodec {
384384
/// time.
385385
public static func encode(
386386
_ input: UnicodeScalar,
387-
sendingOutputTo processCodeUnit: @noescape (CodeUnit) -> Void
387+
into processCodeUnit: @noescape (CodeUnit) -> Void
388388
) {
389389
var c = UInt32(input)
390390
var buf3 = UInt8(c & 0xFF)
@@ -604,7 +604,7 @@ public struct UTF16 : UnicodeCodec {
604604
/// representation. The following code encodes a fermata in UTF-16:
605605
///
606606
/// var codeUnits: [UTF16.CodeUnit] = []
607-
/// UTF16.encode("𝄐", sendingOutputTo: { codeUnits.append($0) })
607+
/// UTF16.encode("𝄐", into: { codeUnits.append($0) })
608608
/// print(codeUnits)
609609
/// // Prints "[55348, 56592]"
610610
///
@@ -614,7 +614,7 @@ public struct UTF16 : UnicodeCodec {
614614
/// time.
615615
public static func encode(
616616
_ input: UnicodeScalar,
617-
sendingOutputTo processCodeUnit: @noescape (CodeUnit) -> Void
617+
into processCodeUnit: @noescape (CodeUnit) -> Void
618618
) {
619619
let scalarValue: UInt32 = UInt32(input)
620620

@@ -704,7 +704,7 @@ public struct UTF32 : UnicodeCodec {
704704
/// encodes a fermata in UTF-32:
705705
///
706706
/// var codeUnit: UTF32.CodeUnit = 0
707-
/// UTF32.encode("𝄐", sendingOutputTo: { codeUnit = $0 })
707+
/// UTF32.encode("𝄐", into: { codeUnit = $0 })
708708
/// print(codeUnit)
709709
/// // Prints "119056"
710710
///
@@ -714,7 +714,7 @@ public struct UTF32 : UnicodeCodec {
714714
/// time.
715715
public static func encode(
716716
_ input: UnicodeScalar,
717-
sendingOutputTo processCodeUnit: @noescape (CodeUnit) -> Void
717+
into processCodeUnit: @noescape (CodeUnit) -> Void
718718
) {
719719
processCodeUnit(UInt32(input))
720720
}
@@ -734,7 +734,7 @@ public struct UTF32 : UnicodeCodec {
734734
/// var codeUnits: [UTF32.CodeUnit] = []
735735
/// let sink = { codeUnits.append($0) }
736736
/// transcode(bytes.makeIterator(), from: UTF8.self, to: UTF32.self,
737-
/// stoppingOnError: false, sendingOutputTo: sink)
737+
/// stoppingOnError: false, into: sink)
738738
/// print(codeUnits)
739739
/// // Prints "[70, 101, 114, 109, 97, 116, 97, 32, 119056]"
740740
///
@@ -760,7 +760,7 @@ public func transcode<Input, InputEncoding, OutputEncoding>(
760760
from inputEncoding: InputEncoding.Type,
761761
to outputEncoding: OutputEncoding.Type,
762762
stoppingOnError stopOnError: Bool,
763-
sendingOutputTo processCodeUnit: @noescape (OutputEncoding.CodeUnit) -> Void
763+
into processCodeUnit: @noescape (OutputEncoding.CodeUnit) -> Void
764764
) -> Bool
765765
where
766766
Input : IteratorProtocol,
@@ -779,15 +779,15 @@ public func transcode<Input, InputEncoding, OutputEncoding>(
779779
while true {
780780
switch inputDecoder.decode(&input) {
781781
case .scalarValue(let us):
782-
OutputEncoding.encode(us, sendingOutputTo: processCodeUnit)
782+
OutputEncoding.encode(us, into: processCodeUnit)
783783
case .emptyInput:
784784
break loop
785785
case .error:
786786
hadError = true
787787
if stopOnError {
788788
break loop
789789
}
790-
OutputEncoding.encode("\u{fffd}", sendingOutputTo: processCodeUnit)
790+
OutputEncoding.encode("\u{fffd}", into: processCodeUnit)
791791
}
792792
}
793793
return hadError
@@ -1182,7 +1182,7 @@ extension UnicodeCodec {
11821182
@available(*, unavailable, renamed: "UnicodeCodec")
11831183
public typealias UnicodeCodecType = UnicodeCodec
11841184

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

validation-test/stdlib/Unicode.swift.gyb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func checkDecodeUTF<Codec : UnicodeCodec>(
120120
from: codec,
121121
to: UTF32.self,
122122
stoppingOnError: true,
123-
sendingOutputTo: output)
123+
into: output)
124124
expectGE(1, iterator.numTimesReturnedEOF)
125125
if expectedHead != decoded {
126126
return assertionFailure()
@@ -142,7 +142,7 @@ func checkDecodeUTF<Codec : UnicodeCodec>(
142142
from: codec,
143143
to: UTF32.self,
144144
stoppingOnError: false,
145-
sendingOutputTo: output)
145+
into: output)
146146
expectEqual(1, iterator.numTimesReturnedEOF)
147147
if expected != decoded {
148148
return assertionFailure()
@@ -188,7 +188,7 @@ func checkEncodeUTF8(_ expected: [UInt8],
188188
from: UTF32.self,
189189
to: UTF8.self,
190190
stoppingOnError: true,
191-
sendingOutputTo: output)
191+
into: output)
192192
expectFalse(hadError)
193193
expectGE(1, iterator.numTimesReturnedEOF)
194194
if expected != encoded {
@@ -2083,7 +2083,7 @@ UnicodeAPIs.test("transcode/MutableArray") {
20832083
from: UTF16.self,
20842084
to: UTF16.self,
20852085
stoppingOnError: true,
2086-
sendingOutputTo: output)
2086+
into: output)
20872087
expectEqual(input, transcoded)
20882088
}
20892089

@@ -2096,7 +2096,7 @@ UnicodeAPIs.test("transcode/ReferenceTypedArray") {
20962096
from: UTF16.self,
20972097
to: UTF16.self,
20982098
stoppingOnError: true,
2099-
sendingOutputTo: output)
2099+
into: output)
21002100
expectEqual(input, transcoded)
21012101
}
21022102

@@ -2124,7 +2124,7 @@ class NonContiguousNSString : NSString {
21242124
from: UTF8.self,
21252125
to: UTF16.self,
21262126
stoppingOnError: true,
2127-
sendingOutputTo: output)
2127+
into: output)
21282128
expectFalse(hadError)
21292129
self.init(encoded)
21302130
}
@@ -2143,7 +2143,7 @@ class NonContiguousNSString : NSString {
21432143
from: UTF32.self,
21442144
to: UTF16.self,
21452145
stoppingOnError: true,
2146-
sendingOutputTo: output)
2146+
into: output)
21472147
expectFalse(hadError)
21482148
self.init(encoded)
21492149
}
@@ -2204,7 +2204,7 @@ StringCookedViews.test("UTF8ForContiguousUTF16") {
22042204
from: UTF32.self,
22052205
to: UTF16.self,
22062206
stoppingOnError: false,
2207-
sendingOutputTo: output)
2207+
into: output)
22082208

22092209
backingStorage.withUnsafeBufferPointer {
22102210
(ptr) -> Void in
@@ -2230,7 +2230,7 @@ StringCookedViews.test("UTF8ForContiguousUTF16") {
22302230
from: UTF32.self,
22312231
to: UTF8.self,
22322232
stoppingOnError: false,
2233-
sendingOutputTo: output)
2233+
into: output)
22342234

22352235
checkUTF8View(expected, subject, test.loc.withCurrentLoc())
22362236
}
@@ -2281,7 +2281,7 @@ StringCookedViews.test("UTF8ForNonContiguousUTF16") {
22812281
from: UTF32.self,
22822282
to: UTF8.self,
22832283
stoppingOnError: false,
2284-
sendingOutputTo: output)
2284+
into: output)
22852285

22862286
var nss = NonContiguousNSString(test.encoded)
22872287
verifyThatStringIsOpaqueForCoreFoundation(nss)
@@ -2354,7 +2354,7 @@ StringCookedViews.test("UTF16") {
23542354
from: UTF32.self,
23552355
to: UTF16.self,
23562356
stoppingOnError: false,
2357-
sendingOutputTo: output)
2357+
into: output)
23582358

23592359
var nss = NonContiguousNSString(test.scalars)
23602360
checkUTF16View(expected, nss as String, test.loc.withCurrentLoc())
@@ -2371,7 +2371,7 @@ StringCookedViews.test("UTF16") {
23712371
from: UTF32.self,
23722372
to: UTF16.self,
23732373
stoppingOnError: false,
2374-
sendingOutputTo: output)
2374+
into: output)
23752375

23762376
checkUTF16View(expected, subject, test.loc.withCurrentLoc())
23772377
}

validation-test/stdlib/UnicodeTrie.swift.gyb

Lines changed: 1 addition & 1 deletion
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
}

validation-test/stdlib/UnicodeUTFEncoders.swift

Lines changed: 1 addition & 1 deletion
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)