Files
swift-nio-imap/Sources/NIOIMAPCore/Grammar/UID/UIDSet.swift
T
David Evans b1a1d7350c Documentation PR part 6 (#387)
* Document UseAttribute

* Document URLRumpMechanism

* Document URLFetchData

* Document UAuthMechanism

* Document StoreModifier

* Document SortData

* Document SequenceMatchData

* Document QResyncParameter

* Document SelectParameter

* Document SectionSpecifier

* Document SectionSpecifier.Part

* Document SectionSpecifier.Kind

* Document ResponseEncodingOptions

* Document ResponseEncodeBuffer

* Document EncodeBuffer

* Document EncodeBuffer.Chunk

* Document EncodeBuffer more.

* Document CommandEncodeBuffer

* Document ParserError

* Document ResponseParser

* Document CommandParser

* Document SynchronisingLiteralParser

* Remove public where it isn't needed

* Document write CommandStream

* Document write TaggedCommand

* Remove public from write functions

* Document FetchAttribute

* Document top-level Capability

* Documents Capability subtypes

* Document FullDateTime

* Document FullDate

* Document FullTime

* Document ContinuationRequest

* Document ListSelectOptions

* Document ResponseOrContinuationRequest

* Document Response

* Document FetchResponse

* Document StreamingKind

* Document ResponseText

* Document ResponseTextCode

* Document TaggedResponse

* Document TaggedResponseState

* Remove docs

* Document UntaggedStatus

* Document ScopeOption

* Document ReturnOption

* Document IServer

* Document InitialClientResponse

* Document AttributeFlag

* Document UIDValidity

* Document UIDSet

* Document UID

* Document EncodedAuthenticationType

* Document EncodedMailbox

* Document EncodedSearch

* Document EncodedSection

* Document EncodedURLAuth

* Document EncodedUser

* Document ResponseCodeAppend

* Document ResponsePayload

* Document SequenceNumber

* Document OptionValueComp

* Document QuotaLimit

* Document QuotaResource

* Document OptionVendorTag

* Document IPartial and remove IPartialOnly

* Document QuotaRoot

* Document ESearchResponse

* Document SearchCorrelator

* Document Address

* Document UIDRange

* Document IUID

* Document SearchModificationSequence

* Document SearchModificationSequenceExtension

* Document SearchReturnData

* Document SearchReturnDataExtension

* Document SearchReturnOption

* Document SearchReturnOptionExtension

* Document SequenceRange

* Document SequenceRangeSet

* Fix compile

* Document SequenceSet

* Document ParameterValue

* Define TaggedExtension

* Document AuthIMAPURL

* Document AuthIMAPURLFull

* Document AuthIMAPURLRump

* Document ChangedSinceModifier

* Document UnchangedSinceModifier

* Document CreateParameter

* Document EntryValue

* Document Expire

* Document FetchModifier

* Document FetchModificationResponse

* Document IAbsolutePath

* Document IAuth

* Document ICommand

* Document IMailboxReference

* Document MetadataValue

* Document IMAPURL

* Document MetadataOption

* Document MetadataResponse

* Document RelativeIMAPURL

* Document INetworkPath

* Document MechanismBase64

* Document IMessageList

* Document IMessageOrPartial

* Document IMessagePart

* Document IPathQuery

* Document ISection

* Document IRelativePath

* Document IUAVerifier

* Document IURLAuthRump

* Document IURLAuthRump

* Document IUserInfo

* Fix missing documentation

* Document CommandEncoder

* Fix sanity

* Update CommandDecoder.swift

* PR reviews
2020-12-11 17:14:37 +00:00

90 lines
2.7 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import struct NIO.ByteBuffer
/// A set contains an array of `UIDRange` to represent a (potentially large) collection of messages.
public struct UIDSet: Hashable {
/// A non-empty array of UID ranges.
public var ranges: [UIDRange]
/// Creates a new `UIDset`.
/// - parameter ranges: A non-empty array of ranges.
/// - returns: `nil` if `ranges` is empty, otherwise a new `UIDSet`.
public init?(_ ranges: [UIDRange]) {
guard !ranges.isEmpty else { return nil }
self.ranges = ranges
}
}
extension UIDSet {
/// Creates a `UIDSet` from a closed range.
/// - parameter range: The closed range to use.
public init(_ range: ClosedRange<UID>) {
self.init(UIDRange(range))
}
/// Creates a `UIDSet` from a partial range.
/// - parameter range: The partial range to use.
public init(_ range: PartialRangeThrough<UID>) {
self.init(UIDRange(range))
}
/// Creates a `UIDSet` from a partial range.
/// - parameter range: The partial range to use.
public init(_ range: PartialRangeFrom<UID>) {
self.init(UIDRange(range))
}
/// Creates a set from a single range.
/// - parameter range: The `UIDRange` to construct a set from.
public init(_ range: UIDRange) {
self.ranges = [range]
}
}
// MARK: - CustomStringConvertible
extension UIDSet: CustomStringConvertible {
/// Creates a human-readable text representation of the set by joined ranges with a comma.
public var description: String {
ranges.map { "\($0)" }.joined(separator: ",")
}
}
// MARK: - Array Literal
extension UIDSet: ExpressibleByArrayLiteral {
/// Creates a new UIDSet from a literal array of ranges.
/// - parameter arrayLiteral: The elements to use, assumed to be non-empty.
public init(arrayLiteral elements: UIDRange...) {
self.init(elements)!
}
}
extension UIDSet {
/// A set that contains a single range, that in turn contains all messages.
public static let all = UIDSet(UIDRange.all)
}
// MARK: - Encoding
extension EncodeBuffer {
@discardableResult mutating func writeUIDSet(_ set: UIDSet) -> Int {
self.writeArray(set.ranges, separator: ",", parenthesis: false) { (element, self) in
self.writeUIDRange(element)
}
}
}