         }
         return sign * value
     }
-} // swiftlint:disable:this file_length
+}
+
+#if swift(>=4.0)
+    fileprivate extension Substring {
+    #if os(Linux)
+        func hasPrefix(_ prefix: String) -> Bool {
+            return String(self).hasPrefix(prefix)
+        }
+
+        func components(separatedBy separator: String) -> [String] {
+            return String(self).components(separatedBy: separator)
+        }
+    #endif
+
+        func sexagesimal<T>() -> T where T: SexagesimalConvertible {
+            assert(contains(":"))
+            var scalar = self
+
+            var sign: T = 1
+            if scalar.hasPrefix("-") {
+                sign = -1
+                scalar = scalar.substring(from: 1)
+            } else if scalar.hasPrefix("+") {
+                scalar = scalar.substring(from: 1)
+            }
+            let digits = scalar.components(separatedBy: ":").flatMap({ T($0) }).reversed()
+            var base: T = 1
+            var value: T = 0
+            digits.forEach {
+                value += $0 * base
+                base *= 60
+            }
+            return sign * value
+        }
+
+        func substring(from offset: Int) -> Substring {
+            if offset == 0 { return self }
+            let index = self.index(startIndex, offsetBy: offset)
+            return self[index...]
+        }
+    }
+#endif

        var sign: T = 1
        if scalar.hasPrefix("-") {
            sign = -1
#if swift(>=4.0)
            scalar = String(scalar[scalar.index(after: scalar.startIndex)...])
#else
            scalar = scalar.substring(from: scalar.index(after: scalar.startIndex))
#endif
        } else if scalar.hasPrefix("+") {
#if swift(>=4.0)
            scalar = String(scalar[scalar.index(after: scalar.startIndex)...])
#else
            scalar = scalar.substring(from: scalar.index(after: scalar.startIndex))
#endif
        }
        let digits = scalar.components(separatedBy: ":").flatMap({ T($0) }).reversed()
        var base: T = 1

extension Int: ScalarConstructible {
    public static func construct(from node: Node) -> Int? {
        assert(node.isScalar) // swiftlint:disable:next force_unwrapping
        var scalarWithSign = node.scalar!.string
        scalarWithSign = scalarWithSign.replacingOccurrences(of: "_", with: "")
        if scalarWithSign == "0" {
            return 0
        }
        let sign = scalarWithSign.hasPrefix("-") ? -1 : 1

        let scalar = sign == -1 || scalarWithSign.hasPrefix("+") ?
            scalarWithSign.substring(from: 1) : scalarWithSign.substring(from: 0)
        if scalar.hasPrefix("0x") {
            let hexadecimal = scalar.substring(from: 2)
            return Int(hexadecimal, radix: 16).map { $0 * sign }
        }
        if scalar.hasPrefix("0b") {
            let octal = scalar.substring(from: 2)
            return Int(octal, radix: 2).map { $0 * sign }
        }
        if scalar.hasPrefix("0o") {
            let octal = scalar.substring(from: 2)
            return Int(octal, radix: 8).map { $0 * sign }
        }
        if scalar.hasPrefix("0") {
            let octal = scalar.substring(from: 1)
            return Int(octal, radix: 8).map { $0 * sign }
        }
        if scalar.contains(":") {
            return Int(sexagesimal: scalar) * sign
        }
        return Int(scalar).map { $0 * sign }
    }
}

