// normalizeSemString returns the passed string stripped of all characters
// which are not valid according to the provided semantic versioning alphabet.
975047
func normalizeSemString(str, alphabet string) string {
	var result bytes.Buffer
	for _, r := range str {
		if strings.ContainsRune(alphabet, r) {
			result.WriteRune(r)
		}
	}
	return result.String()
}
548249
func (vec *T) Normalize() *T {
	sl := vec.LengthSqr()
	if sl == 0 || sl == 1 {
		return vec
	}
	return vec.Scale(1 / math.Sqrt(sl))
}
1271835
func (app *AppModel) Normalize() error {
	for _, env := range app.Environments {
		if err := env.Normalize(); err != nil {
			return err
		}
	}
	return nil
}
8368
func (t *File_Template) Normalize() error {
	if t.Body == "" {
		return errors.New("body is empty")
	}

	defaultParams := make(map[string]*Value, len(t.Param))
	for k, param := range t.Param {
		if k == "" {
			return fmt.Errorf("param %q: invalid name", k)
		}
		if !ParamRegex.MatchString(k) {
			return fmt.Errorf("param %q: malformed name", k)
		}
		if !strings.Contains(t.Body, k) {
			return fmt.Errorf("param %q: not present in body", k)
		}
		if err := param.Normalize(); err != nil {
			return fmt.Errorf("param %q: %s", k, err)
		}
		if param.Default != nil {
			defaultParams[k] = param.Default
		} else {
			defaultParams[k] = param.Schema.Zero()
		}
	}

	maybeJSON, err := t.Render(defaultParams)
	if err != nil {
		return fmt.Errorf("rendering: %s", err)
	}

	err = json.Unmarshal([]byte(maybeJSON), &map[string]interface{}{})
	if err != nil {
		return fmt.Errorf("parsing rendered body: %s", err)
	}
	return nil
}
414237
func NormalizeEmail(email string) string {
	// Trim whitespace.
	email = strings.TrimSpace(email)
	// Make sure it is valid.
	if !IsValidEmail(email) {
		return ""
	}
	// Split email into parts.
	local, domain, ok := splitEmail(email)
	if !ok {
		return ""
	}
	// Remove trailing dot from domain.
	domain = strings.TrimRight(domain, ".")
	// Convert domain to lower case.
	domain = strings.ToLower(domain)
	// Combine and return the result.
	return local + "@" + domain
}
733233
func NormalizeSeriesTitle(title string) string {
	title = optionalReplace(wordDelimiterRegex, title, "")
	title = optionalReplace(punctuationRegex, title, "")
	title = optionalReplace(commonWordRegex, title, "")
	title = optionalReplace(duplicateSpacesRegex, title, "")

	return strings.ToLower(removeSpace(title))
}
1146780
func (config *BitriseDataModel) Normalize() error {
	if err := config.App.Normalize(); err != nil {
		return err
	}

	for _, workflow := range config.Workflows {
		if err := workflow.Normalize(); err != nil {
			return err
		}
	}

	return nil
}
463881
func LessNumericStrings(l, r string) bool {
	var lf, rf float64
	if _, err := fmt.Sscanf(l, "%f", &lf); err != nil {
		return LessStrings(l, r)
	} else if _, err := fmt.Sscanf(r, "%f", &rf); err != nil {
		return LessStrings(l, r)
	} else {
		return lf < rf
	}
}
584497
func normalizeEscape(s string) (string, error) {
	u, err := recursiveUnescape(s)
	if err != nil {
		return "", err
	}
	return escape(u), nil
}
598281
func (s *Stage) Normalize() error {
	switch st := s.GetStageType().(type) {
	case *Stage_Failure:
		return st.Failure.Normalize()
	case *Stage_Stall:
		return st.Stall.Normalize()
	case *Stage_Deps:
		return st.Deps.Normalize()
	}
	return fmt.Errorf("empty stage")
}
1255817
func (c *CipdSpec) Normalize() error {
	if err := schemaHostURLValidate(c.Server); err != nil {
		return fmt.Errorf("job.inputs.cipd.server: %s", err)
	}
	if c.Client != nil {
		if err := c.Client.Normalize(); err != nil {
			return fmt.Errorf("job.inputs.cipd.client: %s", err)
		}
	}
	for path, pkgs := range c.ByPath {
		for i, p := range pkgs.Pkg {
			if err := p.Normalize(); err != nil {
				return fmt.Errorf("job.inputs.cipd.by_path[%s].pkg[%d]: %s", path, i, err)
			}
		}
	}
	return nil
}
830541
func (s *GraphQuery_Search) Normalize() error {
	// for now, start and end MUST be timestamp values.
	switch s.Start.Value.(type) {
	case *PropertyValue_Time:
	default:
		return fmt.Errorf("invalid Start type: %T", s.Start.Value)
	}
	switch s.End.Value.(type) {
	case *PropertyValue_Time:
	default:
		return fmt.Errorf("invalid End type: %T", s.End.Value)
	}
	return nil
}
873526
func normalizeMetric(name string) string {
	// Special cases
	r := strings.NewReplacer("VSchema", "vschema", "VtGate", "vtgate")
	name = r.Replace(name)

	return stats.GetSnakeName(name)
}
534447
func (id *HashID) Normalize() error {
	// encoding/hex encodes using lower-case hexadecimal. Note that this is a
	// no-op if the ID is already lowercase.
	idv := strings.ToLower(string(*id))

	if decodeSize := hex.DecodedLen(len(idv)); decodeSize != sha256.Size {
		return fmt.Errorf("invalid SHA256 hash size (%d != %d)", decodeSize, sha256.Size)
	}
	for i, r := range idv {
		if !strings.ContainsRune(validHashIDChars, r) {
			return fmt.Errorf("invalid character '%c' at %d", r, i)
		}
	}
	*id = HashID(idv)
	return nil
}
344616
func (f *FailureStage) Normalize() error {
	if f.Chance < 0 {
		return fmt.Errorf("too small FailureStage chance")
	}
	if f.Chance > 1 {
		return fmt.Errorf("too large FailureStage chance")
	}
	return nil
}
101118
func normalizeArch(arch, variant string) (string, string) {
	arch, variant = strings.ToLower(arch), strings.ToLower(variant)
	switch arch {
	case "i386":
		arch = "386"
		variant = ""
	case "x86_64", "x86-64":
		arch = "amd64"
		variant = ""
	case "aarch64", "arm64":
		arch = "arm64"
		switch variant {
		case "8", "v8":
			variant = ""
		}
	case "armhf":
		arch = "arm"
		variant = "v7"
	case "armel":
		arch = "arm"
		variant = "v6"
	case "arm":
		switch variant {
		case "", "7":
			variant = "v7"
		case "5", "6", "8":
			variant = "v" + variant
		}
	}

	return arch, variant
}
507764
func NormalizePath(path string) (string, error) {
	s, err := filepath.Abs(path)
	if err != nil {
		return "", trace.ConvertSystemError(err)
	}
	abs, err := filepath.EvalSymlinks(s)
	if err != nil {
		return "", trace.ConvertSystemError(err)
	}
	return abs, nil
}