package multiaddr

import (
	

	
)

// Split returns the sub-address portions of a multiaddr.
func ( Multiaddr) []Component {
	return 
}

// Join returns a combination of addresses.
// Note: This copies all the components from the input Multiaddrs. Depending on
// your use case, you may prefer to use `append(leftMA, rightMA...)` instead.
func ( ...Multiaddrer) Multiaddr {
	 := make([]Multiaddr, len())
	for ,  := range  {
		if  == nil {
			continue
		}
		[] = .Multiaddr()
	}
	 := 0
	for ,  := range  {
		 += len()
	}
	if  == 0 {
		return nil
	}

	 := make([]Component, 0, )
	for ,  := range  {
		 = append(, ...)
	}
	return 
}

// Cast re-casts a byte slice as a multiaddr. will panic if it fails to parse.
func ( []byte) Multiaddr {
	,  := NewMultiaddrBytes()
	if  != nil {
		panic(fmt.Errorf("multiaddr failed to parse: %s", ))
	}
	return 
}

// StringCast like Cast, but parses a string. Will also panic if it fails to parse.
func ( string) Multiaddr {
	,  := NewMultiaddr()
	if  != nil {
		panic(fmt.Errorf("multiaddr failed to parse: %s", ))
	}
	return 
}

// SplitFirst returns the first component and the rest of the multiaddr.
func ( Multiaddr) (*Component, Multiaddr) {
	if len() == 0 {
		return nil, nil
	}
	if len() == 1 {
		return &[0], nil
	}
	// defensive copy. Users can avoid by doing the split themselves.
	 := [0]
	return &, [1:].copy()
}

// SplitLast returns the rest of the multiaddr and the last component.
func ( Multiaddr) (Multiaddr, *Component) {
	if len() == 0 {
		return nil, nil
	}
	if len() == 1 {
		// We want to explicitly return a nil slice if the prefix is now empty.
		return nil, &[0]
	}
	// defensive copy. Users can avoid by doing the split themselves.
	 := [len()-1]
	return [:len()-1].copy(), &
}

// SplitFunc splits the multiaddr when the callback first returns true. The
// component on which the callback first returns will be included in the
// *second* multiaddr.
func ( Multiaddr,  func(Component) bool) (Multiaddr, Multiaddr) {
	if len() == 0 {
		return nil, nil
	}

	 := len()
	for ,  := range  {
		if () {
			 = 
			break
		}
	}
	,  := [:], [:]
	if len() == 0 {
		 = nil
	}
	if len() == 0 {
		 = nil
	}
	// defensive copy. Users can avoid by doing the split themselves.
	return .copy(), .copy()
}

// ForEach walks over the multiaddr, component by component.
//
// This function iterates over components.
// Return true to continue iteration, false to stop.
//
// Prefer a standard for range loop instead
// e.g. `for _, c := range m { ... }`
func ( Multiaddr,  func( Component) bool) {
	for ,  := range  {
		if !() {
			return
		}
	}
}

type componentList []Component

func ( componentList) ( int) meg.Matchable {
	return &[]
}

func ( componentList) () int {
	return len()
}
func ( Multiaddr) ( ...meg.Pattern) (bool, error) {
	 := meg.PatternToMatcher(...)
	return meg.Match(, componentList())
}