Sha256: 220d43341f8800f6ecfffd36ab34701f3efd71420d18f0c3f3f23561a1551395
Contents?: true
Size: 942 Bytes
Versions: 59
Compression:
Stored size: 942 Bytes
Contents
#if os(Linux) import Glibc #elseif os(OSX) import Darwin #endif extension Int { init(_ value: Octal) { self = value.toDecimal } } struct Octal { private var stringValue = "" fileprivate var toDecimal: Int = 0 private func isValidOctal() -> Bool { return (Int(stringValue) ?? -1) > -1 ? true : false } private func oct2int(_ input: String) -> Int { let orderedInput = Array(input.characters.reversed()) var tempInt: Int = 0 for (inx, each) in orderedInput.enumerated() { let tempCharInt = Int("\(each)") ?? 0 if tempCharInt > 7 {return 0} let tempOctPower = Int(pow(Double(8), Double(inx))) tempInt += tempOctPower * tempCharInt } return tempInt } init( _ sv: String) { self.stringValue = sv if isValidOctal() { self.toDecimal = oct2int(sv) } } }
Version data entries
59 entries across 59 versions & 1 rubygems