               )
             }
             return AbsolutePath(location).pathString
-        } else if TSCUtility.URL.scheme(dependencyLocation) == nil {
+        } else if parseScheme(dependencyLocation) == nil {
             // If the dependency URL is not remote, try to "fix" it.
             // If the URL has no scheme, we treat it as a path (either absolute or relative to the base URL).
             return AbsolutePath(dependencyLocation, relativeTo: packagePath).pathString

import Foundation
import PackageModel
import TSCBasic

import struct TSCUtility.URL

fileprivate typealias URL = Foundation.URL

enum ManifestJSONParser {
    private static let filePrefix = "file://"

        )
    }

    /// Parses the URL type of a git repository
    /// e.g. https://github.com/apple/swift returns "https"
    /// e.g. git@github.com:apple/swift returns "git"
    ///
    /// This is *not* a generic URI scheme parser!
    private static func parseScheme(_ location: String) -> String? {
        func prefixOfSplitBy(_ delimiter: String) -> String? {
            let (head, tail) = location.spm_split(around: delimiter)
            if tail == nil {
                //not found
                return nil
            } else {
                //found, return head
                //lowercase the "scheme", as specified by the URI RFC (just in case)
                return head.lowercased()
            }
        }

        for delim in ["://", "@"] {
            if let found = prefixOfSplitBy(delim), !found.contains("/") {
                return found
            }
        }

        return nil
    }

    /// Looks for Xcode-style build setting macros "$()".
    private static let invalidValueRegex = try! RegEx(pattern: #"(\$\(.*?\))"#)
}
