This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testQuotedField() throws { | |
let quotedField = Parse { | |
"|".utf8 | |
Many(into: "") { result, element in | |
result += String(element)! | |
} element: { | |
OneOf { | |
Parse { "||".utf8 }.map { Substring("|").utf8 } | |
Prefix(1...) { $0 != .init(ascii: "|") } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension AsyncSequence { | |
/// Returns another `AsyncSequence` that fetches elements in the background | |
/// from the base sequence and buffers them for faster access. | |
public func buffer(limit: Int = 1) -> AsyncBuffer<Self> { | |
.init(self, limit: limit) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// A JSONValue is a generic DOM representation of decoded JSON. | |
enum JSONValue { | |
case null | |
case boolean(Bool) | |
case number(Double) | |
case string(String) | |
case array(JSONArray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Request.swift | |
// TLS-Test | |
// | |
// Created by Nikolai Ruhe on 12.10.18. | |
// Copyright © 2018 Nikolai Ruhe. All rights reserved. | |
// | |
import Foundation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Copyright (c) 2016, 2018 Nikolai Ruhe. All rights reserved. | |
// | |
import Foundation | |
public extension FileManager { | |
/// Calculate the allocated size of a directory and all its contents on the volume. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class NRLabel : UILabel { | |
var textInsets: UIEdgeInsets = UIEdgeInsetsZero { | |
didSet { invalidateIntrinsicContentSize() } | |
} | |
override func textRectForBounds(bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect { | |
var rect = textInsets.apply(bounds) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class NRLabel : UILabel { | |
var textInsets = UIEdgeInsets.zero { | |
didSet { invalidateIntrinsicContentSize() } | |
} | |
override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect { | |
let insetRect = UIEdgeInsetsInsetRect(bounds, textInsets) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NRLabel : UILabel | |
@property (nonatomic) UIEdgeInsets textInsets; | |
@end | |
@implementation NRLabel | |
- (void)setTextInsets:(UIEdgeInsets)textInsets | |
{ | |
_textInsets = textInsets; | |
[self invalidateIntrinsicContentSize]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class NRLabel : UILabel { | |
var textInsets: UIEdgeInsets = UIEdgeInsetsZero | |
override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect { | |
let insetRect = UIEdgeInsetsInsetRect(bounds, textInsets) | |
let textRect = super.textRect(forBounds: insetRect, limitedToNumberOfLines: numberOfLines) | |
let invertedInsets = UIEdgeInsets(top: -textInsets.top, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CBUUID { | |
func representativeString() -> String { | |
let data = self.data | |
let buffer = UnsafeBufferPointer<UInt8>(start: UnsafePointer(data.bytes), count: data.length) | |
let hex: (UInt8) -> String = { ($0 <= 9 ? "0" : "") + String($0, radix: 16, uppercase: true) } | |
let dashInserter: (Int) -> String = { [3, 5, 7, 9].contains($0) ? "-" : "" } | |
return buffer.map(hex) | |
.enumerate() |