mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/swift-3-api-guidelines' into swift-3-api-guidelines
This commit is contained in:
@@ -22,7 +22,7 @@ public func run_PopFrontArray(N: Int) {
|
|||||||
for _ in 1...20*N {
|
for _ in 1...20*N {
|
||||||
for _ in 1...reps {
|
for _ in 1...reps {
|
||||||
var result = 0
|
var result = 0
|
||||||
a.appendContents(of: orig)
|
a.append(contentsOf: orig)
|
||||||
while a.count != 0 {
|
while a.count != 0 {
|
||||||
result += a[0]
|
result += a[0]
|
||||||
a.remove(at: 0)
|
a.remove(at: 0)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public func run_PopFrontArrayGeneric(N: Int) {
|
|||||||
for _ in 1...20*N {
|
for _ in 1...20*N {
|
||||||
for _ in 1...reps {
|
for _ in 1...reps {
|
||||||
var result = 0
|
var result = 0
|
||||||
a.appendContents(of: orig)
|
a.append(contentsOf: orig)
|
||||||
while a.count != 0 {
|
while a.count != 0 {
|
||||||
result += a[0]
|
result += a[0]
|
||||||
_arrayReplace(&a._buffer, 0..<1, EmptyCollection())
|
_arrayReplace(&a._buffer, 0..<1, EmptyCollection())
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ internal struct InsertContentsOfTest {
|
|||||||
self.newElements = newElements.map(OpaqueValue.init)
|
self.newElements = newElements.map(OpaqueValue.init)
|
||||||
self.indexSelection = indexSelection
|
self.indexSelection = indexSelection
|
||||||
self.expected = expected
|
self.expected = expected
|
||||||
self.loc = SourceLoc(file, line, comment: "insertContents(of:at:) test data")
|
self.loc = SourceLoc(file, line, comment: "insert(contentsOf:at:) test data")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,15 +501,15 @@ self.test("\(testNamePrefix).append()/semantics") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// appendContents(of:)
|
// append(contentsOf:)
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
self.test("\(testNamePrefix).appendContents(of:)/semantics") {
|
self.test("\(testNamePrefix).append(contentsOf:)/semantics") {
|
||||||
for test in appendContentsOfTests {
|
for test in appendContentsOfTests {
|
||||||
var c = makeWrappedCollection(test.collection)
|
var c = makeWrappedCollection(test.collection)
|
||||||
let newElements =
|
let newElements =
|
||||||
MinimalForwardCollection(elements: test.newElements.map(wrapValue))
|
MinimalForwardCollection(elements: test.newElements.map(wrapValue))
|
||||||
c.appendContents(of: newElements)
|
c.append(contentsOf: newElements)
|
||||||
expectEqualSequence(
|
expectEqualSequence(
|
||||||
test.expected,
|
test.expected,
|
||||||
c.map { extractValue($0).value },
|
c.map { extractValue($0).value },
|
||||||
@@ -572,10 +572,10 @@ self.test("\(testNamePrefix).insert()/semantics") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// insertContents(of:at:)
|
// insert(contentsOf:at:)
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
self.test("\(testNamePrefix).insertContents(of:at:)/semantics") {
|
self.test("\(testNamePrefix).insert(contentsOf:at:)/semantics") {
|
||||||
let tests: [InsertContentsOfTest] = [
|
let tests: [InsertContentsOfTest] = [
|
||||||
InsertContentsOfTest(
|
InsertContentsOfTest(
|
||||||
collection: [],
|
collection: [],
|
||||||
@@ -648,7 +648,7 @@ self.test("\(testNamePrefix).insertContents(of:at:)/semantics") {
|
|||||||
var c = makeWrappedCollection(test.collection)
|
var c = makeWrappedCollection(test.collection)
|
||||||
let newElements =
|
let newElements =
|
||||||
MinimalForwardCollection(elements: test.newElements.map(wrapValue))
|
MinimalForwardCollection(elements: test.newElements.map(wrapValue))
|
||||||
c.insertContents(of: newElements, at: test.indexSelection.indexIn(c))
|
c.insert(contentsOf: newElements, at: test.indexSelection.indexIn(c))
|
||||||
expectEqualSequence(
|
expectEqualSequence(
|
||||||
test.expected,
|
test.expected,
|
||||||
c.map { extractValue($0).value },
|
c.map { extractValue($0).value },
|
||||||
|
|||||||
@@ -153,11 +153,11 @@ public struct LoggingRangeReplaceableCollection<
|
|||||||
base.append(newElement)
|
base.append(newElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func appendContents<
|
public mutating func append<
|
||||||
S : Sequence where S.Iterator.Element == Base.Iterator.Element
|
S : Sequence where S.Iterator.Element == Base.Iterator.Element
|
||||||
>(of newElements: S) {
|
>(contentsOf newElements: S) {
|
||||||
Log.appendContentsOf[selfType] += 1
|
Log.appendContentsOf[selfType] += 1
|
||||||
base.appendContents(of: newElements)
|
base.append(contentsOf: newElements)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func insert(
|
public mutating func insert(
|
||||||
@@ -207,11 +207,11 @@ public struct LoggingRangeReplaceableCollection<
|
|||||||
base.reserveCapacity(n)
|
base.reserveCapacity(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func insertContents<
|
public mutating func insert<
|
||||||
C : Collection where C.Iterator.Element == Base.Iterator.Element
|
C : Collection where C.Iterator.Element == Base.Iterator.Element
|
||||||
>(of newElements: C, at i: Base.Index) {
|
>(contentsOf newElements: C, at i: Base.Index) {
|
||||||
Log.insertContentsOf[selfType] += 1
|
Log.insertContentsOf[selfType] += 1
|
||||||
base.insertContents(of: newElements, at: i)
|
base.insert(contentsOf: newElements, at: i)
|
||||||
}
|
}
|
||||||
|
|
||||||
@warn_unused_result
|
@warn_unused_result
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ internal enum _CollectionOperation : Equatable {
|
|||||||
result.append(nextStateId)
|
result.append(nextStateId)
|
||||||
|
|
||||||
case appendContentsOf(let count):
|
case appendContentsOf(let count):
|
||||||
result.appendContents(of:
|
result.append(contentsOf:
|
||||||
repeatElement(nextStateId, count: count))
|
repeatElement(nextStateId, count: count))
|
||||||
|
|
||||||
case replaceRange(let subRange, let replacementCount):
|
case replaceRange(let subRange, let replacementCount):
|
||||||
@@ -229,8 +229,8 @@ internal enum _CollectionOperation : Equatable {
|
|||||||
with: repeatElement(nextStateId, count: invalidIndices.count))
|
with: repeatElement(nextStateId, count: invalidIndices.count))
|
||||||
|
|
||||||
case insertContentsOf(let atIndex, let count):
|
case insertContentsOf(let atIndex, let count):
|
||||||
result.insertContents(
|
result.insert(
|
||||||
of: repeatElement(nextStateId, count: count),
|
contentsOf: repeatElement(nextStateId, count: count),
|
||||||
at: atIndex)
|
at: atIndex)
|
||||||
|
|
||||||
let invalidIndices = atIndex..<result.endIndex
|
let invalidIndices = atIndex..<result.endIndex
|
||||||
@@ -1122,11 +1122,11 @@ public struct ${Self}<T> : RangeReplaceableCollection {
|
|||||||
elements.append(x)
|
elements.append(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func appendContents<
|
public mutating func append<
|
||||||
S : Sequence where S.Iterator.Element == T
|
S : Sequence where S.Iterator.Element == T
|
||||||
>(of newElements: S) {
|
>(contentsOf newElements: S) {
|
||||||
let oldCount = count
|
let oldCount = count
|
||||||
elements.appendContents(of: newElements)
|
elements.append(contentsOf: newElements)
|
||||||
let newCount = count
|
let newCount = count
|
||||||
_willMutate(.appendContentsOf(count: newCount - oldCount))
|
_willMutate(.appendContentsOf(count: newCount - oldCount))
|
||||||
}
|
}
|
||||||
@@ -1151,11 +1151,11 @@ public struct ${Self}<T> : RangeReplaceableCollection {
|
|||||||
elements.insert(newElement, at: i.position)
|
elements.insert(newElement, at: i.position)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func insertContents<
|
public mutating func insert<
|
||||||
S : Collection where S.Iterator.Element == T
|
S : Collection where S.Iterator.Element == T
|
||||||
>(of newElements: S, at i: ${Index}) {
|
>(contentsOf newElements: S, at i: ${Index}) {
|
||||||
let oldCount = count
|
let oldCount = count
|
||||||
elements.insertContents(of: newElements, at: i.position)
|
elements.insert(contentsOf: newElements, at: i.position)
|
||||||
let newCount = count
|
let newCount = count
|
||||||
|
|
||||||
if newCount - oldCount != 0 {
|
if newCount - oldCount != 0 {
|
||||||
|
|||||||
@@ -419,12 +419,12 @@ func _masterThreadOneTrial<RT : RaceTestWithPerTrialData>(
|
|||||||
let rt = RT()
|
let rt = RT()
|
||||||
|
|
||||||
sharedState.raceData.removeAll(keepingCapacity: true)
|
sharedState.raceData.removeAll(keepingCapacity: true)
|
||||||
sharedState.raceData.appendContents(of:
|
sharedState.raceData.append(contentsOf:
|
||||||
(0..<raceDataCount).lazy.map { i in rt.makeRaceData() })
|
(0..<raceDataCount).lazy.map { i in rt.makeRaceData() })
|
||||||
|
|
||||||
let identityShuffle = Array(0..<sharedState.raceData.count)
|
let identityShuffle = Array(0..<sharedState.raceData.count)
|
||||||
sharedState.workerStates.removeAll(keepingCapacity: true)
|
sharedState.workerStates.removeAll(keepingCapacity: true)
|
||||||
sharedState.workerStates.appendContents(of:
|
sharedState.workerStates.append(contentsOf:
|
||||||
(0..<racingThreadCount).lazy.map {
|
(0..<racingThreadCount).lazy.map {
|
||||||
i in
|
i in
|
||||||
let workerState = _RaceTestWorkerState<RT>()
|
let workerState = _RaceTestWorkerState<RT>()
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public func withArrayOfCStrings<R>(
|
|||||||
var argsBuffer: [UInt8] = []
|
var argsBuffer: [UInt8] = []
|
||||||
argsBuffer.reserveCapacity(argsBufferSize)
|
argsBuffer.reserveCapacity(argsBufferSize)
|
||||||
for arg in args {
|
for arg in args {
|
||||||
argsBuffer.appendContents(of: arg.utf8)
|
argsBuffer.append(contentsOf: arg.utf8)
|
||||||
argsBuffer.append(0)
|
argsBuffer.append(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,13 +166,13 @@ public var S_ISVTX: mode_t { return mode_t(0o001000) }
|
|||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
public var SIG_DFL: __sighandler_t? { return nil }
|
public var SIG_DFL: __sighandler_t? { return nil }
|
||||||
public var SIG_IGN: __sighandler_t {
|
public var SIG_IGN: __sighandler_t {
|
||||||
return unsafeBitCast(1, __sighandler_t.self)
|
return unsafeBitCast(1, to: __sighandler_t.self)
|
||||||
}
|
}
|
||||||
public var SIG_ERR: __sighandler_t {
|
public var SIG_ERR: __sighandler_t {
|
||||||
return unsafeBitCast(-1, __sighandler_t.self)
|
return unsafeBitCast(-1, to: __sighandler_t.self)
|
||||||
}
|
}
|
||||||
public var SIG_HOLD: __sighandler_t {
|
public var SIG_HOLD: __sighandler_t {
|
||||||
return unsafeBitCast(2, __sighandler_t.self)
|
return unsafeBitCast(2, to: __sighandler_t.self)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -702,7 +702,7 @@ extension ${Self} : _ArrayProtocol {
|
|||||||
self += newElements
|
self += newElements
|
||||||
}
|
}
|
||||||
|
|
||||||
// An overload of `appendContents(of:)` that uses the += that is optimized for
|
// An overload of `append(contentsOf:)` that uses the += that is optimized for
|
||||||
// collections.
|
// collections.
|
||||||
/// Append the elements of `newElements` to `self`.
|
/// Append the elements of `newElements` to `self`.
|
||||||
///
|
///
|
||||||
@@ -1412,7 +1412,7 @@ extension ${Self} {
|
|||||||
fatalError("unavailable function can't be called")
|
fatalError("unavailable function can't be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable, renamed="appendContents(of:)")
|
@available(*, unavailable, renamed="append(contentsOf:)")
|
||||||
public mutating func appendContentsOf<
|
public mutating func appendContentsOf<
|
||||||
S : Sequence
|
S : Sequence
|
||||||
where
|
where
|
||||||
@@ -1420,15 +1420,6 @@ extension ${Self} {
|
|||||||
>(newElements: S) {
|
>(newElements: S) {
|
||||||
fatalError("unavailable function can't be called")
|
fatalError("unavailable function can't be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable, renamed="appendContents(of:)")
|
|
||||||
public mutating func appendContentsOf<
|
|
||||||
C : Collection
|
|
||||||
where
|
|
||||||
C.Iterator.Element == Element
|
|
||||||
>(newElements: C) {
|
|
||||||
fatalError("unavailable function can't be called")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public struct Character :
|
|||||||
shift += 8
|
shift += 8
|
||||||
}
|
}
|
||||||
|
|
||||||
UTF8.encode(scalar, output: output)
|
UTF8.encode(scalar, sendingOutputTo: output)
|
||||||
asInt |= (~0) << shift
|
asInt |= (~0) << shift
|
||||||
_representation = .small(Builtin.trunc_Int64_Int63(asInt._value))
|
_representation = .small(Builtin.trunc_Int64_Int63(asInt._value))
|
||||||
}
|
}
|
||||||
@@ -199,9 +199,10 @@ public struct Character :
|
|||||||
|
|
||||||
struct _SmallUTF16 : Collection {
|
struct _SmallUTF16 : Collection {
|
||||||
init(_ u8: UInt64) {
|
init(_ u8: UInt64) {
|
||||||
let count = UTF16.measure(
|
let count = UTF16.transcodedLength(
|
||||||
UTF8.self, input: _SmallUTF8(u8).makeIterator(),
|
of: _SmallUTF8(u8).makeIterator(),
|
||||||
repairIllFormedSequences: true)!.0
|
decodedAs: UTF8.self,
|
||||||
|
repairingIllFormedSequences: true)!.0
|
||||||
_sanityCheck(count <= 4, "Character with more than 4 UTF-16 code units")
|
_sanityCheck(count <= 4, "Character with more than 4 UTF-16 code units")
|
||||||
self.count = UInt16(count)
|
self.count = UInt16(count)
|
||||||
var u16: UInt64 = 0
|
var u16: UInt64 = 0
|
||||||
@@ -210,8 +211,10 @@ public struct Character :
|
|||||||
u16 = u16 | UInt64($0)
|
u16 = u16 | UInt64($0)
|
||||||
}
|
}
|
||||||
transcode(
|
transcode(
|
||||||
UTF8.self, UTF16.self, _SmallUTF8(u8).makeIterator(), output,
|
_SmallUTF8(u8).makeIterator(),
|
||||||
stoppingOnError: false)
|
from: UTF8.self, to: UTF16.self,
|
||||||
|
stoppingOnError: false,
|
||||||
|
sendingOutputTo: output)
|
||||||
self.data = u16
|
self.data = u16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,17 +136,17 @@ public struct JoinedSequence<
|
|||||||
|
|
||||||
if separatorSize == 0 {
|
if separatorSize == 0 {
|
||||||
for x in _base {
|
for x in _base {
|
||||||
result.appendContents(of: x)
|
result.append(contentsOf: x)
|
||||||
}
|
}
|
||||||
return result._buffer
|
return result._buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
var iter = _base.makeIterator()
|
var iter = _base.makeIterator()
|
||||||
if let first = iter.next() {
|
if let first = iter.next() {
|
||||||
result.appendContents(of: first)
|
result.append(contentsOf: first)
|
||||||
while let next = iter.next() {
|
while let next = iter.next() {
|
||||||
result.appendContents(of: _separator)
|
result.append(contentsOf: _separator)
|
||||||
result.appendContents(of: next)
|
result.append(contentsOf: next)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,11 +106,11 @@ public protocol RangeReplaceableCollection : Collection {
|
|||||||
/// Append the elements of `newElements` to `self`.
|
/// Append the elements of `newElements` to `self`.
|
||||||
///
|
///
|
||||||
/// - Complexity: O(*length of result*).
|
/// - Complexity: O(*length of result*).
|
||||||
mutating func appendContents<
|
mutating func append<
|
||||||
S : Sequence
|
S : Sequence
|
||||||
where
|
where
|
||||||
S.Iterator.Element == Iterator.Element
|
S.Iterator.Element == Iterator.Element
|
||||||
>(of newElements: S)
|
>(contentsOf newElements: S)
|
||||||
|
|
||||||
/// Insert `newElement` at index `i`.
|
/// Insert `newElement` at index `i`.
|
||||||
///
|
///
|
||||||
@@ -124,9 +124,9 @@ public protocol RangeReplaceableCollection : Collection {
|
|||||||
/// Invalidates all indices with respect to `self`.
|
/// Invalidates all indices with respect to `self`.
|
||||||
///
|
///
|
||||||
/// - Complexity: O(`self.count + newElements.count`).
|
/// - Complexity: O(`self.count + newElements.count`).
|
||||||
mutating func insertContents<
|
mutating func insert<
|
||||||
S : Collection where S.Iterator.Element == Iterator.Element
|
S : Collection where S.Iterator.Element == Iterator.Element
|
||||||
>(of newElements: S, at i: Index)
|
>(contentsOf newElements: S, at i: Index)
|
||||||
|
|
||||||
/// Remove the element at index `i`.
|
/// Remove the element at index `i`.
|
||||||
///
|
///
|
||||||
@@ -191,7 +191,7 @@ extension RangeReplaceableCollection {
|
|||||||
self.init()
|
self.init()
|
||||||
if count != 0 {
|
if count != 0 {
|
||||||
let elements = Repeated(_repeating: repeatedValue, count: count)
|
let elements = Repeated(_repeating: repeatedValue, count: count)
|
||||||
appendContents(of: elements)
|
append(contentsOf: elements)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,16 +199,16 @@ extension RangeReplaceableCollection {
|
|||||||
S : Sequence where S.Iterator.Element == Iterator.Element
|
S : Sequence where S.Iterator.Element == Iterator.Element
|
||||||
>(_ elements: S) {
|
>(_ elements: S) {
|
||||||
self.init()
|
self.init()
|
||||||
appendContents(of: elements)
|
append(contentsOf: elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func append(newElement: Iterator.Element) {
|
public mutating func append(newElement: Iterator.Element) {
|
||||||
insert(newElement, at: endIndex)
|
insert(newElement, at: endIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func appendContents<
|
public mutating func append<
|
||||||
S : Sequence where S.Iterator.Element == Iterator.Element
|
S : Sequence where S.Iterator.Element == Iterator.Element
|
||||||
>(of newElements: S) {
|
>(contentsOf newElements: S) {
|
||||||
let approximateCapacity = self.count +
|
let approximateCapacity = self.count +
|
||||||
numericCast(newElements.underestimatedCount)
|
numericCast(newElements.underestimatedCount)
|
||||||
self.reserveCapacity(approximateCapacity)
|
self.reserveCapacity(approximateCapacity)
|
||||||
@@ -223,9 +223,9 @@ extension RangeReplaceableCollection {
|
|||||||
replaceSubrange(i..<i, with: CollectionOfOne(newElement))
|
replaceSubrange(i..<i, with: CollectionOfOne(newElement))
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func insertContents<
|
public mutating func insert<
|
||||||
C : Collection where C.Iterator.Element == Iterator.Element
|
C : Collection where C.Iterator.Element == Iterator.Element
|
||||||
>(of newElements: C, at i: Index) {
|
>(contentsOf newElements: C, at i: Index) {
|
||||||
replaceSubrange(i..<i, with: newElements)
|
replaceSubrange(i..<i, with: newElements)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +364,7 @@ public func +<
|
|||||||
var lhs = lhs
|
var lhs = lhs
|
||||||
// FIXME: what if lhs is a reference type? This will mutate it.
|
// FIXME: what if lhs is a reference type? This will mutate it.
|
||||||
lhs.reserveCapacity(lhs.count + numericCast(rhs.underestimatedCount))
|
lhs.reserveCapacity(lhs.count + numericCast(rhs.underestimatedCount))
|
||||||
lhs.appendContents(of: rhs)
|
lhs.append(contentsOf: rhs)
|
||||||
return lhs
|
return lhs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,8 +376,8 @@ public func +<
|
|||||||
>(lhs: S, rhs: C) -> C {
|
>(lhs: S, rhs: C) -> C {
|
||||||
var result = C()
|
var result = C()
|
||||||
result.reserveCapacity(rhs.count + numericCast(lhs.underestimatedCount))
|
result.reserveCapacity(rhs.count + numericCast(lhs.underestimatedCount))
|
||||||
result.appendContents(of: lhs)
|
result.append(contentsOf: lhs)
|
||||||
result.appendContents(of: rhs)
|
result.append(contentsOf: rhs)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,7 +390,7 @@ public func +<
|
|||||||
var lhs = lhs
|
var lhs = lhs
|
||||||
// FIXME: what if lhs is a reference type? This will mutate it.
|
// FIXME: what if lhs is a reference type? This will mutate it.
|
||||||
lhs.reserveCapacity(lhs.count + numericCast(rhs.count))
|
lhs.reserveCapacity(lhs.count + numericCast(rhs.count))
|
||||||
lhs.appendContents(of: rhs)
|
lhs.append(contentsOf: rhs)
|
||||||
return lhs
|
return lhs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,7 +416,7 @@ extension RangeReplaceableCollection {
|
|||||||
public mutating func removeRange(subRange: Range<Index>) {
|
public mutating func removeRange(subRange: Range<Index>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable, renamed="appendContents(of:)")
|
@available(*, unavailable, renamed="append(contentsOf:)")
|
||||||
public mutating func appendContentsOf<
|
public mutating func appendContentsOf<
|
||||||
S : Sequence
|
S : Sequence
|
||||||
where
|
where
|
||||||
@@ -425,7 +425,7 @@ extension RangeReplaceableCollection {
|
|||||||
fatalError("unavailable function can't be called")
|
fatalError("unavailable function can't be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable, renamed="insertContents(of:at:)")
|
@available(*, unavailable, renamed="insert(contentsOf:at:)")
|
||||||
public mutating func insertContentsOf<
|
public mutating func insertContentsOf<
|
||||||
C : Collection where C.Iterator.Element == Iterator.Element
|
C : Collection where C.Iterator.Element == Iterator.Element
|
||||||
>(newElements: C, at i: Index) {
|
>(newElements: C, at i: Index) {
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ extension Sequence {
|
|||||||
) rethrows -> [S.${GElement}] {
|
) rethrows -> [S.${GElement}] {
|
||||||
var result: [S.${GElement}] = []
|
var result: [S.${GElement}] = []
|
||||||
for element in self {
|
for element in self {
|
||||||
result.appendContents(of: try transform(element))
|
result.append(contentsOf: try transform(element))
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ public struct StaticString
|
|||||||
buffer = buffer | (UInt64($0) << (UInt64(i) * 8))
|
buffer = buffer | (UInt64($0) << (UInt64(i) * 8))
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
UTF8.encode(unicodeScalar, output: sink)
|
UTF8.encode(unicodeScalar, sendingOutputTo: sink)
|
||||||
return body(UnsafeBufferPointer(
|
return body(UnsafeBufferPointer(
|
||||||
start: UnsafePointer(Builtin.addressof(&buffer)),
|
start: UnsafePointer(Builtin.addressof(&buffer)),
|
||||||
count: i))
|
count: i))
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ extension String : CustomDebugStringConvertible {
|
|||||||
public var debugDescription: String {
|
public var debugDescription: String {
|
||||||
var result = "\""
|
var result = "\""
|
||||||
for us in self.unicodeScalars {
|
for us in self.unicodeScalars {
|
||||||
result += us.escape(asASCII: false)
|
result += us.escaped(asASCII: false)
|
||||||
}
|
}
|
||||||
result += "\""
|
result += "\""
|
||||||
return result
|
return result
|
||||||
@@ -589,11 +589,11 @@ extension String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func appendContents<
|
public mutating func append<
|
||||||
S : Sequence where S.Iterator.Element == Character
|
S : Sequence where S.Iterator.Element == Character
|
||||||
>(of newElements: S) {
|
>(contentsOf newElements: S) {
|
||||||
withMutableCharacters {
|
withMutableCharacters {
|
||||||
(v: inout CharacterView) in v.appendContents(of: newElements)
|
(v: inout CharacterView) in v.append(contentsOf: newElements)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,11 +700,11 @@ extension String {
|
|||||||
/// Invalidates all indices with respect to `self`.
|
/// Invalidates all indices with respect to `self`.
|
||||||
///
|
///
|
||||||
/// - Complexity: O(`self.count + newElements.count`).
|
/// - Complexity: O(`self.count + newElements.count`).
|
||||||
public mutating func insertContents<
|
public mutating func insert<
|
||||||
S : Collection where S.Iterator.Element == Character
|
S : Collection where S.Iterator.Element == Character
|
||||||
>(of newElements: S, at i: Index) {
|
>(contentsOf newElements: S, at i: Index) {
|
||||||
withMutableCharacters {
|
withMutableCharacters {
|
||||||
(v: inout CharacterView) in v.insertContents(of: newElements, at: i)
|
(v: inout CharacterView) in v.insert(contentsOf: newElements, at: i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -988,18 +988,18 @@ extension String.Index {
|
|||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
@available(*, unavailable, renamed="append")
|
@available(*, unavailable, renamed="append")
|
||||||
public mutating func appendContents(of other: String) {
|
public mutating func appendContentsOf(other: String) {
|
||||||
fatalError("unavailable function can't be called")
|
fatalError("unavailable function can't be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable, renamed="appendContents(of:)")
|
@available(*, unavailable, renamed="append(contentsOf:)")
|
||||||
public mutating func appendContentsOf<
|
public mutating func appendContentsOf<
|
||||||
S : Sequence where S.Iterator.Element == Character
|
S : Sequence where S.Iterator.Element == Character
|
||||||
>(newElements: S) {
|
>(newElements: S) {
|
||||||
fatalError("unavailable function can't be called")
|
fatalError("unavailable function can't be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable, renamed="insertContents(of:at:)")
|
@available(*, unavailable, renamed="insert(contentsOf:at:)")
|
||||||
public mutating func insertContentsOf<
|
public mutating func insertContentsOf<
|
||||||
S : Collection where S.Iterator.Element == Character
|
S : Collection where S.Iterator.Element == Character
|
||||||
>(newElements: S, at i: Index) {
|
>(newElements: S, at i: Index) {
|
||||||
|
|||||||
@@ -93,8 +93,10 @@ public struct _StringBuffer {
|
|||||||
) -> (_StringBuffer?, hadError: Bool) {
|
) -> (_StringBuffer?, hadError: Bool) {
|
||||||
// Determine how many UTF-16 code units we'll need
|
// Determine how many UTF-16 code units we'll need
|
||||||
let inputStream = input.makeIterator()
|
let inputStream = input.makeIterator()
|
||||||
guard let (utf16Count, isAscii) = UTF16.measure(encoding, input: inputStream,
|
guard let (utf16Count, isAscii) = UTF16.transcodedLength(
|
||||||
repairIllFormedSequences: repairIllFormedSequences) else {
|
of: inputStream,
|
||||||
|
decodedAs: encoding,
|
||||||
|
repairingIllFormedSequences: repairIllFormedSequences) else {
|
||||||
return (nil, true)
|
return (nil, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,8 +113,10 @@ public struct _StringBuffer {
|
|||||||
p += 1
|
p += 1
|
||||||
}
|
}
|
||||||
let hadError = transcode(
|
let hadError = transcode(
|
||||||
encoding, UTF32.self, input.makeIterator(), sink,
|
input.makeIterator(),
|
||||||
stoppingOnError: true)
|
from: encoding, to: UTF32.self,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: sink)
|
||||||
_sanityCheck(!hadError, "string cannot be ASCII if there were decoding errors")
|
_sanityCheck(!hadError, "string cannot be ASCII if there were decoding errors")
|
||||||
return (result, hadError)
|
return (result, hadError)
|
||||||
}
|
}
|
||||||
@@ -123,8 +127,10 @@ public struct _StringBuffer {
|
|||||||
p += 1
|
p += 1
|
||||||
}
|
}
|
||||||
let hadError = transcode(
|
let hadError = transcode(
|
||||||
encoding, UTF16.self, input.makeIterator(), sink,
|
input.makeIterator(),
|
||||||
stoppingOnError: !repairIllFormedSequences)
|
from: encoding, to: UTF16.self,
|
||||||
|
stoppingOnError: !repairIllFormedSequences,
|
||||||
|
sendingOutputTo: sink)
|
||||||
return (result, hadError)
|
return (result, hadError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -277,16 +277,16 @@ extension String.CharacterView : RangeReplaceableCollection {
|
|||||||
switch c._representation {
|
switch c._representation {
|
||||||
case .small(let _63bits):
|
case .small(let _63bits):
|
||||||
let bytes = Character._smallValue(_63bits)
|
let bytes = Character._smallValue(_63bits)
|
||||||
_core.appendContents(of: Character._SmallUTF16(bytes))
|
_core.append(contentsOf: Character._SmallUTF16(bytes))
|
||||||
case .large(_):
|
case .large(_):
|
||||||
_core.append(String(c)._core)
|
_core.append(String(c)._core)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append the elements of `newElements` to `self`.
|
/// Append the elements of `newElements` to `self`.
|
||||||
public mutating func appendContents<
|
public mutating func append<
|
||||||
S : Sequence where S.Iterator.Element == Character
|
S : Sequence where S.Iterator.Element == Character
|
||||||
>(of newElements: S) {
|
>(contentsOf newElements: S) {
|
||||||
reserveCapacity(_core.count + newElements.underestimatedCount)
|
reserveCapacity(_core.count + newElements.underestimatedCount)
|
||||||
for c in newElements {
|
for c in newElements {
|
||||||
self.append(c)
|
self.append(c)
|
||||||
@@ -298,7 +298,7 @@ extension String.CharacterView : RangeReplaceableCollection {
|
|||||||
S : Sequence where S.Iterator.Element == Character
|
S : Sequence where S.Iterator.Element == Character
|
||||||
>(_ characters: S) {
|
>(_ characters: S) {
|
||||||
self = String.CharacterView()
|
self = String.CharacterView()
|
||||||
self.appendContents(of: characters)
|
self.append(contentsOf: characters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +326,7 @@ extension String.CharacterView {
|
|||||||
fatalError("unavailable function can't be called")
|
fatalError("unavailable function can't be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable, renamed="appendContents(of:)")
|
@available(*, unavailable, renamed="append(contentsOf:)")
|
||||||
public mutating func appendContentsOf<
|
public mutating func appendContentsOf<
|
||||||
S : Sequence where S.Iterator.Element == Character
|
S : Sequence where S.Iterator.Element == Character
|
||||||
>(newElements: S) {
|
>(newElements: S) {
|
||||||
|
|||||||
@@ -336,17 +336,19 @@ public struct _StringCore {
|
|||||||
start: UnsafeMutablePointer<UTF8.CodeUnit>(_baseAddress),
|
start: UnsafeMutablePointer<UTF8.CodeUnit>(_baseAddress),
|
||||||
count: count
|
count: count
|
||||||
) {
|
) {
|
||||||
Encoding.encode(UnicodeScalar(UInt32(x)), output: output)
|
Encoding.encode(UnicodeScalar(UInt32(x)), sendingOutputTo: output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let hadError = transcode(UTF16.self, encoding,
|
let hadError = transcode(
|
||||||
UnsafeBufferPointer(
|
UnsafeBufferPointer(
|
||||||
start: UnsafeMutablePointer<UTF16.CodeUnit>(_baseAddress),
|
start: UnsafeMutablePointer<UTF16.CodeUnit>(_baseAddress),
|
||||||
count: count
|
count: count
|
||||||
).makeIterator(),
|
).makeIterator(),
|
||||||
output,
|
from: UTF16.self,
|
||||||
stoppingOnError: true
|
to: encoding,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: output
|
||||||
)
|
)
|
||||||
_sanityCheck(!hadError, "Swift.String with native storage should not have unpaired surrogates")
|
_sanityCheck(!hadError, "Swift.String with native storage should not have unpaired surrogates")
|
||||||
}
|
}
|
||||||
@@ -652,9 +654,9 @@ extension _StringCore : RangeReplaceableCollection {
|
|||||||
: isRepresentableAsASCII() && !newElements.contains { $0 > 0x7f } ? 1
|
: isRepresentableAsASCII() && !newElements.contains { $0 > 0x7f } ? 1
|
||||||
: 2
|
: 2
|
||||||
))
|
))
|
||||||
r.appendContents(of: self[0..<bounds.startIndex])
|
r.append(contentsOf: self[0..<bounds.startIndex])
|
||||||
r.appendContents(of: newElements)
|
r.append(contentsOf: newElements)
|
||||||
r.appendContents(of: self[bounds.endIndex..<count])
|
r.append(contentsOf: self[bounds.endIndex..<count])
|
||||||
self = r
|
self = r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -677,9 +679,9 @@ extension _StringCore : RangeReplaceableCollection {
|
|||||||
minElementWidth: 1)
|
minElementWidth: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func appendContents<
|
public mutating func append<
|
||||||
S : Sequence where S.Iterator.Element == UTF16.CodeUnit
|
S : Sequence where S.Iterator.Element == UTF16.CodeUnit
|
||||||
>(of s: S) {
|
>(contentsOf s: S) {
|
||||||
var width = elementWidth
|
var width = elementWidth
|
||||||
if width == 1 {
|
if width == 1 {
|
||||||
if let hasNonAscii = s._preprocessingPass({
|
if let hasNonAscii = s._preprocessingPass({
|
||||||
|
|||||||
@@ -263,10 +263,10 @@ extension String.UnicodeScalarView : RangeReplaceableCollection {
|
|||||||
/// Append the elements of `newElements` to `self`.
|
/// Append the elements of `newElements` to `self`.
|
||||||
///
|
///
|
||||||
/// - Complexity: O(*length of result*).
|
/// - Complexity: O(*length of result*).
|
||||||
public mutating func appendContents<
|
public mutating func append<
|
||||||
S : Sequence where S.Iterator.Element == UnicodeScalar
|
S : Sequence where S.Iterator.Element == UnicodeScalar
|
||||||
>(of newElements: S) {
|
>(contentsOf newElements: S) {
|
||||||
_core.appendContents(of: newElements.lazy.flatMap { $0.utf16 })
|
_core.append(contentsOf: newElements.lazy.flatMap { $0.utf16 })
|
||||||
}
|
}
|
||||||
/// Replace the elements within `bounds` with `newElements`.
|
/// Replace the elements within `bounds` with `newElements`.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -70,7 +70,10 @@ public protocol UnicodeCodec {
|
|||||||
|
|
||||||
/// Encode a `UnicodeScalar` as a series of `CodeUnit`s by
|
/// Encode a `UnicodeScalar` as a series of `CodeUnit`s by
|
||||||
/// calling `output` on each `CodeUnit`.
|
/// calling `output` on each `CodeUnit`.
|
||||||
static func encode(input: UnicodeScalar, output: (CodeUnit) -> Void)
|
static func encode(
|
||||||
|
input: UnicodeScalar,
|
||||||
|
sendingOutputTo processCodeUnit: (CodeUnit) -> Void
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A codec for [UTF-8](http://www.unicode.org/glossary/#UTF_8).
|
/// A codec for [UTF-8](http://www.unicode.org/glossary/#UTF_8).
|
||||||
@@ -452,7 +455,7 @@ public struct UTF8 : UnicodeCodec {
|
|||||||
/// calling `output` on each `CodeUnit`.
|
/// calling `output` on each `CodeUnit`.
|
||||||
public static func encode(
|
public static func encode(
|
||||||
input: UnicodeScalar,
|
input: UnicodeScalar,
|
||||||
output put: (CodeUnit) -> Void
|
sendingOutputTo processCodeUnit: (CodeUnit) -> Void
|
||||||
) {
|
) {
|
||||||
var c = UInt32(input)
|
var c = UInt32(input)
|
||||||
var buf3 = UInt8(c & 0xFF)
|
var buf3 = UInt8(c & 0xFF)
|
||||||
@@ -474,13 +477,13 @@ public struct UTF8 : UnicodeCodec {
|
|||||||
else {
|
else {
|
||||||
c >>= 6
|
c >>= 6
|
||||||
buf1 = (buf1 & 0x3F) | 0x80 // 10xxxxxx
|
buf1 = (buf1 & 0x3F) | 0x80 // 10xxxxxx
|
||||||
put(UInt8(c | 0xF0)) // 11110xxx
|
processCodeUnit(UInt8(c | 0xF0)) // 11110xxx
|
||||||
}
|
}
|
||||||
put(buf1)
|
processCodeUnit(buf1)
|
||||||
}
|
}
|
||||||
put(buf2)
|
processCodeUnit(buf2)
|
||||||
}
|
}
|
||||||
put(buf3)
|
processCodeUnit(buf3)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if `byte` is a continuation byte of the form
|
/// Returns `true` if `byte` is a continuation byte of the form
|
||||||
@@ -619,17 +622,17 @@ public struct UTF16 : UnicodeCodec {
|
|||||||
/// calling `output` on each `CodeUnit`.
|
/// calling `output` on each `CodeUnit`.
|
||||||
public static func encode(
|
public static func encode(
|
||||||
input: UnicodeScalar,
|
input: UnicodeScalar,
|
||||||
output put: (CodeUnit) -> Void
|
sendingOutputTo processCodeUnit: (CodeUnit) -> Void
|
||||||
) {
|
) {
|
||||||
let scalarValue: UInt32 = UInt32(input)
|
let scalarValue: UInt32 = UInt32(input)
|
||||||
|
|
||||||
if scalarValue <= UInt32(UInt16.max) {
|
if scalarValue <= UInt32(UInt16.max) {
|
||||||
put(UInt16(scalarValue))
|
processCodeUnit(UInt16(scalarValue))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let lead_offset = UInt32(0xd800) - UInt32(0x10000 >> 10)
|
let lead_offset = UInt32(0xd800) - UInt32(0x10000 >> 10)
|
||||||
put(UInt16(lead_offset + (scalarValue >> 10)))
|
processCodeUnit(UInt16(lead_offset + (scalarValue >> 10)))
|
||||||
put(UInt16(0xdc00 + (scalarValue & 0x3ff)))
|
processCodeUnit(UInt16(0xdc00 + (scalarValue & 0x3ff)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -675,9 +678,9 @@ public struct UTF32 : UnicodeCodec {
|
|||||||
/// calling `output` on each `CodeUnit`.
|
/// calling `output` on each `CodeUnit`.
|
||||||
public static func encode(
|
public static func encode(
|
||||||
input: UnicodeScalar,
|
input: UnicodeScalar,
|
||||||
output put: (CodeUnit) -> Void
|
sendingOutputTo processCodeUnit: (CodeUnit) -> Void
|
||||||
) {
|
) {
|
||||||
put(UInt32(input))
|
processCodeUnit(UInt32(input))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,10 +694,13 @@ public func transcode<
|
|||||||
Input : IteratorProtocol,
|
Input : IteratorProtocol,
|
||||||
InputEncoding : UnicodeCodec,
|
InputEncoding : UnicodeCodec,
|
||||||
OutputEncoding : UnicodeCodec
|
OutputEncoding : UnicodeCodec
|
||||||
where InputEncoding.CodeUnit == Input.Element>(
|
where InputEncoding.CodeUnit == Input.Element
|
||||||
inputEncoding: InputEncoding.Type, _ outputEncoding: OutputEncoding.Type,
|
>(
|
||||||
_ input: Input, _ output: (OutputEncoding.CodeUnit) -> Void,
|
input: Input,
|
||||||
stoppingOnError stopOnError: Bool
|
from inputEncoding: InputEncoding.Type,
|
||||||
|
to outputEncoding: OutputEncoding.Type,
|
||||||
|
stoppingOnError stopOnError: Bool,
|
||||||
|
sendingOutputTo processCodeUnit: (OutputEncoding.CodeUnit) -> Void
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
var input = input
|
var input = input
|
||||||
|
|
||||||
@@ -708,14 +714,14 @@ public func transcode<
|
|||||||
while scalar != .emptyInput {
|
while scalar != .emptyInput {
|
||||||
switch scalar {
|
switch scalar {
|
||||||
case .scalarValue(let us):
|
case .scalarValue(let us):
|
||||||
OutputEncoding.encode(us, output: output)
|
OutputEncoding.encode(us, sendingOutputTo: processCodeUnit)
|
||||||
case .emptyInput:
|
case .emptyInput:
|
||||||
_sanityCheckFailure("should not enter the loop when input becomes empty")
|
_sanityCheckFailure("should not enter the loop when input becomes empty")
|
||||||
case .error:
|
case .error:
|
||||||
if stopOnError {
|
if stopOnError {
|
||||||
return (hadError: true)
|
return (hadError: true)
|
||||||
} else {
|
} else {
|
||||||
OutputEncoding.encode("\u{fffd}", output: output)
|
OutputEncoding.encode("\u{fffd}", sendingOutputTo: processCodeUnit)
|
||||||
hadError = true
|
hadError = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -925,12 +931,14 @@ extension UTF16 {
|
|||||||
/// If it is `false`, `nil` is returned if an ill-formed code unit sequence is
|
/// If it is `false`, `nil` is returned if an ill-formed code unit sequence is
|
||||||
/// found in `input`.
|
/// found in `input`.
|
||||||
@warn_unused_result
|
@warn_unused_result
|
||||||
public static func measure<
|
public static func transcodedLength<
|
||||||
Encoding : UnicodeCodec, Input : IteratorProtocol
|
Encoding : UnicodeCodec, Input : IteratorProtocol
|
||||||
where Encoding.CodeUnit == Input.Element
|
where Encoding.CodeUnit == Input.Element
|
||||||
>(
|
>(
|
||||||
_: Encoding.Type, input: Input, repairIllFormedSequences: Bool
|
of input: Input,
|
||||||
) -> (Int, Bool)? {
|
decodedAs sourceEncoding: Encoding.Type,
|
||||||
|
repairingIllFormedSequences: Bool
|
||||||
|
) -> (count: Int, isASCII: Bool)? {
|
||||||
var input = input
|
var input = input
|
||||||
var count = 0
|
var count = 0
|
||||||
var isAscii = true
|
var isAscii = true
|
||||||
@@ -947,7 +955,7 @@ extension UTF16 {
|
|||||||
case .emptyInput:
|
case .emptyInput:
|
||||||
break loop
|
break loop
|
||||||
case .error:
|
case .error:
|
||||||
if !repairIllFormedSequences {
|
if !repairingIllFormedSequences {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
isAscii = false
|
isAscii = false
|
||||||
@@ -961,3 +969,29 @@ extension UTF16 {
|
|||||||
@available(*, unavailable, renamed="UnicodeCodec")
|
@available(*, unavailable, renamed="UnicodeCodec")
|
||||||
public typealias UnicodeCodecType = UnicodeCodec
|
public typealias UnicodeCodecType = UnicodeCodec
|
||||||
|
|
||||||
|
@available(*, unavailable, message="use 'transcode(_:from:to:stoppingOnError:sendingOutputTo:)'")
|
||||||
|
public func transcode<
|
||||||
|
Input : IteratorProtocol,
|
||||||
|
InputEncoding : UnicodeCodec,
|
||||||
|
OutputEncoding : UnicodeCodec
|
||||||
|
where InputEncoding.CodeUnit == Input.Element
|
||||||
|
>(
|
||||||
|
inputEncoding: InputEncoding.Type, _ outputEncoding: OutputEncoding.Type,
|
||||||
|
_ input: Input, _ output: (OutputEncoding.CodeUnit) -> Void,
|
||||||
|
stoppingOnError stopOnError: Bool
|
||||||
|
) -> Bool {
|
||||||
|
fatalError("unavailable function can't be called")
|
||||||
|
}
|
||||||
|
|
||||||
|
extension UTF16 {
|
||||||
|
@available(*, unavailable, message="use 'transcodedLength(of:decodedAs:repairingIllFormedSequences:)'")
|
||||||
|
public static func measure<
|
||||||
|
Encoding : UnicodeCodec, Input : IteratorProtocol
|
||||||
|
where Encoding.CodeUnit == Input.Element
|
||||||
|
>(
|
||||||
|
_: Encoding.Type, input: Input, repairIllFormedSequences: Bool
|
||||||
|
) -> (Int, Bool)? {
|
||||||
|
fatalError("unavailable function can't be called")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,11 +33,6 @@ public struct UnicodeScalar :
|
|||||||
self = value
|
self = value
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an instance of the NUL scalar value.
|
|
||||||
public init() {
|
|
||||||
self._value = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create an instance with numeric value `v`.
|
/// Create an instance with numeric value `v`.
|
||||||
///
|
///
|
||||||
/// - Precondition: `v` is a valid Unicode scalar value.
|
/// - Precondition: `v` is a valid Unicode scalar value.
|
||||||
@@ -83,7 +78,7 @@ public struct UnicodeScalar :
|
|||||||
/// - parameter forceASCII: If `true`, forces most values into a numeric
|
/// - parameter forceASCII: If `true`, forces most values into a numeric
|
||||||
/// representation.
|
/// representation.
|
||||||
@warn_unused_result
|
@warn_unused_result
|
||||||
public func escape(asASCII forceASCII: Bool) -> String {
|
public func escaped(asASCII forceASCII: Bool) -> String {
|
||||||
func lowNibbleAsHex(v: UInt32) -> String {
|
func lowNibbleAsHex(v: UInt32) -> String {
|
||||||
let nibble = v & 15
|
let nibble = v & 15
|
||||||
if nibble < 10 {
|
if nibble < 10 {
|
||||||
@@ -203,11 +198,11 @@ public struct UnicodeScalar :
|
|||||||
extension UnicodeScalar : CustomStringConvertible, CustomDebugStringConvertible {
|
extension UnicodeScalar : CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
/// A textual representation of `self`.
|
/// A textual representation of `self`.
|
||||||
public var description: String {
|
public var description: String {
|
||||||
return "\"\(escape(asASCII: false))\""
|
return "\"\(escaped(asASCII: false))\""
|
||||||
}
|
}
|
||||||
/// A textual representation of `self`, suitable for debugging.
|
/// A textual representation of `self`, suitable for debugging.
|
||||||
public var debugDescription: String {
|
public var debugDescription: String {
|
||||||
return "\"\(escape(asASCII: true))\""
|
return "\"\(escaped(asASCII: true))\""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,3 +320,16 @@ func _ascii16(c: UnicodeScalar) -> UTF16.CodeUnit {
|
|||||||
return UTF16.CodeUnit(c.value)
|
return UTF16.CodeUnit(c.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension UnicodeScalar {
|
||||||
|
/// Creates an instance of the NUL scalar value.
|
||||||
|
@available(*, unavailable, message="use the 'UnicodeScalar(\"\\0\")'")
|
||||||
|
public init() {
|
||||||
|
fatalError("unavailable function can't be called")
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, unavailable, renamed="escaped")
|
||||||
|
public func escape(asASCII forceASCII: Bool) -> String {
|
||||||
|
fatalError("unavailable function can't be called")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,8 @@
|
|||||||
// LITERAL4-DAG: Decl[InstanceVar]/CurrNominal: startIndex[#Index#]; name=startIndex{{$}}
|
// LITERAL4-DAG: Decl[InstanceVar]/CurrNominal: startIndex[#Index#]; name=startIndex{{$}}
|
||||||
// LITERAL4-DAG: Decl[InstanceVar]/CurrNominal: endIndex[#Index#]; name=endIndex{{$}}
|
// LITERAL4-DAG: Decl[InstanceVar]/CurrNominal: endIndex[#Index#]; name=endIndex{{$}}
|
||||||
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: append({#(c): Character#})[#Void#]; name=append(c: Character){{$}}
|
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: append({#(c): Character#})[#Void#]; name=append(c: Character){{$}}
|
||||||
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: appendContents({#of: S#})[#Void#]; name=appendContents(of: S){{$}}
|
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: append({#contentsOf: S#})[#Void#]; name=append(contentsOf: S){{$}}
|
||||||
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: insertContents({#of: S#}, {#at: Index#})[#Void#]; name=insertContents(of: S, at: Index){{$}}
|
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: insert({#contentsOf: S#}, {#at: Index#})[#Void#]; name=insert(contentsOf: S, at: Index){{$}}
|
||||||
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: remove({#at: Index#})[#Character#]; name=remove(at: Index){{$}}
|
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: remove({#at: Index#})[#Character#]; name=remove(at: Index){{$}}
|
||||||
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: lowercased()[#String#]; name=lowercased(){{$}}
|
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: lowercased()[#String#]; name=lowercased(){{$}}
|
||||||
|
|
||||||
@@ -59,4 +59,4 @@ func giveMeAString() -> Int {
|
|||||||
// LITERAL5-DAG: Decl[InstanceVar]/CurrNominal: endIndex[#Index#]{{; name=.+$}}
|
// LITERAL5-DAG: Decl[InstanceVar]/CurrNominal: endIndex[#Index#]{{; name=.+$}}
|
||||||
// LITERAL5-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: reserveCapacity({#(n): Int#})[#Void#]{{; name=.+$}}
|
// LITERAL5-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: reserveCapacity({#(n): Int#})[#Void#]{{; name=.+$}}
|
||||||
// LITERAL5-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: append({#(c): Character#})[#Void#]{{; name=.+$}}
|
// LITERAL5-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: append({#(c): Character#})[#Void#]{{; name=.+$}}
|
||||||
// LITERAL5-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: appendContents({#of: S#})[#Void#]{{; name=.+$}}
|
// LITERAL5-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: append({#contentsOf: S#})[#Void#]{{; name=.+$}}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func flatten<Element, Seq: Sequence, InnerSequence: Sequence
|
|||||||
var result = [Element]()
|
var result = [Element]()
|
||||||
|
|
||||||
for innerSequence in outerSequence {
|
for innerSequence in outerSequence {
|
||||||
result.appendContents(of: innerSequence)
|
result.append(contentsOf: innerSequence)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -124,10 +124,10 @@ extension RangeReplaceableCollection {
|
|||||||
var result = Self()
|
var result = Self()
|
||||||
var iter = elements.makeIterator()
|
var iter = elements.makeIterator()
|
||||||
if let first = iter.next() {
|
if let first = iter.next() {
|
||||||
result.appendContents(of: first)
|
result.append(contentsOf: first)
|
||||||
while let next = iter.next() {
|
while let next = iter.next() {
|
||||||
result.appendContents(of: self)
|
result.append(contentsOf: self)
|
||||||
result.appendContents(of: next)
|
result.append(contentsOf: next)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -90,17 +90,17 @@ public protocol CollectionBuilder {
|
|||||||
/// added at the end.
|
/// added at the end.
|
||||||
///
|
///
|
||||||
/// Complexity: amortized O(n), where `n` is equal to `count(elements)`.
|
/// Complexity: amortized O(n), where `n` is equal to `count(elements)`.
|
||||||
mutating func appendContents<
|
mutating func append<
|
||||||
C : Collection
|
C : Collection
|
||||||
where
|
where
|
||||||
C.Iterator.Element == Element
|
C.Iterator.Element == Element
|
||||||
>(of elements: C)
|
>(contentsOf elements: C)
|
||||||
|
|
||||||
/// Append elements from `otherBuilder` to `self`, emptying `otherBuilder`.
|
/// Append elements from `otherBuilder` to `self`, emptying `otherBuilder`.
|
||||||
///
|
///
|
||||||
/// Equivalent to::
|
/// Equivalent to::
|
||||||
///
|
///
|
||||||
/// self.appendContents(of: otherBuilder.takeResult())
|
/// self.append(contentsOf: otherBuilder.takeResult())
|
||||||
///
|
///
|
||||||
/// but is more efficient.
|
/// but is more efficient.
|
||||||
///
|
///
|
||||||
@@ -146,12 +146,12 @@ public struct ArrayBuilder<T> : CollectionBuilder {
|
|||||||
_resultTail.append(element)
|
_resultTail.append(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func appendContents<
|
public mutating func append<
|
||||||
C : Collection
|
C : Collection
|
||||||
where
|
where
|
||||||
C.Iterator.Element == T
|
C.Iterator.Element == T
|
||||||
>(of elements: C) {
|
>(contentsOf elements: C) {
|
||||||
_resultTail.appendContents(of: elements)
|
_resultTail.append(contentsOf: elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func moveContentsOf(otherBuilder: inout ArrayBuilder<T>) {
|
public mutating func moveContentsOf(otherBuilder: inout ArrayBuilder<T>) {
|
||||||
@@ -160,7 +160,7 @@ public struct ArrayBuilder<T> : CollectionBuilder {
|
|||||||
_resultParts.append(_resultTail)
|
_resultParts.append(_resultTail)
|
||||||
_resultTail = []
|
_resultTail = []
|
||||||
// FIXME: not O(1)!
|
// FIXME: not O(1)!
|
||||||
_resultParts.appendContents(of: otherBuilder._resultParts)
|
_resultParts.append(contentsOf: otherBuilder._resultParts)
|
||||||
otherBuilder._resultParts = []
|
otherBuilder._resultParts = []
|
||||||
swap(&_resultTail, &otherBuilder._resultTail)
|
swap(&_resultTail, &otherBuilder._resultTail)
|
||||||
}
|
}
|
||||||
@@ -1058,11 +1058,11 @@ struct _ElementCollectorOneToMaybeOne<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func appendContents<
|
mutating func append<
|
||||||
C : Collection
|
C : Collection
|
||||||
where
|
where
|
||||||
C.Iterator.Element == Element
|
C.Iterator.Element == Element
|
||||||
>(of elements: C) {
|
>(contentsOf elements: C) {
|
||||||
for e in elements {
|
for e in elements {
|
||||||
append(e)
|
append(e)
|
||||||
}
|
}
|
||||||
@@ -1076,11 +1076,11 @@ protocol _ElementCollector {
|
|||||||
|
|
||||||
mutating func append(element: Element)
|
mutating func append(element: Element)
|
||||||
|
|
||||||
mutating func appendContents<
|
mutating func append<
|
||||||
C : Collection
|
C : Collection
|
||||||
where
|
where
|
||||||
C.Iterator.Element == Element
|
C.Iterator.Element == Element
|
||||||
>(of elements: C)
|
>(contentsOf elements: C)
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CollectionTransformerFinalizer<PipelineInputElement, Result> {
|
class _CollectionTransformerFinalizer<PipelineInputElement, Result> {
|
||||||
@@ -1141,11 +1141,11 @@ struct _ElementCollectorReduce<Element_, Result> : _ElementCollector {
|
|||||||
_current = _combine(_current, element)
|
_current = _combine(_current, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func appendContents<
|
mutating func append<
|
||||||
C : Collection
|
C : Collection
|
||||||
where
|
where
|
||||||
C.Iterator.Element == Element
|
C.Iterator.Element == Element
|
||||||
>(of elements: C) {
|
>(contentsOf elements: C) {
|
||||||
for e in elements {
|
for e in elements {
|
||||||
append(e)
|
append(e)
|
||||||
}
|
}
|
||||||
@@ -1209,12 +1209,12 @@ struct _ElementCollectorCollectTo<
|
|||||||
_builder.append(element)
|
_builder.append(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func appendContents<
|
mutating func append<
|
||||||
C : Collection
|
C : Collection
|
||||||
where
|
where
|
||||||
C.Iterator.Element == Element
|
C.Iterator.Element == Element
|
||||||
>(of elements: C) {
|
>(contentsOf elements: C) {
|
||||||
_builder.appendContents(of: elements)
|
_builder.append(contentsOf: elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func takeResult() -> BuildableCollection {
|
mutating func takeResult() -> BuildableCollection {
|
||||||
@@ -1394,7 +1394,7 @@ func _parallelMap(input: [Int], transform: (Int) -> Int, range: Range<Int>)
|
|||||||
|
|
||||||
var builder = Array<Int>.Builder()
|
var builder = Array<Int>.Builder()
|
||||||
if range.count < 1_000 {
|
if range.count < 1_000 {
|
||||||
builder.appendContents(of: input[range].map(transform))
|
builder.append(contentsOf: input[range].map(transform))
|
||||||
} else {
|
} else {
|
||||||
let tasks = input.split(range).map {
|
let tasks = input.split(range).map {
|
||||||
(subRange) in
|
(subRange) in
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ struct EscapedStringFormat : XStreamable {
|
|||||||
func writeTo<Target: XOutputStream>(target: inout Target) {
|
func writeTo<Target: XOutputStream>(target: inout Target) {
|
||||||
target.append("\"")
|
target.append("\"")
|
||||||
for c in _value.unicodeScalars {
|
for c in _value.unicodeScalars {
|
||||||
target.append(c.escape(asASCII: true))
|
target.append(c.escaped(asASCII: true))
|
||||||
}
|
}
|
||||||
target.append("\"")
|
target.append("\"")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ struct MonoStruct {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
static var zang = UnicodeScalar()
|
static var zang = UnicodeScalar("\0")
|
||||||
|
|
||||||
static var zung: UInt16 {
|
static var zung: UInt16 {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@@ -458,7 +458,7 @@ func testSingleQuoteStringLiterals() {
|
|||||||
|
|
||||||
// <rdar://problem/17128913>
|
// <rdar://problem/17128913>
|
||||||
var s = ""
|
var s = ""
|
||||||
s.appendContents(of: ["x"])
|
s.append(contentsOf: ["x"])
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// InOut arguments
|
// InOut arguments
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ RangeReplaceableTestSuite.test("append/dispatch") {
|
|||||||
|
|
||||||
RangeReplaceableTestSuite.test("appendContentsOf/dispatch") {
|
RangeReplaceableTestSuite.test("appendContentsOf/dispatch") {
|
||||||
var tester = RangeReplaceableCollectionLog.dispatchTester([ OpaqueValue(1) ])
|
var tester = RangeReplaceableCollectionLog.dispatchTester([ OpaqueValue(1) ])
|
||||||
tester.appendContents(of: [ 2, 3 ].map(OpaqueValue.init))
|
tester.append(contentsOf: [ 2, 3 ].map(OpaqueValue.init))
|
||||||
expectCustomizable(tester, tester.log.appendContentsOf)
|
expectCustomizable(tester, tester.log.appendContentsOf)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,10 +40,10 @@ RangeReplaceableTestSuite.test("insert/dispatch") {
|
|||||||
expectCustomizable(tester, tester.log.insert)
|
expectCustomizable(tester, tester.log.insert)
|
||||||
}
|
}
|
||||||
|
|
||||||
RangeReplaceableTestSuite.test("insertContents(of:at:)/dispatch") {
|
RangeReplaceableTestSuite.test("insert(contentsOf:at:)/dispatch") {
|
||||||
var tester = RangeReplaceableCollectionLog.dispatchTester([ OpaqueValue(1) ])
|
var tester = RangeReplaceableCollectionLog.dispatchTester([ OpaqueValue(1) ])
|
||||||
tester.insertContents(
|
tester.insert(
|
||||||
of: [ 2, 3 ].map(OpaqueValue.init),
|
contentsOf: [ 2, 3 ].map(OpaqueValue.init),
|
||||||
at: tester.base.endIndex)
|
at: tester.base.endIndex)
|
||||||
expectCustomizable(tester, tester.log.insertContentsOf)
|
expectCustomizable(tester, tester.log.insertContentsOf)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ do {
|
|||||||
func makeCollection(elements: [OpaqueValue<Int>])
|
func makeCollection(elements: [OpaqueValue<Int>])
|
||||||
-> ${Wrapper}<${Base}<OpaqueValue<Int>>> {
|
-> ${Wrapper}<${Base}<OpaqueValue<Int>>> {
|
||||||
var baseElements = prefix.map(OpaqueValue.init)
|
var baseElements = prefix.map(OpaqueValue.init)
|
||||||
baseElements.appendContents(of: elements)
|
baseElements.append(contentsOf: elements)
|
||||||
baseElements.appendContents(of: suffix.map(OpaqueValue.init))
|
baseElements.append(contentsOf: suffix.map(OpaqueValue.init))
|
||||||
let base = ${Base}(elements: baseElements)
|
let base = ${Base}(elements: baseElements)
|
||||||
let startIndex = base.startIndex.advanced(by: numericCast(prefix.count))
|
let startIndex = base.startIndex.advanced(by: numericCast(prefix.count))
|
||||||
let endIndex = base.startIndex.advanced(
|
let endIndex = base.startIndex.advanced(
|
||||||
@@ -26,8 +26,8 @@ do {
|
|||||||
func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
|
func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
|
||||||
-> ${Wrapper}<${Base}<MinimalEquatableValue>> {
|
-> ${Wrapper}<${Base}<MinimalEquatableValue>> {
|
||||||
var baseElements = prefix.map(MinimalEquatableValue.init)
|
var baseElements = prefix.map(MinimalEquatableValue.init)
|
||||||
baseElements.appendContents(of: elements)
|
baseElements.append(contentsOf: elements)
|
||||||
baseElements.appendContents(of: suffix.map(MinimalEquatableValue.init))
|
baseElements.append(contentsOf: suffix.map(MinimalEquatableValue.init))
|
||||||
let base = ${Base}(elements: baseElements)
|
let base = ${Base}(elements: baseElements)
|
||||||
let startIndex = base.startIndex.advanced(by: numericCast(prefix.count))
|
let startIndex = base.startIndex.advanced(by: numericCast(prefix.count))
|
||||||
let endIndex = base.startIndex.advanced(
|
let endIndex = base.startIndex.advanced(
|
||||||
@@ -40,8 +40,8 @@ do {
|
|||||||
func makeCollectionOfComparable(elements: [MinimalComparableValue])
|
func makeCollectionOfComparable(elements: [MinimalComparableValue])
|
||||||
-> ${Wrapper}<${Base}<MinimalComparableValue>> {
|
-> ${Wrapper}<${Base}<MinimalComparableValue>> {
|
||||||
var baseElements = prefix.map(MinimalComparableValue.init)
|
var baseElements = prefix.map(MinimalComparableValue.init)
|
||||||
baseElements.appendContents(of: elements)
|
baseElements.append(contentsOf: elements)
|
||||||
baseElements.appendContents(of: suffix.map(MinimalComparableValue.init))
|
baseElements.append(contentsOf: suffix.map(MinimalComparableValue.init))
|
||||||
let base = ${Base}(elements: baseElements)
|
let base = ${Base}(elements: baseElements)
|
||||||
let startIndex = base.startIndex.advanced(by: numericCast(prefix.count))
|
let startIndex = base.startIndex.advanced(by: numericCast(prefix.count))
|
||||||
let endIndex = base.startIndex.advanced(
|
let endIndex = base.startIndex.advanced(
|
||||||
|
|||||||
@@ -119,10 +119,10 @@ ${Self}TestSuite.test("subscript(_:Index)/Set/DifferentCollections") {
|
|||||||
func getTwoInterchangeable${Self}(elements: [Int])
|
func getTwoInterchangeable${Self}(elements: [Int])
|
||||||
-> (${Self}<OpaqueValue<Int>>, ${Self}<OpaqueValue<Int>>) {
|
-> (${Self}<OpaqueValue<Int>>, ${Self}<OpaqueValue<Int>>) {
|
||||||
var c1 = ${Self}<OpaqueValue<Int>>()
|
var c1 = ${Self}<OpaqueValue<Int>>()
|
||||||
c1.appendContents(of: elements.map(OpaqueValue.init))
|
c1.append(contentsOf: elements.map(OpaqueValue.init))
|
||||||
|
|
||||||
var c2 = ${Self}<OpaqueValue<Int>>()
|
var c2 = ${Self}<OpaqueValue<Int>>()
|
||||||
c2.appendContents(of: elements.map(OpaqueValue.init))
|
c2.append(contentsOf: elements.map(OpaqueValue.init))
|
||||||
|
|
||||||
return (c1, c2)
|
return (c1, c2)
|
||||||
}
|
}
|
||||||
@@ -199,10 +199,10 @@ ${Self}TestSuite.test("append()/IndexInvalidation") {
|
|||||||
_blackHole(c2)
|
_blackHole(c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
${Self}TestSuite.test("appendContents(of:)/IndexInvalidation") {
|
${Self}TestSuite.test("append(contentsOf:)/IndexInvalidation") {
|
||||||
var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ])
|
var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ])
|
||||||
let i1 = c1.endIndex
|
let i1 = c1.endIndex
|
||||||
c1.appendContents(of: [ 4040, 5050 ].map(OpaqueValue.init))
|
c1.append(contentsOf: [ 4040, 5050 ].map(OpaqueValue.init))
|
||||||
let i2 = c1.startIndex.advanced(by: 3)
|
let i2 = c1.startIndex.advanced(by: 3)
|
||||||
|
|
||||||
expectCrashLater()
|
expectCrashLater()
|
||||||
@@ -234,10 +234,10 @@ ${Self}TestSuite.test("insert()/IndexInvalidation") {
|
|||||||
_blackHole(c2)
|
_blackHole(c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
${Self}TestSuite.test("insertContents(of:at:)/IndexInvalidation") {
|
${Self}TestSuite.test("insert(contentsOf:at:)/IndexInvalidation") {
|
||||||
var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ])
|
var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ])
|
||||||
let i1 = c1.startIndex.advanced(by: 1)
|
let i1 = c1.startIndex.advanced(by: 1)
|
||||||
c1.insertContents(of: [ 4040, 5050 ].map(OpaqueValue.init), at: i1)
|
c1.insert(contentsOf: [ 4040, 5050 ].map(OpaqueValue.init), at: i1)
|
||||||
let i2 = c1.startIndex.advanced(by: 1)
|
let i2 = c1.startIndex.advanced(by: 1)
|
||||||
|
|
||||||
expectCrashLater()
|
expectCrashLater()
|
||||||
|
|||||||
@@ -608,7 +608,7 @@ func asciiString<
|
|||||||
S: Sequence where S.Iterator.Element == Character
|
S: Sequence where S.Iterator.Element == Character
|
||||||
>(content: S) -> String {
|
>(content: S) -> String {
|
||||||
var s = String()
|
var s = String()
|
||||||
s.appendContents(of: content)
|
s.append(contentsOf: content)
|
||||||
expectEqual(1, s._core.elementWidth)
|
expectEqual(1, s._core.elementWidth)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
@@ -633,11 +633,11 @@ StringTests.test("stringCoreExtensibility")
|
|||||||
if k == 0 { expectEqual(1, x.elementWidth) }
|
if k == 0 { expectEqual(1, x.elementWidth) }
|
||||||
|
|
||||||
for i in 0..<count {
|
for i in 0..<count {
|
||||||
x.appendContents(of:
|
x.append(contentsOf:
|
||||||
repeatElement(i < boundary ? ascii : nonAscii, count: 3))
|
repeatElement(i < boundary ? ascii : nonAscii, count: 3))
|
||||||
}
|
}
|
||||||
// Make sure we can append pure ASCII to wide storage
|
// Make sure we can append pure ASCII to wide storage
|
||||||
x.appendContents(of: repeatElement(ascii, count: 2))
|
x.append(contentsOf: repeatElement(ascii, count: 2))
|
||||||
|
|
||||||
expectEqualSequence(
|
expectEqualSequence(
|
||||||
[UTF16.CodeUnit(UnicodeScalar("b").value)]
|
[UTF16.CodeUnit(UnicodeScalar("b").value)]
|
||||||
@@ -721,7 +721,7 @@ func makeStringCore(base: String) -> _StringCore {
|
|||||||
var x = _StringCore()
|
var x = _StringCore()
|
||||||
// make sure some - but not all - replacements will have to grow the buffer
|
// make sure some - but not all - replacements will have to grow the buffer
|
||||||
x.reserveCapacity(base._core.count * 3 / 2)
|
x.reserveCapacity(base._core.count * 3 / 2)
|
||||||
x.appendContents(of: base._core)
|
x.append(contentsOf: base._core)
|
||||||
// In case the core was widened and lost its capacity
|
// In case the core was widened and lost its capacity
|
||||||
x.reserveCapacity(base._core.count * 3 / 2)
|
x.reserveCapacity(base._core.count * 3 / 2)
|
||||||
return x
|
return x
|
||||||
@@ -784,17 +784,17 @@ StringTests.test("reserveCapacity") {
|
|||||||
let id0 = s.bufferID
|
let id0 = s.bufferID
|
||||||
let oldCap = s.capacity
|
let oldCap = s.capacity
|
||||||
let x: Character = "x" // Help the typechecker - <rdar://problem/17128913>
|
let x: Character = "x" // Help the typechecker - <rdar://problem/17128913>
|
||||||
s.insertContents(of: repeatElement(x, count: s.capacity + 1), at: s.endIndex)
|
s.insert(contentsOf: repeatElement(x, count: s.capacity + 1), at: s.endIndex)
|
||||||
expectNotEqual(id0, s.bufferID)
|
expectNotEqual(id0, s.bufferID)
|
||||||
s = ""
|
s = ""
|
||||||
print("empty capacity \(s.capacity)")
|
print("empty capacity \(s.capacity)")
|
||||||
s.reserveCapacity(oldCap + 2)
|
s.reserveCapacity(oldCap + 2)
|
||||||
print("reserving \(oldCap + 2) -> \(s.capacity), width = \(s._core.elementWidth)")
|
print("reserving \(oldCap + 2) -> \(s.capacity), width = \(s._core.elementWidth)")
|
||||||
let id1 = s.bufferID
|
let id1 = s.bufferID
|
||||||
s.insertContents(of: repeatElement(x, count: oldCap + 2), at: s.endIndex)
|
s.insert(contentsOf: repeatElement(x, count: oldCap + 2), at: s.endIndex)
|
||||||
print("extending by \(oldCap + 2) -> \(s.capacity), width = \(s._core.elementWidth)")
|
print("extending by \(oldCap + 2) -> \(s.capacity), width = \(s._core.elementWidth)")
|
||||||
expectEqual(id1, s.bufferID)
|
expectEqual(id1, s.bufferID)
|
||||||
s.insertContents(of: repeatElement(x, count: s.capacity + 100), at: s.endIndex)
|
s.insert(contentsOf: repeatElement(x, count: s.capacity + 100), at: s.endIndex)
|
||||||
expectNotEqual(id1, s.bufferID)
|
expectNotEqual(id1, s.bufferID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,12 @@ func checkDecodeUTF<Codec : UnicodeCodec>(
|
|||||||
var decoded = [UInt32]()
|
var decoded = [UInt32]()
|
||||||
let output: (UInt32) -> Void = { decoded.append($0) }
|
let output: (UInt32) -> Void = { decoded.append($0) }
|
||||||
let iterator = EOFCountingIterator(utfStr)
|
let iterator = EOFCountingIterator(utfStr)
|
||||||
transcode(codec, UTF32.self, iterator, output, stoppingOnError: true)
|
transcode(
|
||||||
|
iterator,
|
||||||
|
from: codec,
|
||||||
|
to: UTF32.self,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: output)
|
||||||
expectGE(1, iterator.numTimesReturnedEOF)
|
expectGE(1, iterator.numTimesReturnedEOF)
|
||||||
if expectedHead != decoded {
|
if expectedHead != decoded {
|
||||||
return assertionFailure()
|
return assertionFailure()
|
||||||
@@ -143,7 +148,12 @@ func checkDecodeUTF<Codec : UnicodeCodec>(
|
|||||||
var decoded = [UInt32]()
|
var decoded = [UInt32]()
|
||||||
let output: (UInt32) -> Void = { decoded.append($0) }
|
let output: (UInt32) -> Void = { decoded.append($0) }
|
||||||
let iterator = EOFCountingIterator(utfStr)
|
let iterator = EOFCountingIterator(utfStr)
|
||||||
transcode(codec, UTF32.self, iterator, output, stoppingOnError: false)
|
transcode(
|
||||||
|
iterator,
|
||||||
|
from: codec,
|
||||||
|
to: UTF32.self,
|
||||||
|
stoppingOnError: false,
|
||||||
|
sendingOutputTo: output)
|
||||||
expectEqual(1, iterator.numTimesReturnedEOF)
|
expectEqual(1, iterator.numTimesReturnedEOF)
|
||||||
if expected != decoded {
|
if expected != decoded {
|
||||||
return assertionFailure()
|
return assertionFailure()
|
||||||
@@ -184,8 +194,12 @@ func checkEncodeUTF8(expected: [UInt8],
|
|||||||
var encoded = [UInt8]()
|
var encoded = [UInt8]()
|
||||||
let output: (UInt8) -> Void = { encoded.append($0) }
|
let output: (UInt8) -> Void = { encoded.append($0) }
|
||||||
let iterator = EOFCountingIterator(scalars)
|
let iterator = EOFCountingIterator(scalars)
|
||||||
let hadError =
|
let hadError = transcode(
|
||||||
transcode(UTF32.self, UTF8.self, iterator, output, stoppingOnError: true)
|
iterator,
|
||||||
|
from: UTF32.self,
|
||||||
|
to: UTF8.self,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: output)
|
||||||
expectFalse(hadError)
|
expectFalse(hadError)
|
||||||
expectGE(1, iterator.numTimesReturnedEOF)
|
expectGE(1, iterator.numTimesReturnedEOF)
|
||||||
if expected != encoded {
|
if expected != encoded {
|
||||||
@@ -1904,11 +1918,13 @@ UTF8Decoder.test("Noncharacters") {
|
|||||||
|
|
||||||
var UTF16Decoder = TestSuite("UTF16Decoder")
|
var UTF16Decoder = TestSuite("UTF16Decoder")
|
||||||
|
|
||||||
UTF16Decoder.test("measure") {
|
UTF16Decoder.test("UTF16.transcodedLength") {
|
||||||
do {
|
do {
|
||||||
var u8: [UTF8.CodeUnit] = [ 0, 1, 2, 3, 4, 5 ]
|
var u8: [UTF8.CodeUnit] = [ 0, 1, 2, 3, 4, 5 ]
|
||||||
let (count, isASCII) = UTF16.measure(
|
let (count, isASCII) = UTF16.transcodedLength(
|
||||||
UTF8.self, input: u8.makeIterator(), repairIllFormedSequences: false)!
|
of: u8.makeIterator(),
|
||||||
|
decodedAs: UTF8.self,
|
||||||
|
repairingIllFormedSequences: false)!
|
||||||
expectEqual(6, count)
|
expectEqual(6, count)
|
||||||
expectTrue(isASCII)
|
expectTrue(isASCII)
|
||||||
}
|
}
|
||||||
@@ -1916,16 +1932,20 @@ UTF16Decoder.test("measure") {
|
|||||||
do {
|
do {
|
||||||
// "€" == U+20AC.
|
// "€" == U+20AC.
|
||||||
var u8: [UTF8.CodeUnit] = [ 0xF0, 0xA4, 0xAD, 0xA2 ]
|
var u8: [UTF8.CodeUnit] = [ 0xF0, 0xA4, 0xAD, 0xA2 ]
|
||||||
let (count, isASCII) = UTF16.measure(
|
let (count, isASCII) = UTF16.transcodedLength(
|
||||||
UTF8.self, input: u8.makeIterator(), repairIllFormedSequences: false)!
|
of: u8.makeIterator(),
|
||||||
|
decodedAs: UTF8.self,
|
||||||
|
repairingIllFormedSequences: false)!
|
||||||
expectEqual(2, count)
|
expectEqual(2, count)
|
||||||
expectFalse(isASCII)
|
expectFalse(isASCII)
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let u16: [UTF16.CodeUnit] = [ 6, 7, 8, 9, 10, 11 ]
|
let u16: [UTF16.CodeUnit] = [ 6, 7, 8, 9, 10, 11 ]
|
||||||
let (count, isASCII) = UTF16.measure(
|
let (count, isASCII) = UTF16.transcodedLength(
|
||||||
UTF16.self, input: u16.makeIterator(), repairIllFormedSequences: false)!
|
of: u16.makeIterator(),
|
||||||
|
decodedAs: UTF16.self,
|
||||||
|
repairingIllFormedSequences: false)!
|
||||||
expectEqual(6, count)
|
expectEqual(6, count)
|
||||||
expectTrue(isASCII)
|
expectTrue(isASCII)
|
||||||
}
|
}
|
||||||
@@ -2095,7 +2115,12 @@ UnicodeAPIs.test("transcode/MutableArray") {
|
|||||||
var input: [UInt16] = [ 0x0041, 0x0042 ]
|
var input: [UInt16] = [ 0x0041, 0x0042 ]
|
||||||
var transcoded = [UInt16]()
|
var transcoded = [UInt16]()
|
||||||
let output: (UInt16) -> Void = { transcoded.append($0) }
|
let output: (UInt16) -> Void = { transcoded.append($0) }
|
||||||
transcode(UTF16.self, UTF16.self, input.makeIterator(), output, stoppingOnError: true)
|
transcode(
|
||||||
|
input.makeIterator(),
|
||||||
|
from: UTF16.self,
|
||||||
|
to: UTF16.self,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: output)
|
||||||
expectEqual(input, transcoded)
|
expectEqual(input, transcoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2103,7 +2128,12 @@ UnicodeAPIs.test("transcode/ReferenceTypedArray") {
|
|||||||
var input: [UInt16] = [ 0x0041, 0x0042 ]
|
var input: [UInt16] = [ 0x0041, 0x0042 ]
|
||||||
var transcoded = [UInt16]()
|
var transcoded = [UInt16]()
|
||||||
let output: (UInt16) -> Void = { transcoded.append($0) }
|
let output: (UInt16) -> Void = { transcoded.append($0) }
|
||||||
transcode(UTF16.self, UTF16.self, input.makeIterator(), output, stoppingOnError: true)
|
transcode(
|
||||||
|
input.makeIterator(),
|
||||||
|
from: UTF16.self,
|
||||||
|
to: UTF16.self,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: output)
|
||||||
expectEqual(input, transcoded)
|
expectEqual(input, transcoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2123,8 +2153,12 @@ class NonContiguousNSString : NSString {
|
|||||||
var encoded = [UInt16]()
|
var encoded = [UInt16]()
|
||||||
let output: (UInt16) -> Void = { encoded.append($0) }
|
let output: (UInt16) -> Void = { encoded.append($0) }
|
||||||
let iterator = utf8.makeIterator()
|
let iterator = utf8.makeIterator()
|
||||||
let hadError =
|
let hadError = transcode(
|
||||||
transcode(UTF8.self, UTF16.self, iterator, output, stoppingOnError: true)
|
iterator,
|
||||||
|
from: UTF8.self,
|
||||||
|
to: UTF16.self,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: output)
|
||||||
expectFalse(hadError)
|
expectFalse(hadError)
|
||||||
self.init(encoded)
|
self.init(encoded)
|
||||||
}
|
}
|
||||||
@@ -2138,8 +2172,12 @@ class NonContiguousNSString : NSString {
|
|||||||
var encoded = [UInt16]()
|
var encoded = [UInt16]()
|
||||||
let output: (UInt16) -> Void = { encoded.append($0) }
|
let output: (UInt16) -> Void = { encoded.append($0) }
|
||||||
let iterator = scalars.makeIterator()
|
let iterator = scalars.makeIterator()
|
||||||
let hadError =
|
let hadError = transcode(
|
||||||
transcode(UTF32.self, UTF16.self, iterator, output, stoppingOnError: true)
|
iterator,
|
||||||
|
from: UTF32.self,
|
||||||
|
to: UTF16.self,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: output)
|
||||||
expectFalse(hadError)
|
expectFalse(hadError)
|
||||||
self.init(encoded)
|
self.init(encoded)
|
||||||
}
|
}
|
||||||
@@ -2195,7 +2233,12 @@ StringCookedViews.test("UTF8ForContiguousUTF16") {
|
|||||||
let output: (UInt16) -> Void = { backingStorage.append($0) }
|
let output: (UInt16) -> Void = { backingStorage.append($0) }
|
||||||
|
|
||||||
var iterator = test.scalars.makeIterator()
|
var iterator = test.scalars.makeIterator()
|
||||||
transcode(UTF32.self, UTF16.self, iterator, output, stoppingOnError: false)
|
transcode(
|
||||||
|
iterator,
|
||||||
|
from: UTF32.self,
|
||||||
|
to: UTF16.self,
|
||||||
|
stoppingOnError: false,
|
||||||
|
sendingOutputTo: output)
|
||||||
|
|
||||||
backingStorage.withUnsafeBufferPointer {
|
backingStorage.withUnsafeBufferPointer {
|
||||||
(ptr) -> Void in
|
(ptr) -> Void in
|
||||||
@@ -2216,7 +2259,12 @@ StringCookedViews.test("UTF8ForContiguousUTF16") {
|
|||||||
let output: (UInt8) -> Void = { expected.append($0) }
|
let output: (UInt8) -> Void = { expected.append($0) }
|
||||||
var expectedScalars = test.scalarsHead + test.scalarsRepairedTail
|
var expectedScalars = test.scalarsHead + test.scalarsRepairedTail
|
||||||
var iterator = expectedScalars.makeIterator()
|
var iterator = expectedScalars.makeIterator()
|
||||||
transcode(UTF32.self, UTF8.self, iterator, output, stoppingOnError: false)
|
transcode(
|
||||||
|
iterator,
|
||||||
|
from: UTF32.self,
|
||||||
|
to: UTF8.self,
|
||||||
|
stoppingOnError: false,
|
||||||
|
sendingOutputTo: output)
|
||||||
|
|
||||||
checkUTF8View(expected, subject, test.loc.withCurrentLoc())
|
checkUTF8View(expected, subject, test.loc.withCurrentLoc())
|
||||||
}
|
}
|
||||||
@@ -2262,7 +2310,12 @@ StringCookedViews.test("UTF8ForNonContiguousUTF16") {
|
|||||||
let output: (UInt8) -> Void = { expected.append($0) }
|
let output: (UInt8) -> Void = { expected.append($0) }
|
||||||
var expectedScalars = test.scalarsHead + test.scalarsRepairedTail
|
var expectedScalars = test.scalarsHead + test.scalarsRepairedTail
|
||||||
var iterator = expectedScalars.makeIterator()
|
var iterator = expectedScalars.makeIterator()
|
||||||
transcode(UTF32.self, UTF8.self, iterator, output, stoppingOnError: false)
|
transcode(
|
||||||
|
iterator,
|
||||||
|
from: UTF32.self,
|
||||||
|
to: UTF8.self,
|
||||||
|
stoppingOnError: false,
|
||||||
|
sendingOutputTo: output)
|
||||||
|
|
||||||
var nss = NonContiguousNSString(test.encoded)
|
var nss = NonContiguousNSString(test.encoded)
|
||||||
verifyThatStringIsOpaqueForCoreFoundation(nss)
|
verifyThatStringIsOpaqueForCoreFoundation(nss)
|
||||||
@@ -2330,7 +2383,12 @@ StringCookedViews.test("UTF16") {
|
|||||||
let output: (UInt16) -> Void = { expected.append($0) }
|
let output: (UInt16) -> Void = { expected.append($0) }
|
||||||
var expectedScalars = test.scalars
|
var expectedScalars = test.scalars
|
||||||
var iterator = expectedScalars.makeIterator()
|
var iterator = expectedScalars.makeIterator()
|
||||||
transcode(UTF32.self, UTF16.self, iterator, output, stoppingOnError: false)
|
transcode(
|
||||||
|
iterator,
|
||||||
|
from: UTF32.self,
|
||||||
|
to: UTF16.self,
|
||||||
|
stoppingOnError: false,
|
||||||
|
sendingOutputTo: output)
|
||||||
|
|
||||||
var nss = NonContiguousNSString(test.scalars)
|
var nss = NonContiguousNSString(test.scalars)
|
||||||
checkUTF16View(expected, nss as String, test.loc.withCurrentLoc())
|
checkUTF16View(expected, nss as String, test.loc.withCurrentLoc())
|
||||||
@@ -2342,7 +2400,12 @@ StringCookedViews.test("UTF16") {
|
|||||||
let output: (UInt16) -> Void = { expected.append($0) }
|
let output: (UInt16) -> Void = { expected.append($0) }
|
||||||
var expectedScalars = test.scalarsHead + test.scalarsRepairedTail
|
var expectedScalars = test.scalarsHead + test.scalarsRepairedTail
|
||||||
var iterator = expectedScalars.makeIterator()
|
var iterator = expectedScalars.makeIterator()
|
||||||
transcode(UTF32.self, UTF16.self, iterator, output, stoppingOnError: false)
|
transcode(
|
||||||
|
iterator,
|
||||||
|
from: UTF32.self,
|
||||||
|
to: UTF16.self,
|
||||||
|
stoppingOnError: false,
|
||||||
|
sendingOutputTo: output)
|
||||||
|
|
||||||
checkUTF16View(expected, subject, test.loc.withCurrentLoc())
|
checkUTF16View(expected, subject, test.loc.withCurrentLoc())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,8 +95,12 @@ class NonContiguousNSString : NSString {
|
|||||||
var encoded: [UInt16] = []
|
var encoded: [UInt16] = []
|
||||||
var iter = scalars.makeIterator()
|
var iter = scalars.makeIterator()
|
||||||
let output: (UInt16) -> Void = { encoded.append($0) }
|
let output: (UInt16) -> Void = { encoded.append($0) }
|
||||||
let hadError =
|
let hadError = transcode(
|
||||||
transcode(UTF32.self, UTF16.self, iter, output, stoppingOnError: true)
|
iter,
|
||||||
|
from: UTF32.self,
|
||||||
|
to: UTF16.self,
|
||||||
|
stoppingOnError: true,
|
||||||
|
sendingOutputTo: output)
|
||||||
expectFalse(hadError)
|
expectFalse(hadError)
|
||||||
self.init(encoded)
|
self.init(encoded)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ class CodecTest<Codec : TestableUnicodeCodec> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
encodeIndex = encodeBuffer.startIndex
|
encodeIndex = encodeBuffer.startIndex
|
||||||
Codec.encode(scalar, output: encodeOutput)
|
Codec.encode(scalar, sendingOutputTo: encodeOutput)
|
||||||
expectEqual(
|
expectEqual(
|
||||||
nsEncoded, encodeBuffer[0..<encodeIndex],
|
nsEncoded, encodeBuffer[0..<encodeIndex],
|
||||||
"Decoding failed: \(asHex(nsEncoded)) => " +
|
"Decoding failed: \(asHex(nsEncoded)) => " +
|
||||||
|
|||||||
Reference in New Issue
Block a user