added iOS source code
[wl-app.git] / iOS / Pods / OAuthSwift / Sources / Collection+OAuthSwift.swift
1 //
2 //  Collection+OAuthSwift.swift
3 //  OAuthSwift
4 //
5 //  Created by phimage on 02/10/16.
6 //  Copyright © 2016 Dongri Jin. All rights reserved.
7 //
8
9 import Foundation
10
11 extension Collection where Self.Iterator.Element == UInt8, Self.Index == Int {
12
13     var toUInt32: UInt32 {
14         assert(self.count > 3)
15         // XXX optimize do the job only for the first one...
16         return toUInt32Array()[0]
17     }
18
19     func toUInt32Array() -> [UInt32] {
20         var result = [UInt32]()
21         result.reserveCapacity(16)
22         for idx in stride(from: self.startIndex, to: self.endIndex, by: MemoryLayout<UInt32>.size) {
23             var val: UInt32 = 0
24             val |= self.count > 3 ? UInt32(self[idx.advanced(by: 3)]) << 24 : 0
25             val |= self.count > 2 ? UInt32(self[idx.advanced(by: 2)]) << 16 : 0
26             val |= self.count > 1 ? UInt32(self[idx.advanced(by: 1)]) << 8  : 0
27             //swiftlint:disable:next empty_count
28             val |= self.count > 0 ? UInt32(self[idx]) : 0
29             result.append(val)
30         }
31
32         return result
33     }
34 }