class Bundler::URI::RFC3986_Parser

:nodoc:

def convert_to_uri(uri)

def convert_to_uri(uri)
  if uri.is_a?(Bundler::URI::Generic)
    uri
  elsif uri = String.try_convert(uri)
    parse(uri)
  else
    raise ArgumentError,
      "bad argument (expected Bundler::URI object or Bundler::URI string)"
  end
end

def default_regexp # :nodoc:

:nodoc:
def default_regexp # :nodoc:
  {
    SCHEME: %r[\A#{SCHEME}\z]o,
    USERINFO: %r[\A#{USERINFO}\z]o,
    HOST: %r[\A#{HOST}\z]o,
    ABS_PATH: %r[\A/#{SEG}*+\z]o,
    REL_PATH: %r[\A(?!/)#{SEG}++\z]o,
    QUERY: %r[\A(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/?])*+\z],
    FRAGMENT: %r[\A#{FRAGMENT}\z]o,
    OPAQUE: %r[\A(?:[^/].*)?\z],
    PORT: /\A[\x09\x0a\x0c\x0d ]*+\d*[\x09\x0a\x0c\x0d ]*\z/,
  }
end

def initialize

def initialize
  @regexp = default_regexp.each_value(&:freeze).freeze
end

def inspect

def inspect
  @@to_s.bind_call(self)
end

def inspect

def inspect
  @@to_s.bind(self).call
end

def join(*uris) # :nodoc:

:nodoc:
def join(*uris) # :nodoc:
  uris[0] = convert_to_uri(uris[0])
  uris.inject :merge
end

def parse(uri) # :nodoc:

:nodoc:
def parse(uri) # :nodoc:
  Bundler::URI.for(*self.split(uri), self)
end

def split(uri) #:nodoc:

:nodoc:
def split(uri) #:nodoc:
  begin
    uri = uri.to_str
  rescue NoMethodError
    raise InvalidURIError, "bad Bundler::URI(is not Bundler::URI?): #{uri.inspect}"
  end
  uri.ascii_only? or
    raise InvalidURIError, "Bundler::URI must be ascii only #{uri.dump}"
  if m = RFC3986_URI.match(uri)
    query = m["query"]
    scheme = m["scheme"]
    opaque = m["path-rootless"]
    if opaque
      opaque << "?#{query}" if query
      [ scheme,
        nil, # userinfo
        nil, # host
        nil, # port
        nil, # registry
        nil, # path
        opaque,
        nil, # query
        m["fragment"]
      ]
    else # normal
      [ scheme,
        m["userinfo"],
        m["host"],
        m["port"],
        nil, # registry
        (m["path-abempty"] ||
         m["path-absolute"] ||
         m["path-empty"]),
        nil, # opaque
        query,
        m["fragment"]
      ]
    end
  elsif m = RFC3986_relative_ref.match(uri)
    [ nil, # scheme
      m["userinfo"],
      m["host"],
      m["port"],
      nil, # registry,
      (m["path-abempty"] ||
       m["path-absolute"] ||
       m["path-noscheme"] ||
       m["path-empty"]),
      nil, # opaque
      m["query"],
      m["fragment"]
    ]
  else
    raise InvalidURIError, "bad Bundler::URI(is not Bundler::URI?): #{uri.inspect}"
  end
end