当前位置: 首页>>代码示例>>Golang>>正文


Golang strings.ContainsRune函数代码示例

本文整理汇总了Golang中strings.ContainsRune函数的典型用法代码示例。如果您正苦于以下问题:Golang ContainsRune函数的具体用法?Golang ContainsRune怎么用?Golang ContainsRune使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ContainsRune函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: hostname

// Performs heuristics to determine the hostname of the current host.
// Tries os.Hostname(), and if that isn't fully qualified (contains a '.'),
// Fails over to finding the first hostname for the first IP of the host
// that contains a '.'. If none do, fails back to the unqualified hostname.
func hostname() string {
	h, err := os_hostname()
	if err != nil {
		log.Error("Couldn't get hostname for current host: %s", err.Error())
		return "unknown"
	}
	if strings.ContainsRune(h, '.') {
		return h
	}
	addrs, err := net_lookuphost(h)
	if err != nil {
		log.Warn("Couldn't resolve FQDN of host: %s", err.Error())
		return h
	}
	if len(addrs) > 0 {
		names, err := net_lookupaddr(addrs[0])
		if err != nil {
			log.Warn("Couldn't resolve FQDN of host: %s", err.Error())
			return h
		}
		for _, name := range names {
			if strings.ContainsRune(name, '.') {
				return name
			}
		}
	}

	log.Warn("No FQDN resolvable, defaulting to unqualified hostname")
	return h
}
开发者ID:qanx,项目名称:bmad,代码行数:34,代码来源:config.go

示例2: Validate

func (c Config) Validate() error {
	if c.Host == "" {
		return errors.New("host cannot be empty")
	}
	if c.Port <= 0 {
		return fmt.Errorf("invalid port %d", c.Port)
	}
	if c.IdleTimeout < 0 {
		return errors.New("idle timeout must be positive")
	}
	if c.Enabled && c.From == "" {
		return errors.New("must provide a 'from' address")
	}
	// Poor mans email validation, but since emails have a very large domain this is probably good enough
	// to catch user error.
	if c.From != "" && !strings.ContainsRune(c.From, '@') {
		return fmt.Errorf("invalid from email address: %q", c.From)
	}
	for _, t := range c.To {
		if !strings.ContainsRune(t, '@') {
			return fmt.Errorf("invalid to email address: %q", t)
		}
	}
	return nil
}
开发者ID:influxdata,项目名称:kapacitor,代码行数:25,代码来源:config.go

示例3: quoteAs

func (q MysqlQuoter) quoteAs(parts ...string) string {

	lp := len(parts)

	hasQuote0 := strings.ContainsRune(parts[0], quoteRune)
	hasDot0 := strings.ContainsRune(parts[0], '.')

	switch {
	case lp == 1 && hasQuote0:
		return parts[0] // already quoted
	case lp > 1 && parts[1] == "" && !hasQuote0 && !hasDot0:
		return quote + q.unQuote(parts[0]) + quote // must be quoted
	case lp == 1 && !hasQuote0 && hasDot0:
		return q.splitDotAndQuote(parts[0])
	}

	n := q.splitDotAndQuote(parts[0])

	switch lp {
	case 1:
		return n
	case 2:
		return n + " AS " + quote + q.unQuote(parts[1]) + quote
	default:
		return n + " AS " + quote + q.unQuote(strings.Join(parts[1:], "_")) + quote
	}
}
开发者ID:joao-parana,项目名称:csfw,代码行数:27,代码来源:quote.go

示例4: readMapFile

func readMapFile(map_file string, hook func(line string, email string)) []Alias {
	f, err := os.Open(map_file)
	if err != nil {
		log.Fatal("could not open map file ", map_file, " due to ", err)
	}
	aliases := make([]Alias, 0)
	scanner := bufio.NewScanner(bufio.NewReader(f))
	for scanner.Scan() {
		line := strings.TrimSpace(scanner.Text())
		if strings.HasPrefix(line, "#") {
			if hook != nil {
				hook(line, "")
			}
			continue
		}
		fields := strings.Fields(line)
		// there could be a comment after the map entry
		if len(fields) >= 2 && strings.ContainsRune(fields[0], '@') {
			if strings.ContainsRune(fields[0], '@') {
				aliases = append(aliases, Alias{fields[0], fields[1]})
			}
			if hook != nil {
				hook(line, fields[0])
			}
		} else {
			if hook != nil {
				hook(line, "")
			}
		}
	}
	return aliases
}
开发者ID:fazalmajid,项目名称:postmapweb,代码行数:32,代码来源:postmapweb.go

示例5: outputWhere

// Generates the WHERE part
func (b *Builder) outputWhere() string {
	if b.where == "" {
		return ""
	}

	var ret bytes.Buffer

	ret.WriteString(" WHERE ")

	inside := false
	var insiderune rune
	for _, c := range b.where {
		if strings.ContainsRune("'\"", c) {
			if !inside || insiderune == c {
				inside = !inside
				insiderune = c
			}
		}

		if !inside && strings.ContainsRune("?", c) {
			ret.WriteString(b.processor.NextParam(""))
		} else {
			ret.WriteRune(c)
		}
	}

	return ret.String()
}
开发者ID:RangelReale,项目名称:sqldimel,代码行数:29,代码来源:builder.go

示例6:

func Test한글(t *testing.T) {
	h := "한글"
	assert.Equal(t, 6, len(h))
	assert.Equal(t, 2, utf8.RuneCountInString(h))
	assert.Equal(t, []string{"한", "글"}, strings.Split(h, ""))
	assert.True(t, strings.Contains(h, "한"))
	assert.True(t, strings.Contains(h, "글"))
	assert.True(t, strings.ContainsRune(h, '한'))
	assert.True(t, strings.ContainsRune(h, '글'))
	runes := []rune(h)
	assert.Equal(t, []int32{54620, 44544}, runes)
	assert.Equal(t, "[]int32", reflect.TypeOf(runes).String())
	assert.Equal(t, "int32", reflect.TypeOf(runes[0]).String())
	r := reflect.ValueOf(runes[0])
	assert.Equal(t, "reflect.Value", reflect.TypeOf(r).String())
	assert.Equal(t, "int32", r.Type().String())
	assert.Equal(t, reflect.Int32, r.Kind())
	for i, c := range h {
		assert.True(t, strings.Contains(h, string(c)))
		assert.True(t, strings.ContainsRune(h, c))
		assert.Equal(t, "int32", reflect.TypeOf(c).String())
		assert.Equal(t, "int32", reflect.TypeOf(rune(c)).String())
		assert.Equal(t, "string", reflect.TypeOf(strconv.QuoteRune(c)).String())
		if 0 == i {
			assert.True(t, 54620 == c)
			assert.Equal(t, "한", string(c))
			assert.Equal(t, "'한'", strconv.QuoteRune(c))
		}
	}
}
开发者ID:wookay,项目名称:aheui-go,代码行数:30,代码来源:hangul_test.go

示例7: ContainsRune

// ContainRune reports whether the Unicode code point r is within s
func ContainsRune(s string, r rune) bool {
	fmt.Println(strings.ContainsRune("seafood", 12))    // false
	fmt.Println(strings.ContainsRune("seafood12", 12))  // false
	fmt.Println(strings.ContainsRune("seafood12", 97))  // true 97 ->a
	fmt.Println(strings.ContainsRune("seafood12", 111)) // true  111->o
	return strings.ContainsRune(s, r)
}
开发者ID:upccup,项目名称:cuplearn,代码行数:8,代码来源:stringsTest.go

示例8: validate

func (t *Test) validate(d *Document) error {
	if len(t.TestID) == 0 {
		return fmt.Errorf("a test in document has no identifier")
	}
	if t.getEvaluationInterface() == nil {
		return fmt.Errorf("%v: no valid evaluation interface", t.TestID)
	}
	for _, x := range t.If {
		ptr, err := d.getTest(x)
		if err != nil {
			return fmt.Errorf("%v: %v", t.TestID, err)
		}
		if ptr == t {
			return fmt.Errorf("%v: test cannot reference itself", t.TestID)
		}
	}
	// Ensure the tags only contain valid characters
	for _, x := range t.Tags {
		if strings.ContainsRune(x.Key, '"') {
			return fmt.Errorf("%v: test tag key cannot contain quote", t.TestID)
		}
		if strings.ContainsRune(x.Value, '"') {
			return fmt.Errorf("%v: test tag value cannot contain quote", t.TestID)
		}
	}
	return nil
}
开发者ID:ZhuHangpeng,项目名称:mig,代码行数:27,代码来源:test.go

示例9: newMailAddress

func newMailAddress(w http.ResponseWriter, r *http.Request) (string, error) {
	mail := r.FormValue("mail")
	if len(mail) > 140 || strings.ContainsRune(mail, '\n') ||
		strings.ContainsRune(mail, '\t') {
		return "", errors.New("Illegal mail address.")
	}
	return mail, nil
}
开发者ID:plomlompom,项目名称:htwtxt,代码行数:8,代码来源:main.go

示例10: TestTransformerQuotesOff

func TestTransformerQuotesOff(t *testing.T) {
	t.Parallel()
	tname := "double and single quotes 1"
	res := Transform(samples[tname], QuotesOff)
	if strings.ContainsRune(res, 0x22) || strings.ContainsRune(res, 0x27) {
		t.Errorf("Error in transform of %s: quotes are not replaced in the result [[%s]]: original %s\n", tname, res, samples[tname])
	}
}
开发者ID:optimuse,项目名称:webseclab,代码行数:8,代码来源:transform_test.go

示例11: TestDetectCharacterSetInHTML

func TestDetectCharacterSetInHTML(t *testing.T) {
	msg := readMessage("non-mime-missing-charset.raw")
	mime, err := ParseMIMEBody(msg)
	if err != nil {
		t.Fatalf("Failed to parse non-MIME: %v", err)
	}
	assert.False(t, strings.ContainsRune(mime.Html, 0x80), "HTML body should not have contained a Windows CP1250 Euro Symbol")
	assert.True(t, strings.ContainsRune(mime.Html, 0x20ac), "HTML body should have contained a Unicode Euro Symbol")
}
开发者ID:redsift,项目名称:go.enmime,代码行数:9,代码来源:mail_test.go

示例12: Word

func (b *buffer) Word(offset int) Region {
	if offset < 0 {
		offset = 0
	}
	lr := b.FullLine(offset)
	col := offset - lr.Begin()

	line := b.SubstrR(lr)
	if len(line) == 0 {
		return Region{offset, offset}
	}

	seps := "./\\()\"'-:,.;<>[email protected]#$%^&*|+=[]{}`~?"
	if v, ok := b.Settings().Get("word_separators", seps).(string); ok {
		seps = v
	}
	spacing := " \n\t\r"
	eseps := seps + spacing

	if col >= len(line) {
		col = len(line) - 1
	}
	last := true
	li := 0
	ls := false
	lc := 0
	for i, r := range line {
		cur := strings.ContainsRune(eseps, r)
		cs := r == ' '
		if !cs {
			lc = i
		}
		if last == cur && ls == cs {
			continue
		}
		ls = cs
		r := Region{li, i}
		if r.Contains(col) && i != 0 {
			r.A, r.B = r.A+lr.Begin(), r.B+lr.Begin()
			if !(r.B == offset && last) {
				return r
			}
		}
		li = i
		last = cur
	}
	r := Region{lr.Begin() + li, lr.End()}
	lc += lr.Begin()
	if lc != offset && !strings.ContainsRune(spacing, b.Index(r.A)) {
		r.B = lc
	}
	if r.A == offset && r.B == r.A+1 {
		r.B--
	}
	return r
}
开发者ID:jiyeyuran,项目名称:util,代码行数:56,代码来源:buffer.go

示例13: File

func (fs *SubFileSystem) File(subPath string) File {
	if strings.HasPrefix(subPath, fs.Prefix()) || strings.HasPrefix(subPath, "..") || strings.ContainsRune(subPath, ':') {
		panic("invalid subPath for SubFileSystem: " + subPath)
	}
	cleanedPath := filepath.Clean(subPath)
	if cleanedPath == "/" || strings.ContainsRune(cleanedPath, ':') {
		panic("invalid subPath for SubFileSystem: " + subPath)
	}
	return fs.Parent.File(filepath.Join(fs.BasePath, cleanedPath))
}
开发者ID:ungerik,项目名称:go-fs,代码行数:10,代码来源:subfilesystem.go

示例14: Tokenize

func Tokenize(code []byte) []Token {
	tokens := make([]Token, 0)
	token := ""
	state := S_DUNNO
	for i := 0; i < len(code); i++ {
		r := rune(code[i])
		cut := false
		if state == S_DUNNO {
			if strings.ContainsRune("0123456789", r) {
				state = S_INTEGER
			} else if strings.ContainsRune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", r) {
				state = S_IDENTIFIER
			} else if strings.ContainsRune("()", r) {
				state = S_PARANTHESES
			} else if strings.ContainsRune("+-*/=^", r) {
				state = S_OP
			} else if strings.ContainsRune(",", r) {
				state = S_COMMA
			}
		} else if state == S_INTEGER {
			if strings.ContainsRune("0123456789", r) {
				state = S_INTEGER
			} else if strings.ContainsRune(".", r) {
				state = S_FLOAT
			} else {
				cut = true
			}
		} else if state == S_FLOAT {
			if strings.ContainsRune("0123456789", r) {
				state = S_FLOAT
			} else {
				cut = true
			}
		} else if state == S_IDENTIFIER {
			if strings.ContainsRune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", r) {
				state = S_IDENTIFIER
			} else {
				cut = true
			}
		} else if state == S_PARANTHESES {
			cut = true
		} else if state == S_OP {
			cut = true
		} else if state == S_COMMA {
			cut = true
		}
		if cut {
			tokens = append(tokens, Token{state, token})
			state = S_DUNNO
			token = ""
			cut = false
			i--
		} else {
			if state != S_DUNNO {
				token += string(r)
			}
		}
	}
	return tokens
}
开发者ID:irth,项目名称:notecalc,代码行数:60,代码来源:eval.go

示例15: TestTransformerTagsOff

func TestTransformerTagsOff(t *testing.T) {
	t.Parallel()
	for _, k := range []string{"tags", "less-than", "greater-than", "script"} {
		tname := k
		v := samples[k]
		res := Transform(v, TagCharsOff)
		if strings.ContainsRune(res, 0x3c) || strings.ContainsRune(res, 0x3e) {
			t.Errorf("Error in transform of %s: no wanted replacement in the result [[%s]] (original: %s)\n", tname, res, v)
		}
	}
}
开发者ID:optimuse,项目名称:webseclab,代码行数:11,代码来源:transform_test.go


注:本文中的strings.ContainsRune函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。