//Scans contents of [] (not including []'s), and converts to a set.
330701
func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) {
	ch := '\x00'
	chPrev := '\x00'
	inRange := false
	firstChar := true
	closed := false

	var cc *CharSet
	if !scanOnly {
		cc = &CharSet{}
	}

	if p.charsRight() > 0 && p.rightChar(0) == '^' {
		p.moveRight(1)
		if !scanOnly {
			cc.negate = true
		}
	}

	for ; p.charsRight() > 0; firstChar = false {
		fTranslatedChar := false
		ch = p.moveRightGetChar()
		if ch == ']' {
			if !firstChar {
				closed = true
				break
			} else if p.useOptionE() {
				if !scanOnly {
					cc.addRanges(NoneClass().ranges)
				}
				closed = true
				break
			}

		} else if ch == '\\' && p.charsRight() > 0 {
			switch ch = p.moveRightGetChar(); ch {
			case 'D', 'd':
				if !scanOnly {
					if inRange {
						return nil, p.getErr(ErrBadClassInCharRange, ch)
					}
					cc.addDigit(p.useOptionE(), ch == 'D', p.patternRaw)
				}
				continue

			case 'S', 's':
				if !scanOnly {
					if inRange {
						return nil, p.getErr(ErrBadClassInCharRange, ch)
					}
					cc.addSpace(p.useOptionE(), ch == 'S')
				}
				continue

			case 'W', 'w':
				if !scanOnly {
					if inRange {
						return nil, p.getErr(ErrBadClassInCharRange, ch)
					}

					cc.addWord(p.useOptionE(), ch == 'W')
				}
				continue

			case 'p', 'P':
				if !scanOnly {
					if inRange {
						return nil, p.getErr(ErrBadClassInCharRange, ch)
					}
					prop, err := p.parseProperty()
					if err != nil {
						return nil, err
					}
					cc.addCategory(prop, (ch != 'p'), caseInsensitive, p.patternRaw)
				} else {
					p.parseProperty()
				}

				continue

			case '-':
				if !scanOnly {
					cc.addRange(ch, ch)
				}
				continue

			default:
				p.moveLeft()
				var err error
				ch, err = p.scanCharEscape() // non-literal character
				if err != nil {
					return nil, err
				}
				fTranslatedChar = true
				break // this break will only break out of the switch
			}
		} else if ch == '[' {
			// This is code for Posix style properties - [:Ll:] or [:IsTibetan:].
			// It currently doesn't do anything other than skip the whole thing!
			if p.charsRight() > 0 && p.rightChar(0) == ':' && !inRange {
				savePos := p.textpos()

				p.moveRight(1)
				p.scanCapname() // throwaway the name
				if p.charsRight() < 2 || p.moveRightGetChar() != ':' || p.moveRightGetChar() != ']' {
					p.textto(savePos)
				}
				// else lookup name (nyi)
			}
		}

		if inRange {
			inRange = false
			if !scanOnly {
				if ch == '[' && !fTranslatedChar && !firstChar {
					// We thought we were in a range, but we're actually starting a subtraction.
					// In that case, we'll add chPrev to our char class, skip the opening [, and
					// scan the new character class recursively.
					cc.addChar(chPrev)
					sub, err := p.scanCharSet(caseInsensitive, false)
					if err != nil {
						return nil, err
					}
					cc.addSubtraction(sub)

					if p.charsRight() > 0 && p.rightChar(0) != ']' {
						return nil, p.getErr(ErrSubtractionMustBeLast)
					}
				} else {
					// a regular range, like a-z
					if chPrev > ch {
						return nil, p.getErr(ErrReversedCharRange)
					}
					cc.addRange(chPrev, ch)
				}
			}
		} else if p.charsRight() >= 2 && p.rightChar(0) == '-' && p.rightChar(1) != ']' {
			// this could be the start of a range
			chPrev = ch
			inRange = true
			p.moveRight(1)
		} else if p.charsRight() >= 1 && ch == '-' && !fTranslatedChar && p.rightChar(0) == '[' && !firstChar {
			// we aren't in a range, and now there is a subtraction.  Usually this happens
			// only when a subtraction follows a range, like [a-z-[b]]
			if !scanOnly {
				p.moveRight(1)
				sub, err := p.scanCharSet(caseInsensitive, false)
				if err != nil {
					return nil, err
				}
				cc.addSubtraction(sub)

				if p.charsRight() > 0 && p.rightChar(0) != ']' {
					return nil, p.getErr(ErrSubtractionMustBeLast)
				}
			} else {
				p.moveRight(1)
				p.scanCharSet(caseInsensitive, true)
			}
		} else {
			if !scanOnly {
				cc.addRange(ch, ch)
			}
		}
	}

	if !closed {
		return nil, p.getErr(ErrUnterminatedBracket)
	}

	if !scanOnly && caseInsensitive {
		cc.addLowercase()
	}

	return cc, nil
}
202527
func (h HTTPOrigin) Scan() (HashSet, string, error) {
	data, err := h.Get(PatchFile)
	if err != nil {
		log.Warning("http scan:", err)
		return HashSet{}, "", err
	}
	items, source := Parse(string(data))
	log.Notice("fetched", len(items), "from http origin")
	return items, source, nil
}
607677
func (s *set) List() []interface{} {
	list := make([]interface{}, 0, len(s.m))

	for item := range s.m {
		list = append(list, item)
	}

	return list
}
1359344
func (a *StringArray) Scan(value interface{}) error {
	if value == nil {
		*a = nil
		return nil
	}

	var b []byte
	switch v := value.(type) {
	case []byte:
		b = v
	case string:
		b = []byte(v)
	default:
		return fmt.Errorf("StringArray.Scan: expected []byte or string, got %T (%q)", value, value)
	}

	if len(b) < 2 || b[0] != '{' || b[len(b)-1] != '}' {
		return fmt.Errorf("StringArray.Scan: unexpected data %q", b)
	}

	// reuse underlying array if present
	if *a == nil {
		*a = make(StringArray, 0)
	}
	*a = (*a)[:0]

	if len(b) == 2 { // '{}'
		return nil
	}

	reader := bytes.NewReader(b[1 : len(b)-1]) // skip '{' and '}'

	// helper function to read next rune and check if it valid
	readRune := func() (rune, error) {
		r, _, err := reader.ReadRune()
		if err != nil {
			return 0, err
		}
		if r == unicode.ReplacementChar {
			return 0, fmt.Errorf("StringArray.Scan: invalid rune")
		}
		return r, nil
	}

	var q bool
	var e []rune
	for {
		// read next rune and check if we are done
		r, err := readRune()
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}

		switch r {
		case '"':
			// enter or leave quotes
			q = !q
			continue
		case ',':
			// end of element unless in we are in quotes
			if !q {
				*a = append(*a, string(e))
				e = e[:0]
				continue
			}
		case '\\':
			// skip to next rune, it should be present
			n, err := readRune()
			if err != nil {
				return err
			}
			r = n
		}

		e = append(e, r)
	}

	// we should not be in quotes at this point
	if q {
		panic("StringArray.Scan bug")
	}

	// add last element
	*a = append(*a, string(e))
	return nil
}
857525
func ReadLines(fileName string) ([]string, error) {
	file, err := os.Open(fileName)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	scanner := bufio.NewScanner(file)
	var lines []string
	for scanner.Scan() {
		lines = append(lines, scanner.Text())
	}
	return lines, scanner.Err()
}
473027
func (set StringSet) Contains(i string) bool {
	_, found := set[i]
	return found
}
529532
func (rs *ResultSet) Values() Values {
	values := []Value{}
	for _, item := range rs.items {
		switch i := item.(type) {
		case Value:
			values = append(values, i)
		case *ResultSet:
			values = append(values, i.Values()...)
		}
	}
	return values
}
1339650
func ReadSet(iname, lname string) (set *Set, err error) {
	set = &Set{}
	if set.NRow, set.NCol, set.Images, err = ReadImageFile(iname); err != nil {
		return nil, err
	}
	if set.Labels, err = ReadLabelFile(lname); err != nil {
		return nil, err
	}
	return
}
450248
func (setting *Setting) Scan(value interface{}) error {
	if bytes, ok := value.([]byte); ok {
		json.Unmarshal(bytes, setting)
	} else if str, ok := value.(string); ok {
		json.Unmarshal([]byte(str), setting)
	} else if strs, ok := value.([]string); ok {
		for _, str := range strs {
			json.Unmarshal([]byte(str), setting)
		}
	}
	return nil
}
482545
func ParseSeqSet(set string) (s *SeqSet, err error) {
	s = new(SeqSet)
	return s, s.Add(set)
}
592324
func scan(s string) <-chan match {
	ch := make(chan match)
	go func() {
		depth := 0
		opener := 0
		for index, char := range s {
			switch char {
			case '(':
				if depth == 0 {
					opener = index
				}
				depth++
			case ')':
				depth--
				if depth == 0 {
					ch <- match{
						openPos:  opener,
						closePos: index + 1,
					}
				}
			}

		}
		close(ch)
	}()
	return ch
}
576983
func ContainsStrings(coll []string, item string) bool {
	for _, a := range coll {
		if a == item {
			return true
		}
	}
	return false
}
1283683
func (ss *StringSlice) Scan(src interface{}) error {
	buf, ok := src.([]byte)
	if !ok {
		return errors.New("invalid StringSlice")
	}

	// change quote escapes for csv parser
	str := quoteEscapeRegex.ReplaceAllString(string(buf), `$1""`)
	str = strings.Replace(str, `\\`, `\`, -1)

	// remove braces
	str = str[1 : len(str)-1]

	// bail if only one
	if len(str) == 0 {
		*ss = StringSlice([]string{})
		return nil
	}

	// parse with csv reader
	cr := csv.NewReader(strings.NewReader(str))
	slice, err := cr.Read()
	if err != nil {
		fmt.Printf("exiting!: %v\n", err)
		return err
	}

	*ss = StringSlice(slice)

	return nil
}
1078511
func (s *Set) Contains(key interface{}) bool {
	_, ok := s.skiplist.Get(key)
	return ok
}
254608
func (s *OrderedSet) Contains(i string) bool {
	if _, ok := s.m[i]; ok {
		return true
	}
	return false
}
403898
func (s IntSet) List() []int {
	res := make([]int, 0, len(s))
	for key := range s {
		res = append(res, key)
	}
	sort.IntSlice(res).Sort()
	return res
}
1033485
func (s *Set) ToStrings() []string {
	if s.IsEmpty() {
		return nil
	}
	if s.All {
		return []string{"*"}
	}
	out := make([]string, 0, len(s.IDs)+len(s.Groups))
	for ident := range s.IDs {
		out = append(out, string(ident))
	}
	for group := range s.Groups {
		out = append(out, "group:"+group)
	}
	sort.Strings(out)
	return out
}