// extractTopicName extract topic name for valid topic name input
192079
func extractTopicName(inTopic string) (result string) {
	Tmptopic := strings.ToLower(inTopic)
	if strings.Contains(Tmptopic, "/topics/") {
		tmp := strings.Split(inTopic, "/")
		result = tmp[len(tmp)-1]
		return
	}

	result = inTopic
	return
}
594869
func ExtractReplyScreenname(text string) *TwitterEntity {
	match := validReply.FindStringSubmatchIndex(text)
	if match != nil && !invalidMentionMatchEnd.MatchString(text[match[1]:]) {
		atSignStart := match[validReplyGroupAt*2]
		screennameStart := match[validReplyGroupUsername*2]
		screennameEnd := match[validReplyGroupUsername*2+1]
		entity := &TwitterEntity{
			Text:            text[atSignStart:screennameEnd],
			screenName:      text[screennameStart:screennameEnd],
			screenNameIsSet: true,
			ByteRange: Range{
				Start: atSignStart,
				Stop:  screennameEnd},
			Type: MENTION}

		start := utf8.RuneCountInString(text[:entity.ByteRange.Start])
		entity.Range.Start = start
		entity.Range.Stop = start + utf8.RuneCountInString(text[entity.ByteRange.Start:entity.ByteRange.Stop])
		return entity
	}
	return nil
}
607290
func ExtractNamespace(np metav1.Object) string {
	ns := np.GetNamespace()
	if ns == "" {
		return v1.NamespaceDefault
	}
	return ns
}
452600
func ensureTopic(pubsubClient *pubsub.Client, topicName string) *pubsub.Topic {
	var topic *pubsub.Topic
	ctx, _ := context.WithTimeout(context.Background(), ContextDuration)
	topic = pubsubClient.Topic(topicName)
	topicExists, err := topic.Exists(ctx)

	if err != nil {
		log.Fatalf("Could not check if topic exists: %v", err)
	}
	if !topicExists {
		new_topic, err := pubsubClient.CreateTopic(ctx, topicName)
		if err != nil {
			log.Fatalf("Could not create PubSub topic: %v", err)
		}
		topic = new_topic
	}

	return topic
}
966113
func extractKey(s, prefix string) (string, error) {
	substrings := strings.SplitN(s, "/", 2)
	if len(substrings) <= 1 || substrings[0] != prefix {
		switch prefix {
		case deleteFromPrimitiveListDirectivePrefix:
			return "", mergepatch.ErrBadPatchFormatForPrimitiveList
		case setElementOrderDirectivePrefix:
			return "", mergepatch.ErrBadPatchFormatForSetElementOrderList
		default:
			return "", fmt.Errorf("fail to find unknown prefix %q in %s\n", prefix, s)
		}
	}
	return substrings[1], nil
}
432776
func (s *Server) AddTopic(topicARN, endpoint string, callback func(*Message)) {
	t := &topicDescription{
		TopicARN: topicARN,
		Callback: callback,
	}
	if endpoint[:1] != "/" {
		endpoint = "/" + endpoint
	}
	if s.topics == nil {
		s.topics = map[string]*topicDescription{
			endpoint: t,
		}
	} else {
		s.topics[endpoint] = t
	}
	if s.Logger != nil {
		s.Logger.Printf("Adding endpoint '%s' for topic '%s'\n", endpoint, topicARN)
	}
}
317310
func (s *DescribeEventTopicsInput) SetTopicNames(v []*string) *DescribeEventTopicsInput {
	s.TopicNames = v
	return s
}
581904
func extractSection(s string, start, end rune) (prefix, body, suffix string, found bool) {
	s = trim(s)
	if strings.HasPrefix(s, string(start)) {
		// no prefix
		body = s[1:]
	} else {
		a := strings.SplitN(s, string(start), 2)
		if len(a) != 2 {
			return "", "", s, false
		}
		prefix = a[0]
		body = a[1]
	}
	a := strings.SplitN(body, string(end), 2)
	if len(a) != 2 {
		return "", "", "", false
	}
	return prefix, a[0], a[1], true
}
1238913
func (info *HostCertificateInfo) SubjectName() *pkix.Name {
	if info.subjectName != nil {
		return info.subjectName
	}

	return info.toName(info.Subject)
}
1064770
func (c *Client) ListTopicPermissionsOf(username string) (rec []TopicPermissionInfo, err error) {
	req, err := newGETRequest(c, "users/"+PathEscape(username)+"/topic-permissions")
	if err != nil {
		return []TopicPermissionInfo{}, err
	}

	if err = executeAndParseRequest(c, req, &rec); err != nil {
		return []TopicPermissionInfo{}, err
	}

	return rec, nil
}
1176984
func ParseApplicationTopic(topic string) (*ApplicationTopic, error) {
	pattern := regexp.MustCompile("^([0-9a-z](?:[_-]?[0-9a-z]){1,35}|\\+)/(events)([0-9a-z/-]+|/#)?$")
	matches := pattern.FindStringSubmatch(topic)
	if len(matches) < 3 {
		return nil, fmt.Errorf("Invalid topic format")
	}
	var appID string
	if matches[1] != simpleWildcard {
		appID = matches[1]
	}
	topicType := ApplicationTopicType(matches[2])
	appTopic := &ApplicationTopic{appID, topicType, ""}
	if topicType == AppEvents && len(matches) > 3 {
		appTopic.Field = strings.Trim(matches[3], "/")
	}
	return appTopic, nil
}
1121647
func ExtractClusterName(opts ...interface{}) *opt.ClusterNameOption {
	for _, o := range opts {
		if v, ok := o.(*opt.ClusterNameOption); ok {
			return v
		}
	}
	return nil
}
103381
func extract(str string) (name string, num int, rest string, ok bool) {
	if len(str) < 2 || str[0] != '$' {
		return
	}
	brace := false
	if str[1] == '{' {
		brace = true
		str = str[2:]
	} else {
		str = str[1:]
	}
	i := 0
	for i < len(str) {
		rune, size := utf8.DecodeRuneInString(str[i:])
		if !unicode.IsLetter(rune) && !unicode.IsDigit(rune) && rune != '_' {
			break
		}
		i += size
	}
	if i == 0 {
		// empty name is not okay
		return
	}
	name = str[:i]
	if brace {
		if i >= len(str) || str[i] != '}' {
			// missing closing brace
			return
		}
		i++
	}

	// Parse number.
	num = 0
	for i := 0; i < len(name); i++ {
		if name[i] < '0' || '9' < name[i] || num >= 1e8 {
			num = -1
			break
		}
		num = num*10 + int(name[i]) - '0'
	}
	// Disallow leading zeros.
	if name[0] == '0' && len(name) > 1 {
		num = -1
	}

	rest = str[i:]
	ok = true
	return
}
832322
func extractHost(header string) (host string) {
	host, _, err := net.SplitHostPort(header)
	if err != nil {
		host = header
	}
	return host
}
1263277
func ClusterName(subject pkix.Name) (string, error) {
	if len(subject.Organization) == 0 {
		return "", trace.BadParameter("missing subject organization")
	}
	return subject.Organization[0], nil
}
651569
func extractTableSourceAsNames(node ast.ResultSetNode, input []string, onlySelectStmt bool) []string {
	switch x := node.(type) {
	case *ast.Join:
		input = extractTableSourceAsNames(x.Left, input, onlySelectStmt)
		input = extractTableSourceAsNames(x.Right, input, onlySelectStmt)
	case *ast.TableSource:
		if _, ok := x.Source.(*ast.SelectStmt); !ok && onlySelectStmt {
			break
		}
		if s, ok := x.Source.(*ast.TableName); ok {
			if x.AsName.L == "" {
				input = append(input, s.Name.L)
				break
			}
		}
		input = append(input, x.AsName.L)
	}
	return input
}
1214253
func extractHostname(in string) string {
	if in == "" {
		return ""
	}
	// help url.Parse by adding a scheme if one is missing. This should still
	// allow for any scheme, but by default we assume http (only for parsing)
	urlStr := in
	if !strings.Contains(urlStr, "://") {
		urlStr = "http://" + urlStr
	}
	u, err := url.Parse(urlStr)
	if err == nil {
		if ch := fsutil.CleanFilename(u.Hostname()); ch != "" {
			return ch
		}
	}
	return fsutil.CleanFilename(in)
}