// generateShortName takes a list of existing short names and a long
// name and generates the next valid short name. This process is done
// according to the MS specification.
193376
func generateShortName(longName string, used []string) (string, error) {
	longName = strings.ToUpper(longName)

	// Split the string at the final "."
	dotIdx := strings.LastIndex(longName, ".")

	var ext string
	if dotIdx == -1 {
		dotIdx = len(longName)
	} else {
		ext = longName[dotIdx+1:]
	}

	ext = cleanShortString(ext)
	ext = ext[0:]
	rawName := longName[0:dotIdx]
	name := cleanShortString(rawName)
	simpleName := fmt.Sprintf("%s.%s", name, ext)
	if ext == "" {
		simpleName = simpleName[0 : len(simpleName)-1]
	}

	doSuffix := name != rawName || len(name) > 8 || len(ext) > 3
	if !doSuffix {
		for _, usedSingle := range used {
			if strings.ToUpper(usedSingle) == simpleName {
				doSuffix = true
				break
			}
		}
	}

	if doSuffix {
		if len(ext) > 3 {
			ext = ext[:3]
		}
		found := false
		for i := 1; i < 99999; i++ {
			serial := fmt.Sprintf("~%d", i)

			nameOffset := 8 - len(serial)
			if len(name) < nameOffset {
				nameOffset = len(name)
			}

			serialName := fmt.Sprintf("%s%s", name[0:nameOffset], serial)
			simpleName = fmt.Sprintf("%s.%s", serialName, ext)

			exists := false
			for _, usedSingle := range used {
				if strings.ToUpper(usedSingle) == simpleName {
					exists = true
					break
				}
			}

			if !exists {
				found = true
				break
			}
		}

		if !found {
			return "", fmt.Errorf("could not generate short name for %s", longName)
		}
	}

	return simpleName, nil
}
557398
func (s *ConnectDirectoryInput) SetShortName(v string) *ConnectDirectoryInput {
	s.ShortName = &v
	return s
}
429359
func NewName(GivenName string, Surname string, FamiliarName string, DisplayName string, AbbreviatedName string) *Name {
	s := new(Name)
	s.GivenName = GivenName
	s.Surname = Surname
	s.FamiliarName = FamiliarName
	s.DisplayName = DisplayName
	s.AbbreviatedName = AbbreviatedName
	return s
}
274618
function generateShortName (name, filename, css) {
  // first occurrence of the name
  // TODO: better match with regex
  var i = css.indexOf('.' + name);
  var numLines = css.substr(0, i).split(/[\r\n]/).length;

  var hash = stringHash(css).toString(36).substr(0, 5);
  return '_' + name + '_' + hash + '_' + numLines;
}
510125
func shortParam(param *types.Var) string {
	ret := param.Name()
	if ret != "" {
		ret += " "
	}
	return ret + shortType(param.Type())
}
727044
func (pc *class) generate(dir, template, name string) ([]string, error) {
	fileName := filepath.Join(dir, pc.Name()+".py")

	if pc.AliasOf != "" {
		return []string{pc.Name()}, commons.GenerateFile(pc, "./templates/python/class_alias.tmpl",
			"class_alias", fileName, true)
	}

	// generate enums
	typeNames := make([]string, 0)
	for _, f := range pc.Fields {
		if f.Enum != nil {
			typeNames = append(typeNames, f.Enum.Name)
			if err := f.Enum.generate(dir); err != nil {
				return typeNames, err
			}
		}
	}

	if pc.Enum != nil {
		typeNames = append(typeNames, pc.Enum.Name)
		return typeNames, pc.Enum.generate(dir)
	}

	typeNames = append(typeNames, pc.Name())
	return typeNames, commons.GenerateFile(pc, template, name, fileName, true)
}
1175570
func generateStoreLockName() string {
	h := sha256.New()
	h.Write([]byte(JujuControllersPath()))
	fullHash := fmt.Sprintf("%x", h.Sum(nil))
	return fmt.Sprintf("store-lock-%x", fullHash[:8])
}
207250
func (f *Field) ShortName() string {
	name := f.Name
	if i := strings.LastIndex(name, "."); i > 0 {
		name = name[i+1:]
	}
	return f.Translate(name)
}
398826
func shortID() string {
	b := make([]byte, 6)
	io.ReadFull(rand.Reader, b)
	return base64.StdEncoding.EncodeToString(b)
}
568765
func GenerateName(backendName string) string {
	data := []byte("_TRAEFIK_BACKEND_" + backendName)

	hash := sha1.New()
	_, err := hash.Write(data)
	if err != nil {
		// Impossible case
		log.Errorf("Fail to create cookie name: %v", err)
	}

	return fmt.Sprintf("_%x", hash.Sum(nil))[:cookieNameLength]
}
808980
func GenerateMountName(mount *MountConfig) string {
	h := fnv.New32a()
	h.Write([]byte(mount.HostDir))
	h.Write([]byte(mount.MountDir))
	return fmt.Sprintf("mount-%x", h.Sum32())
}
312715
func (c *RouteAllocationController) GenerateHostname(route *routeapi.Route, shard *routeapi.RouterShard) string {
	klog.V(4).Infof("Generating host name for Route: %s", route.Name)

	s := c.Plugin.GenerateHostname(route, shard)

	klog.V(4).Infof("Route: %s, generated host name/alias=%s",
		route.Name, s)

	return s
}
1277083
func (s *CreateLayerInput) SetShortname(v string) *CreateLayerInput {
	s.Shortname = &v
	return s
}
693447
func (ws *WebSessionV2) GetShortName() string {
	if len(ws.Metadata.Name) < 4 {
		return "<undefined>"
	}
	return ws.Metadata.Name[:4]
}
1130785
func (g *generator) mockName(typeName string) string {
	if mockName, ok := g.mockNames[typeName]; ok {
		return mockName
	}

	return "Mock" + typeName
}
1090734
func generateUsername(r *http.Request, firstname, lastname string) (string, error) {
	counter := 0
	var username string
	for _, r := range firstname {
		if unicode.IsSpace(r) {
			continue
		}
		username += string(unicode.ToLower(r))
	}
	username += "_"
	for _, r := range lastname {
		if unicode.IsSpace(r) {
			continue
		}
		username += string(unicode.ToLower(r))
	}
	username += "_"
	userMgr := user.NewManager(r)

	count, err := userMgr.GetPendingRegistrationsCount()
	if err != nil {
		return "", err
	}
	log.Debug("count", count)
	if count >= MAX_PENDING_REGISTRATION_COUNT {
		return "", errors.New("Max amount of pending registrations reached")
	}

	orgMgr := organization.NewManager(r)
	exists := true
	for exists {
		counter++
		var err error
		exists, err = userMgr.Exists(username + strconv.Itoa(counter))
		if err != nil {
			return "", err
		}
		if !exists {
			exists = orgMgr.Exists(username + strconv.Itoa(counter))
		}
	}
	username = username + strconv.Itoa(counter)
	return username, nil
}
210328
func funcname(name string) string {
	i := strings.LastIndex(name, "/")
	name = name[i+1:]
	i = strings.Index(name, ".")
	return name[i+1:]
}