// Parses a connection string into a structure more easily consumed by the library.
768478
func parseConnSpec(connStr string) connSpec {
	var out connSpec
	out.Options = map[string]string{}

	partMatcher := regexp.MustCompile(`((.*):\/\/)?(([^\/?:]*)(:([^\/?:@]*))?@)?([^\/?]*)(\/([^\?]*))?(\?(.*))?`)
	hostMatcher := regexp.MustCompile(`([^;\,\:]+)(:([0-9]*))?(;\,)?`)
	kvMatcher := regexp.MustCompile(`([^=]*)=([^&?]*)[&?]?`)
	parts := partMatcher.FindStringSubmatch(connStr)

	if parts[2] != "" {
		out.Scheme = parts[2]
	}

	if parts[7] != "" {
		hosts := hostMatcher.FindAllStringSubmatch(parts[7], -1)
		for _, hostInfo := range hosts {
			port := 0
			if hostInfo[3] != "" {
				port, _ = strconv.Atoi(hostInfo[3])
			}

			out.Hosts = append(out.Hosts, connSpecAddr{
				Host: hostInfo[1],
				Port: uint16(port),
			})
		}
	}

	if parts[9] != "" {
		out.Bucket = parts[9]
	}

	if parts[11] != "" {
		kvs := kvMatcher.FindAllStringSubmatch(parts[11], -1)
		for _, kvInfo := range kvs {
			out.Options[kvInfo[1]] = kvInfo[2]
		}
	}

	return out
}
1251251
func DBConnectionString(name string) string {
	dbConnStr := os.Getenv("ABOT_DATABASE_URL")
	if dbConnStr == "" {
		dbConnStr = "host=127.0.0.1 user=postgres"
	}
	if len(dbConnStr) <= 11 || dbConnStr[:11] != "postgres://" {
		dbConnStr += " sslmode=disable dbname=" + name
		if strings.ToLower(os.Getenv("ABOT_ENV")) == "test" {
			dbConnStr += "_test"
		}
	}
	return dbConnStr
}
1277136
func parseLinkHeader(linkLines []string) (linkHeader, error) {
	var lH linkHeader
	// URL in link is enclosed in < >
	stringsToRemove := []string{"<", ">"}

	for _, linkLine := range linkLines {
		for _, linkItem := range strings.Split(linkLine, ",") {
			linkData := strings.Split(linkItem, ";")
			trimmedUrl := removeSubstringsFromString(strings.TrimSpace(linkData[0]), stringsToRemove)
			linkVal := linkData[1]
			switch {
			case strings.Contains(linkVal, "first"):
				lH.First = trimmedUrl
			case strings.Contains(linkVal, "last"):
				lH.Last = trimmedUrl
			case strings.Contains(linkVal, "next"):
				lH.Next = trimmedUrl
			case strings.Contains(linkVal, "prev"):
				lH.Prev = trimmedUrl
			}
		}
	}
	return lH, nil
}
1326434
func Parse(s string) (Reference, error) {
	matches := ReferenceRegexp.FindStringSubmatch(s)
	if matches == nil {
		if s == "" {
			return nil, ErrNameEmpty
		}
		if ReferenceRegexp.FindStringSubmatch(strings.ToLower(s)) != nil {
			return nil, ErrNameContainsUppercase
		}
		return nil, ErrReferenceInvalidFormat
	}

	if len(matches[1]) > NameTotalLengthMax {
		return nil, ErrNameTooLong
	}

	var repo repository

	nameMatch := anchoredNameRegexp.FindStringSubmatch(matches[1])
	if len(nameMatch) == 3 {
		repo.domain = nameMatch[1]
		repo.path = nameMatch[2]
	} else {
		repo.domain = ""
		repo.path = matches[1]
	}

	ref := reference{
		namedRepository: repo,
		tag:             matches[2],
	}
	if matches[3] != "" {
		var err error
		ref.digest, err = digest.Parse(matches[3])
		if err != nil {
			return nil, err
		}
	}

	r := getBestReferenceType(ref)
	if r == nil {
		return nil, ErrNameEmpty
	}

	return r, nil
}
80507
func (c *DriverConfig) ConnectionString(original string) string {
	if c.driver == nil {
		panic("DriverConfig must be registered before calling ConnectionString")
	}

	buf := make([]byte, 9)
	binary.BigEndian.PutUint64(buf[1:], uint64(c.id))
	buf = append(buf, original...)
	return string(buf)
}
218040
func ConnectionProblem(err error, message string, args ...interface{}) error {
	return WrapWithMessage(&ConnectionProblemError{
		Message: fmt.Sprintf(message, args...),
		Err:     err,
	}, message, args...)
}
47336
func Parse(in string) *Version {
	v := &Version{}

	sp := strings.Split(in, ".")
	if len(sp) != 3 {
		v.err = errors.Errorf("passed string is not following to semver: %s", in)
		return v
	}

	v.major(sp[0])
	v.minor(sp[1])
	v.patch(sp[2])

	return v
}
899825
func (parser *Parser) Parse(sql, charset, collation string) ([]ast.StmtNode, error) {
	if charset == "" {
		charset = mysql.DefaultCharset
	}
	if collation == "" {
		collation = mysql.DefaultCollationName
	}
	parser.charset = charset
	parser.collation = collation
	parser.src = sql
	parser.result = parser.result[:0]

	var l yyLexer
	parser.lexer.reset(sql)
	l = &parser.lexer
	yyParse(l, parser)

	if len(l.Errors()) != 0 {
		return nil, errors.Trace(l.Errors()[0])
	}
	for _, stmt := range parser.result {
		ast.SetFlag(stmt)
	}
	return parser.result, nil
}
1040632
func Parse(l string) ([]Link, error) {
	v := []byte(l)
	v = bytes.TrimSpace(v)
	if len(v) == 0 {
		return nil, nil
	}

	links := make([]Link, 0, 1)
	for len(v) > 0 {
		if v[0] != '<' {
			return nil, errors.New("link: does not start with <")
		}
		lend := bytes.IndexByte(v, '>')
		if lend == -1 {
			return nil, errors.New("link: does not contain ending >")
		}

		params := make(map[string]string)
		link := Link{URI: string(v[1:lend]), Params: params}
		links = append(links, link)

		// trim off parsed url
		v = v[lend+1:]
		if len(v) == 0 {
			break
		}
		v = bytes.TrimLeftFunc(v, unicode.IsSpace)

		for len(v) > 0 {
			if v[0] != ';' && v[0] != ',' {
				return nil, errors.New(`link: expected ";" or "'", got "` + string(v[0:1]) + `"`)
			}
			var next bool
			if v[0] == ',' {
				next = true
			}
			v = bytes.TrimLeftFunc(v[1:], unicode.IsSpace)
			if next || len(v) == 0 {
				break
			}
			var key, value []byte
			key, value, v = consumeParam(v)
			if key == nil || value == nil {
				return nil, errors.New("link: malformed param")
			}
			if k := string(key); k == "rel" {
				if links[len(links)-1].Rel == "" {
					links[len(links)-1].Rel = string(value)
				}
			} else {
				params[k] = string(value)
			}
			v = bytes.TrimLeftFunc(v, unicode.IsSpace)
		}
	}

	return links, nil
}
572444
func newParsedConnection(namespace, suffix, hubName, keyName, key string) *ParsedConn {
	return &ParsedConn{
		Host:      "amqps://" + namespace + "." + suffix,
		Suffix:    suffix,
		Namespace: namespace,
		KeyName:   keyName,
		Key:       key,
		HubName:   hubName,
	}
}
106997
func (parser *myParser) Parse(s string) error {
	typ := reflect.TypeOf(parser.ptr)
	val := reflect.ValueOf(parser.ptr)
	if typ.Kind() == reflect.Ptr {
		kind := reflect.Indirect(val).Type().Kind()
		if kind == reflect.Struct {
			typElem, valElem := typ.Elem(), val.Elem()
			numField := valElem.NumField()
			for i := 0; i < numField; i++ {
				_, valField := typElem.Field(i), valElem.Field(i)
				if valField.Kind() == reflect.Int &&
					valField.CanSet() {
					valField.SetInt(2)
				}
				if valField.Kind() == reflect.String &&
					valField.CanSet() {
					valField.SetString("B")
				}
			}
		}
	}
	return nil
}
787113
func (t *tree) parse() (_ Node, err error) {
	defer func() {
		if p := recover(); p != nil {
			err = fmt.Errorf("parse error: %v", p)
		}
	}()
	return t.O(0), err
}
58245
func (m *GenericParser) Parse(data interface{}) (e *Entity, err error) {
	val := reflect.ValueOf(data)
	// dereference pointers, and get concrete values from interfaces
	val = deref(val)
	// Map and Struct are the only valid Kinds at the top level.
	switch val.Kind() {
	case reflect.Map:
		e, err = m.parseMap(val)
	case reflect.Struct:
		e, err = m.parseStruct(val)
	default:
		e, err = nil, errors.Errorf("unsupported kind, '%v' in GenericParser: %v", val.Kind(), data)
	}
	if err != nil {
		return e, err
	}
	var subj string
	if !m.SubjectAll {
		if m.EntitySubjecter != nil {
			subj, err = m.EntitySubjecter.Subject(e)
		} else {
			subj, err = m.Subjecter.Subject(data)
		}
		e.Subject = IRI(subj)
	}
	return e, err
}
1148136
func ParseString(b []byte) (string, error) {
	var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings
	if bU, err := Unescape(b, stackbuf[:]); err != nil {
		return "", MalformedValueError
	} else {
		return string(bU), nil
	}
}
1067051
func (self *ConnectionString) Dataset() string {
	dataset := self.URI.Path
	dataset = strings.TrimPrefix(dataset, `/`)
	dataset = strings.TrimSuffix(dataset, `/`)
	return dataset
}
25746
func Parse(s string) (*ACL, error) {
	cs := C.CString(s)
	cacl, _ := C.acl_from_text(cs)
	if cacl == nil {
		return nil, fmt.Errorf("unable to parse ACL")
	}
	return &ACL{cacl}, nil
}
613504
func BuildConnectionStringWithChroot(nodes []string, chroot string) string {
	return fmt.Sprintf("%s%s", strings.Join(nodes, ","), chroot)
}