// NormalizeIdentifier change invalid character in identifier
// to `_`.
// Edge cases:
// - If started with invalid char, we prepend with `The_`
// - don't replace `.` if it means a library
13527
func NormalizeIdentifier(s string) string {
	if s == "" {
		return s
	}

	str := regValidIdentifier.ReplaceAllString(s, underscore)

	// it needs to be started with letter
	// if not, prepend `The_`
	startedWithLetter := func() bool {
		r := []rune(str)
		return unicode.IsLetter(r[0])
	}()
	if !startedWithLetter && !strings.HasPrefix(str, "[]") {
		str = "The_" + str
	}

	return strings.Trim(str, "_")
}
1283940
func normalizeKeys(key []string) {
	for i, k := range key {
		if !validCharactersRE.MatchString(k) {
			// first replace */* with all
			k = strings.Replace(k, allMatcher, allReplacement, -1)

			// now replace all other invalid characters with a safe one.
			key[i] = invalidCharactersRE.ReplaceAllString(k, normalizedToken)
		}
	}
}
115908
func (ctx *Context) GetIdentifier(fields []string) (interface{}, error) {
	switch fields[0] {
	case UserIdentifier:
		var user User
		if ctx.User == nil {
			user = emptyUser
		} else {
			user = ctx.User
		}
		return predicate.GetFieldByTag(user, teleport.JSON, fields[1:])
	case ResourceIdentifier:
		var resource Resource
		if ctx.Resource == nil {
			resource = emptyResource
		} else {
			resource = ctx.Resource
		}
		return predicate.GetFieldByTag(resource, "json", fields[1:])
	default:
		return nil, trace.NotFound("%v is not defined", strings.Join(fields, "."))
	}
}
1196790
func ConvertIdentifyError(assertion string, err error) error {
	switch err.(type) {
	case libkb.NotFoundError:
		return idutil.NoSuchUserError{Input: assertion}
	case libkb.ResolutionError:
		return idutil.NoSuchUserError{Input: assertion}
	}
	return err
}
912991
func (q *Query) GetIdentifier() string {
	return fmt.Sprintf("%s|%s", q.method, q.ns)
}
1045801
func normalizeNumber(v interface{}) (n interface{}, err error) {
	switch t := v.(type) {

	case json.Number:
		if strings.Contains(t.String(), ".") {
			n, err = t.Float64()
		} else {
			n, err = t.Int64()
		}

	case float32:
		n = float64(t)
	case float64:
		n = t

	case int:
		n = int64(t)
	case int8:
		n = int64(t)
	case int16:
		n = int64(t)
	case int32:
		n = int64(t)
	case int64:
		n = t

	case uint8:
		n = int64(t)
	case uint16:
		n = int64(t)
	case uint32:
		n = int64(t)
	case uint64:
		n = t
		err = fmt.Errorf("%s is not a supported type", reflect.TypeOf(v))

	default:
		n = t
	}

	return
}
1000641
func (p *gc_parser) parse_dot_ident() string {
	if p.tok == '?' {
		p.next()
		return "?"
	}

	ident := ""
	sep := 'x'
	i, j := 0, -1
	for (p.tok == scanner.Ident || p.tok == scanner.Int || p.tok == '·') && sep > ' ' {
		ident += p.lit
		if p.tok == '·' {
			ident += "·"
			j = i
			i++
		}
		i += len(p.lit)
		sep = p.scanner.Peek()
		p.next()
	}
	// middot = \xc2\xb7
	if j != -1 && i > j+1 {
		c := ident[j+2]
		if c >= '0' && c <= '9' {
			ident = ident[0:j]
		}
	}
	return ident
}
269988
func SingularizeIdentifier(s string) string {
	if i := reverseIndexRune(s, '_'); i != -1 {
		s = s[:i] + "_" + inflector.Singularize(s[i+1:])
	} else {
		s = inflector.Singularize(s)
	}

	return snaker.SnakeToCamelIdentifier(s)
}
108830
func (s *FQDNSelector) sanitize() error {
	if len(s.MatchName) > 0 && !allowedMatchNameChars.MatchString(s.MatchName) {
		return fmt.Errorf("Invalid characters in MatchName: \"%s\". Only 0-9, a-z, A-Z and . and - characters are allowed", s.MatchName)
	}

	if len(s.MatchPattern) > 0 && !allowedPatternChars.MatchString(s.MatchPattern) {
		return fmt.Errorf("Invalid characters in MatchPattern: \"%s\". Only 0-9, a-z, A-Z and ., - and * characters are allowed", s.MatchPattern)
	}
	_, err := matchpattern.Validate(s.MatchPattern)
	return err
}
1368706
func (s *CreateResourceServerInput) SetIdentifier(v string) *CreateResourceServerInput {
	s.Identifier = &v
	return s
}
657941
func (si SignerInfo) subjectKeyIdentifierSID() ([]byte, error) {
	if si.SID.Class != asn1.ClassContextSpecific || si.SID.Tag != 0 {
		return nil, ErrWrongType
	}

	return si.SID.Bytes, nil
}
1368758
func (o *GetCatalogsIdentifierParams) WithIdentifier(identifier string) *GetCatalogsIdentifierParams {
	o.Identifier = identifier
	return o
}
149843
func (s *S3Grantee) SetTypeIdentifier(v string) *S3Grantee {
	s.TypeIdentifier = &v
	return s
}
919515
func IsCIdentifier(value string) []string {
	if !cIdentifierRegexp.MatchString(value) {
		return []string{RegexError(identifierErrMsg, cIdentifierFmt, "my_name", "MY_NAME", "MyName")}
	}
	return nil
}
289083
func identifier(s string) string {
	b := make([]byte, 0, len(s))
	cap := true
	for _, c := range s {
		if c == '-' {
			cap = true
			continue
		}
		if cap && 'a' <= c && c <= 'z' {
			c -= 'a' - 'A'
		}
		cap = false
		b = append(b, byte(c))
	}
	return string(b)
}
50725
func IsValidIdentity(identity string) bool {
	for _, r := range identity {
		if !isIdentifierFirstRune(r) {
			return false
		}
		break
	}
	return IdentityRunesOnly(identity)
}
1060491
func NewACIdentifier(s string) (*ACIdentifier, error) {
	n := ACIdentifier(s)
	if err := n.assertValid(); err != nil {
		return nil, err
	}
	return &n, nil
}