     ///
     /// - SeeAlso: `func urlQueryEncode() -> String`
     /// - Returns: Encoded string
-    func formUrlencode() -> String {
-        return addingPercentEncoding(withAllowedCharacters: HTTPData.formUrlencodedAllowedCharacters)?.replacingOccurrences(of: " ", with: "+") ?? ""
+    public func formUrlencode() -> String {
+        #if os(Linux)
+        let encoded = _addingPercentEncoding(withAllowedCharacters: HTTPData.formUrlencodedAllowedCharacters)
+        #else
+        let encoded = addingPercentEncoding(withAllowedCharacters: HTTPData.formUrlencodedAllowedCharacters)
+        #endif
+        return encoded?.replacingOccurrences(of: " ", with: "+") ?? ""
     }
     
     /// Percent-encodes everything except alphanumerics


extension String {
    struct HTTPData {
        static let formUrlencodedAllowedCharacters: CharacterSet = {
            var cs = CharacterSet.alphanumerics
            cs.insert(charactersIn: "-._* ")
            return cs
        }()
        
        static let urlQueryAllowedCharacters: CharacterSet = {
            var cs = CharacterSet.alphanumerics
			cs.insert(charactersIn: "-._~")
            return cs
        }()
    }

    ///
    /// - Returns: Encoded string
    /// - SeeAlso: `func formUrlencode() -> String`
    public func urlQueryEncode() -> String {
        #if os(Linux)
        return _addingPercentEncoding(withAllowedCharacters: HTTPData.urlQueryAllowedCharacters) ?? ""
        #else
		return addingPercentEncoding(withAllowedCharacters: HTTPData.urlQueryAllowedCharacters) ?? ""
        #endif
    }
    
    private func _addingPercentEncoding(withAllowedCharacters allowedCharacters: CharacterSet) -> String? {
        // Workaround broken addingPercentEncoding()
        var result: [CChar] = []
        for byte in utf8 {
            let scalar = UnicodeScalar(byte)
            if allowedCharacters.contains(scalar) {
                result.append(CChar(bitPattern: byte))
            } else {
                result.append(37) // "%"
                result.append(HTTPData.hexDigits[Int((byte & 0xf0) >> 4)])
                result.append(HTTPData.hexDigits[Int(byte & 0x0f)])
            }
        }
        result.append(0)
        let encoded = String(cString: result, encoding: .utf8)
        return encoded
    }
}
