// NewKeyFromString returns a new extended key instance from a base58-encoded
// extended key.
760101
func NewKeyFromString(key string) (*ExtendedKey, error) {
	// The base58-decoded extended key must consist of a serialized payload
	// plus an additional 4 bytes for the checksum.
	decoded := base58.Decode(key)
	if len(decoded) != serializedKeyLen+4 {
		return nil, ErrInvalidKeyLen
	}

	// The serialized format is:
	//   version (4) || depth (1) || parent fingerprint (4)) ||
	//   child num (4) || chain code (32) || key data (33) || checksum (4)

	// Split the payload and checksum up and ensure the checksum matches.
	payload := decoded[:len(decoded)-4]
	checkSum := decoded[len(decoded)-4:]
	expectedCheckSum := chainhash.DoubleHashB(payload)[:4]
	if !bytes.Equal(checkSum, expectedCheckSum) {
		return nil, ErrBadChecksum
	}

	// Deserialize each of the payload fields.
	version := payload[:4]
	depth := payload[4:5][0]
	parentFP := payload[5:9]
	childNum := binary.BigEndian.Uint32(payload[9:13])
	chainCode := payload[13:45]
	keyData := payload[45:78]

	// The key data is a private key if it starts with 0x00.  Serialized
	// compressed pubkeys either start with 0x02 or 0x03.
	isPrivate := keyData[0] == 0x00
	if isPrivate {
		// Ensure the private key is valid.  It must be within the range
		// of the order of the secp256k1 curve and not be 0.
		keyData = keyData[1:]
		keyNum := new(big.Int).SetBytes(keyData)
		if keyNum.Cmp(btcec.S256().N) >= 0 || keyNum.Sign() == 0 {
			return nil, ErrUnusableSeed
		}
	} else {
		// Ensure the public key parses correctly and is actually on the
		// secp256k1 curve.
		_, err := btcec.ParsePubKey(keyData, btcec.S256())
		if err != nil {
			return nil, err
		}
	}

	return NewExtendedKey(version, keyData, chainCode, parentFP, depth,
		childNum, isPrivate), nil
}
1013936
func FlagsFromString(imapFlagString string) Flags {
	var f Flags

	for _, flag := range strings.Split(imapFlagString, " ") {
		switch flag {
		case "\\Seen":
			f = f.SetFlags(FlagSeen)
		case "\\Answered":
			f = f.SetFlags(FlagAnswered)
		case "\\Flagged":
			f = f.SetFlags(FlagFlagged)
		case "\\Deleted":
			f = f.SetFlags(FlagDeleted)
		case "\\Draft":
			f = f.SetFlags(FlagDraft)
		case "\\Recent":
			f = f.SetFlags(FlagRecent)
		}
	}

	return f
}
104431
func NewQueryString(field, query string) QueryString {
	return QueryString{"", field, query, "", "", nil, false}
}
1188264
func (p *param) SetFromString(s string) error {
	parts := strings.SplitN(s, "=", 2)
	if len(parts) <= 1 {
		return errors.New("Unable to convert to param: " + s)
	}

	p.name = strings.TrimSpace(parts[0])
	p.value = fmt.Sprintf(`"%s"`, strings.TrimSpace(parts[1]))

	return nil
}
367765
func ValueFromString(vt string) ValueType {
	switch vt {
	case "nil", "null":
		return NilType
	case "error":
		return ErrorType
	case "unknown":
		return UnknownType
	case "value":
		return ValueInterfaceType
	case "number":
		return NumberType
	case "int":
		return IntType
	case "bool":
		return BoolType
	case "time":
		return TimeType
	case "[]byte":
		return ByteSliceType
	case "string":
		return StringType
	case "[]string":
		return StringsType
	case "map[string]value":
		return MapValueType
	case "map[string]int":
		return MapIntType
	case "map[string]string":
		return MapStringType
	case "map[string]number":
		return MapNumberType
	case "map[string]bool":
		return MapBoolType
	case "map[string]time":
		return MapTimeType
	case "[]value":
		return SliceValueType
	case "struct":
		return StructType
	case "json":
		return JsonType
	default:
		return UnknownType
	}
}
527154
func MustFromString(str string) UUID {
	u, err := FromString(str)
	if err != nil {
		panic(err)
	}

	return u
}
1227240
func (t *Token) SignedString(key interface{}) (string, error) {
	var sig, sstr string
	var err error
	if sstr, err = t.SigningString(); err != nil {
		return "", err
	}
	if sig, err = t.Method.Sign(sstr, key); err != nil {
		return "", err
	}
	return strings.Join([]string{sstr, sig}, "."), nil
}
807675
func KeyFrom(fields []string, doc Document) Key {
	key := make(Key, 0, len(fields))
	for _, f := range fields {
		if s, ok := doc[f].(String); ok {
			key = append(key, string(s))
		}
	}
	return key
}
188399
func NewKeyStringValueTree(k, v string, duplicates bool) KeyStringValueTree {
	return &keyStringValueTree{
		container: newNodeContainer(keyValue{k, v}, duplicates),
	}
}
902083
func stringKeyFunc(obj interface{}) (string, error) {
	key := obj.(objectEntry).key
	return key, nil
}
892428
func NewURLBuilderFromString(root string, relative bool) (*URLBuilder, error) {
	u, err := url.Parse(root)
	if err != nil {
		return nil, err
	}

	return NewURLBuilder(u, relative), nil
}
307987
func NewListFromString(src string, options *ParserOption) (*List, error) {
	l := NewList()
	_, err := l.LoadString(src, options)
	return l, err
}
1174291
func NewJSONPointerFromString(pointer string) (*JSONPointer, error) {
	if len(pointer) != 0 && pointer[0] != '/' {
		return nil, JSONPointerSyntaxError{pointer}
	}
	bytes := []byte(pointer)
	if at := badEscapeSequence.FindIndex(bytes); at != nil {
		sequence := string(bytes[at[0]:at[1]])
		return nil, BadEscapeSequence{pointer, sequence}
	}
	tokens := strings.Split(pointer, "/")[1:] // remove the leading ""
	for index, token := range tokens {
		tokens[index] = strings.Replace(
			strings.Replace(token, "~1", "/", -1),
			"~0",
			"~",
			-1)
	}
	p := JSONPointer{pointer, tokens}
	return &p, nil
}
1012978
func MetadataFromString(str string) Metadata {
	meta := strings.SplitAfterN(str, " ", 2)
	key := strings.TrimSpace(meta[0])
	value := meta[1]
	switch key {
	case "AppEUI":
		var appEUI types.AppEUI
		appEUI.UnmarshalText([]byte(value))
		return AppEUIMetadata{appEUI}
	case "AppID":
		return AppIDMetadata{value}
	case "GatewayID":
		return GatewayIDMetadata{value}
	case "Prefix":
		prefix := &types.DevAddrPrefix{
			Length: 32,
		}
		prefix.UnmarshalText([]byte(value))
		return PrefixMetadata{*prefix}
	}
	return nil
}
331724
func makeMapKeyFromString(mapKeyType reflect.Type, pointer string) (reflect.Value, bool) {
	valp := reflect.New(mapKeyType)
	val := reflect.Indirect(valp)
	switch mapKeyType.Kind() {
	case reflect.String:
		return reflect.ValueOf(pointer), true
	case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
		iv, err := strconv.ParseInt(pointer, 10, mapKeyType.Bits())
		if err == nil {
			val.SetInt(iv)
			return val, true
		}
	case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
		iv, err := strconv.ParseUint(pointer, 10, mapKeyType.Bits())
		if err == nil {
			val.SetUint(iv)
			return val, true
		}
	case reflect.Float32, reflect.Float64:
		fv, err := strconv.ParseFloat(pointer, mapKeyType.Bits())
		if err == nil {
			val.SetFloat(fv)
			return val, true
		}
	}

	return reflect.ValueOf(nil), false
}
452404
func (enc *Encoder) AddStringKeyOmitEmpty(key, v string) {
	enc.StringKeyOmitEmpty(key, v)
}
1174062
func NewValueString(v string) Value {
	return Value{
		typ:     TBinary,
		tbinary: unsafeStringToBytes(v),
	}
}