// MaybeFromString reads a UUID into a new UUID instance,
// setting the instance to zero if it fails.
171164
func MaybeFromString(str string) UUID {
	u, err := FromString(str)
	if err != nil {
		return zero
	}

	return u
}
463082
func (r DynamicRender) AddFromString(name, templateString string) *template.Template {
	builder := &templateBuilder{templateName: name, templateString: templateString}
	builder.buildType = stringTemplateType
	r[name] = builder
	return builder.buildTemplate()
}
746484
func (b *builtinUUIDSig) evalString(_ chunk.Row) (d string, isNull bool, err error) {
	return uuid.NewV1().String(), false, nil
}
661067
func ComponentNameFromString(s string) ComponentName {
	switch s {
	case string(ComponentNameCLI):
		return ComponentNameCLI
	case string(ComponentNameService):
		return ComponentNameService
	case string(ComponentNameKBFS):
		return ComponentNameKBFS
	case string(ComponentNameKBNM):
		return ComponentNameKBNM
	case string(ComponentNameUpdater):
		return ComponentNameUpdater
	case string(ComponentNameApp):
		return ComponentNameApp
	case string(ComponentNameFuse):
		return ComponentNameFuse
	case string(ComponentNameHelper):
		return ComponentNameHelper
	case string(ComponentNameCLIPaths):
		return ComponentNameCLIPaths
	case string(ComponentNameRedirector):
		return ComponentNameRedirector
	}
	return ComponentNameUnknown
}
677189
func createFromString(data [][]string) []*TabulateRow {
	rows := make([]*TabulateRow, len(data))

	for index, el := range data {
		rows[index] = &TabulateRow{Elements: el}
	}
	return rows
}
1016939
func SetValueFromString(valueField reflect.Value, value string) error {
	if !valueField.IsValid() {
		return fmt.Errorf("r.SetValueFromString: %s is not valid", valueField)
	}
	if !valueField.CanSet() {
		return fmt.Errorf("r.SetValueFromString: Cannot set %s field value", valueField)
	}
	switch valueField.Interface().(type) {
	case string:
		valueField.SetString(value)
	case *string:
		refValue := reflect.ValueOf(&value)
		valueField.Set(refValue)
	case int:
		val, err := totype.StringToInt(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(val)
		valueField.Set(refValue)
	case *int:
		val, err := totype.StringToInt(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(&val)
		valueField.Set(refValue)
	case int16:
		val, err := totype.StringToInt16(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(val)
		valueField.Set(refValue)
	case *int16:
		val, err := totype.StringToInt16(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(&val)
		valueField.Set(refValue)
	case int32:
		val, err := totype.StringToInt32(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(val)
		valueField.Set(refValue)
	case *int32:
		val, err := totype.StringToInt32(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(&val)
		valueField.Set(refValue)
	case int64:
		val, err := totype.StringToInt64(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(val)
		valueField.Set(refValue)
	case *int64:
		val, err := totype.StringToInt64(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(&val)
		valueField.Set(refValue)
	case bool:
		val, err := totype.StringToBool(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(val)
		valueField.Set(refValue)
	case *bool:
		val, err := totype.StringToBool(value)
		if err != nil {
			return err
		}
		refValue := reflect.ValueOf(&val)
		valueField.Set(refValue)
	default:
		return fmt.Errorf("unsupported value type %v", valueField.Type().String())
	}
	return nil
}
1359431
func filesFromString(in string) ([]*proxy.FileDescriptor, error) {
	var out []fileDescriptor
	if err := json.Unmarshal([]byte(in), &out); err != nil {
		return nil, err
	}
	files := make([]*proxy.FileDescriptor, len(out))
	for i, o := range out {
		files[i] = &proxy.FileDescriptor{
			File:    os.NewFile(uintptr(o.FileFD), o.FileName),
			Address: o.Address,
		}
	}
	return files, nil
}
39221
func (*parser) parseString(b []byte) string {
	if i := bytes.IndexByte(b, 0); i >= 0 {
		return string(b[:i])
	}
	return string(b)
}
175721
func GetRandomString(length int) string {
	b := make([]byte, length)

	for i := range b {
		c := rand.Intn(allowedCharsSize)
		b[i] = allowedChars[c]
	}

	return string(b)
}
1356328
func KiteFromString(s string) (*Kite, error) {
	if s == "" || s[0] != '/' {
		return nil, errors.New("invalid kite string")
	}

	fields := make([]string, 7)
	copy(fields, strings.SplitN(s[1:], "/", 7))

	return &Kite{
		Username:    fields[0],
		Environment: fields[1],
		Name:        fields[2],
		Version:     fields[3],
		Region:      fields[4],
		Hostname:    fields[5],
		ID:          fields[6],
	}, nil
}
365895
func MustIDFromString(s string) sha1 {
	b, _ := hex.DecodeString(s)
	return MustID(b)
}
1362139
func LogLevelFromString(s string) (LogLevel, error) {
	switch s {
	case "trace":
		return LogLevelTrace, nil
	case "debug":
		return LogLevelDebug, nil
	case "info":
		return LogLevelInfo, nil
	case "warn":
		return LogLevelWarn, nil
	case "error":
		return LogLevelError, nil
	case "none":
		return LogLevelNone, nil
	default:
		return 0, errors.New("invalid log level")
	}
}
1141010
func (ctx *Context) RenderFromString(tplSrc string, data ...map[string]interface{}) {
	var renderData map[string]interface{}
	if len(data) == 0 {
		renderData = make(map[string]interface{})
	} else {
		renderData = data[0]
	}
	renderData["xsrf_token"] = ctx.xsrfToken()
	content, e := ctx.App.View.RenderFromString(ctx.templateLoader, tplSrc, renderData)
	if e != nil {
		panic(e)
	}
	ctx.Send(content)
}
1102933
func (u *UUIDFieldIndex) parseString(s string, enforceLength bool) ([]byte, error) {
	// Verify the length
	l := len(s)
	if enforceLength && l != 36 {
		return nil, fmt.Errorf("UUID must be 36 characters")
	} else if l > 36 {
		return nil, fmt.Errorf("Invalid UUID length. UUID have 36 characters; got %d", l)
	}

	hyphens := strings.Count(s, "-")
	if hyphens > 4 {
		return nil, fmt.Errorf(`UUID should have maximum of 4 "-"; got %d`, hyphens)
	}

	// The sanitized length is the length of the original string without the "-".
	sanitized := strings.Replace(s, "-", "", -1)
	sanitizedLength := len(sanitized)
	if sanitizedLength%2 != 0 {
		return nil, fmt.Errorf("Input (without hyphens) must be even length")
	}

	dec, err := hex.DecodeString(sanitized)
	if err != nil {
		return nil, fmt.Errorf("Invalid UUID: %v", err)
	}

	return dec, nil
}
60498
func ResourceTypeFromString(typeString string) (ResourceType, error) {
	switch strings.ToUpper(typeString) {
	case "ANY":
		return ResourceAny, nil
	case "TOPIC":
		return ResourceTopic, nil
	case "GROUP":
		return ResourceGroup, nil
	case "BROKER":
		return ResourceBroker, nil
	default:
		return ResourceUnknown, NewError(ErrInvalidArg, "Unknown resource type", false)
	}
}
1100613
func (v *Variable) TypeString() string {
	if v == nilVariable {
		return "nil"
	}
	if v.DwarfType != nil {
		return v.DwarfType.Common().Name
	}
	return v.Kind.String()
}
774076
func (v *UIManager) AddUIFromString(buffer string) error {
	ptr := C.CString(buffer)
	defer cfree(ptr)
	var gerror *C.GError
	C.gtk_ui_manager_add_ui_from_string(UI_MANAGER(v), gstring(ptr), -1, &gerror)
	if gerror != nil {
		err := glib.ErrorFromNative(unsafe.Pointer(gerror))
		return err
	}
	return nil
}