Skip to content

Commit

Permalink
Formatting and updated file headers
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Jul 25, 2021
1 parent 421c58b commit 0824165
Show file tree
Hide file tree
Showing 34 changed files with 3,385 additions and 3,533 deletions.
50 changes: 25 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
import PackageDescription

let package = Package(
name: "SwiftRadix",
platforms: [.macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v2)],
products: [
.library(
name: "SwiftRadix",
targets: ["SwiftRadix"])
],
dependencies: [
// none
],
targets: [
.target(
name: "SwiftRadix",
dependencies: []),
.testTarget(
name: "SwiftRadixTests",
dependencies: ["SwiftRadix"])
]
name: "SwiftRadix",
platforms: [.macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v2)],
products: [
.library(
name: "SwiftRadix",
targets: ["SwiftRadix"])
],
dependencies: [
// none
],
targets: [
.target(
name: "SwiftRadix",
dependencies: []),
.testTarget(
name: "SwiftRadixTests",
dependencies: ["SwiftRadix"])
]
)
136 changes: 65 additions & 71 deletions Sources/SwiftRadix/Radix/Binary/Binary Type Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,93 +1,87 @@
//
// Binary Type Extensions.swift
// SwiftRadix
//
// Created by Steffan Andrews on 2020-09-13.
// MIT License
// https://github.com/orchetect/SwiftRadix
// SwiftRadix • https://github.com/orchetect/SwiftRadix
//

import Foundation

// MARK: - Constructors

extension BinaryInteger {
/// Returns a new `Radix<T>` base-2 struct from an integer, preserving the integer type.
@inline(__always) public var binary: Radix<Self> {
Radix(self, base: 2)
}
/// Returns a new `Radix<T>` base-2 struct from an integer, preserving the integer type.
@inline(__always) public var binary: Radix<Self> {
Radix(self, base: 2)
}
}

extension String {

/// Returns a new `Radix<Int>?` base-2 struct from a binary string.
@inlinable public var binary: Radix<Int>? {

Radix(self, base: 2)

}

/// Returns a new `Radix<T>?` base-2 struct from a binary string.
///
/// Example usage:
///
/// ```
/// "1010".binary(as: Int16.self)
/// ```
@inlinable public func binary<T: BinaryInteger>(as type: T.Type) -> Radix<T>? {

Radix<T>(self, base: 2)

}


/// Returns a new `Radix<Int>?` base-2 struct from a binary string.
@inlinable public var binary: Radix<Int>? {

Radix(self, base: 2)

}

/// Returns a new `Radix<T>?` base-2 struct from a binary string.
///
/// Example usage:
///
/// "1010".binary(as: Int16.self)
///
@inlinable public func binary<T: BinaryInteger>(as type: T.Type) -> Radix<T>? {

Radix<T>(self, base: 2)

}

}

extension Array where Element == String {

/// Returns an array of `Radix<Int>?` base-2 structs constructed from an array of binary strings.
public var binary: [Radix<Int>?] {

self.map { Radix<Int>($0, base: 2) }

}

/// Returns an array of `Radix<T>?` base-2 structs constructed from an array of binary strings.
///
/// Example usage:
///
/// ```
/// ["1010", "1111"].binary(as: Int16.self)
/// ```
public func binary<T: BinaryInteger>(as type: T.Type) -> [Radix<T>?] {

self.map { Radix<T>($0, base: 2) }

}


/// Returns an array of `Radix<Int>?` base-2 structs constructed from an array of binary strings.
public var binary: [Radix<Int>?] {

self.map { Radix<Int>($0, base: 2) }

}

/// Returns an array of `Radix<T>?` base-2 structs constructed from an array of binary strings.
///
/// Example usage:
///
/// ["1010", "1111"].binary(as: Int16.self)
///
public func binary<T: BinaryInteger>(as type: T.Type) -> [Radix<T>?] {

self.map { Radix<T>($0, base: 2) }

}

}

extension Collection where Element: BinaryInteger {
/// Returns an array of `Radix<T>` base-2 structs built from an integer array, preserving the integer type.
@inlinable public var binary: [Radix<Element>] {
self.map { Radix($0, base: 2) }
}
/// Returns an array of `Radix<T>` base-2 structs built from an integer array, preserving the integer type.
@inlinable public var binary: [Radix<Element>] {
self.map { Radix($0, base: 2) }
}
}

extension Data {
/// Returns an array of `Radix<UInt8>` base-2 structs built from Data bytes.
public var binary: [Radix<UInt8>] {
self.map { Radix($0, base: 2) }
}
/// Returns an array of `Radix<UInt8>` base-2 structs built from `Data` bytes.
public var binary: [Radix<UInt8>] {
self.map { Radix($0, base: 2) }
}
}
29 changes: 12 additions & 17 deletions Sources/SwiftRadix/Radix/Binary/Binary.swift
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
//
// Binary.swift
// SwiftRadix
//
// Created by Steffan Andrews on 2020-09-13.
// MIT License
// https://github.com/orchetect/SwiftRadix
// SwiftRadix • https://github.com/orchetect/SwiftRadix
//

import Foundation

/// Convenience constructor for `Radix<T>` with a radix of 2 (binary).
@inlinable public func Binary<T: BinaryInteger>(_ number: T) -> Radix<T> {
Radix<T>(number, base: 2)
Radix<T>(number, base: 2)
}

/// Convenience constructor for `Radix<Int>` with a radix of 2 (binary).
@inlinable public func Binary(_ string: String) -> Radix<Int>? {

Radix<Int>(string, base: 2)

Radix<Int>(string, base: 2)
}

/// Convenience constructor for `Radix<T>` with a radix of 2 (binary).
///
/// Example usage:
///
/// ```
/// Binary("1010", as: Int16.self)
/// ```
/// Binary("1010", as: Int16.self)
///
@inlinable public func Binary<T: BinaryInteger>(_ string: String, as type: T.Type) -> Radix<T>? {
Radix<T>(string, base: 2)
Radix<T>(string, base: 2)
}
Loading

0 comments on commit 0824165

Please sign in to comment.