OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [encoding/] [json/] [tags.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package json
6
 
7
import (
8
        "strings"
9
)
10
 
11
// tagOptions is the string following a comma in a struct field's "json"
12
// tag, or the empty string. It does not include the leading comma.
13
type tagOptions string
14
 
15
// parseTag splits a struct field's json tag into its name and
16
// comma-separated options.
17
func parseTag(tag string) (string, tagOptions) {
18
        if idx := strings.Index(tag, ","); idx != -1 {
19
                return tag[:idx], tagOptions(tag[idx+1:])
20
        }
21
        return tag, tagOptions("")
22
}
23
 
24
// Contains returns whether checks that a comma-separated list of options
25
// contains a particular substr flag. substr must be surrounded by a
26
// string boundary or commas.
27
func (o tagOptions) Contains(optionName string) bool {
28
        if len(o) == 0 {
29
                return false
30
        }
31
        s := string(o)
32
        for s != "" {
33
                var next string
34
                i := strings.Index(s, ",")
35
                if i >= 0 {
36
                        s, next = s[:i], s[i+1:]
37
                }
38
                if s == optionName {
39
                        return true
40
                }
41
                s = next
42
        }
43
        return false
44
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.