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
| // | |
| // 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
| // | |
| // 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
| 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
| 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
| 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
| func testCSV() throws { | |
| let plainField = Prefix { $0 != .init(ascii: ",") && $0 != .init(ascii: "|") && $0 != .init(ascii: "\n") } | |
| let quotedField = Parse { | |
| "|".utf8 | |
| Many { | |
| OneOf { | |
| Parse { "||".utf8 }.map { Substring("").utf8 } | |
| Prefix { $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
| // example unit test: | |
| func testAscii() async throws { | |
| locate { | |
| "Celcius" | |
| "Farenheit" | |
| "Kelvin" | |
| "yes?" | |
| "no?" | |
| "yes;no;cancel" |
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
| /// A type that synchronizes progress of two tasks. | |
| /// | |
| /// After setup, two tasks should eventually call the `join` function. The | |
| /// first task will suspend until the second task arrives and calls `join` as | |
| /// well. Both tasks resume normally after that. | |
| public final actor TaskRendezvous: Sendable { | |
| private var completion: CheckedContinuation<Void, Error>? = nil | |
| /// Suspends until a second task calls `join()` on this instance. | |
| public func join() async throws { |
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
| // TaskMeeting | |
| // (c) 2022, Nikolai Ruhe | |
| /// A type that synchronizes progress of two tasks. | |
| public final actor TaskMeeting: Sendable { | |
| private var completion: CheckedContinuation<Void, Error>? = nil | |
| /// This method synchronizes two tasks so that both perform the closure at | |
| /// the same time. Both tasks need to call `rendezvous`. | |
| /// |