mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Generate Unicode data for Scalar Binary Properties * Use native scalar binary property lookup * Add _BinaryProperties to Scalar Properties narrow access control * Upgrade the notice to a warning in UnicodeScalarProperties
44 lines
1.2 KiB
Swift
44 lines
1.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2021 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Given a collection, format it into a string within 80 columns and fitting as
|
|
// many elements in a row as possible.
|
|
public func formatCollection<C: Collection>(
|
|
_ c: C,
|
|
into result: inout String,
|
|
using handler: (C.Element) -> String
|
|
) {
|
|
// Our row length always starts at 2 for the initial indentation.
|
|
var rowLength = 2
|
|
|
|
for element in c {
|
|
let string = handler(element)
|
|
|
|
if rowLength == 2 {
|
|
result += " "
|
|
}
|
|
|
|
if rowLength + string.count + 1 > 100 {
|
|
result += "\n "
|
|
|
|
rowLength = 2
|
|
} else {
|
|
result += rowLength == 2 ? "" : " "
|
|
}
|
|
|
|
result += "\(string),"
|
|
|
|
// string.count + , + space
|
|
rowLength += string.count + 1 + 1
|
|
}
|
|
}
|