// Space is (0x20|0x09)+. It returns a boolean indicating
// if space has been found, and an integer indicating
// how many spaces, iff uniform (either all 0x20 or 0x09)
359287
func (p *Lexer) Space() (int, byte) {

	// Need a bufio that unreads many bytes for the Block case

	n := 0
	m := 0

	for {
		c, _ := p.Byte()
		if c != '\t' && c != ' ' {
			break
		}
		if c == ' ' {
			n++
		} else {
			m++
		}

	}

	p.UnreadByte()

	var r byte
	if m == 0 {
		r = ' '
	} else if n == 0 {
		r = '\t'
	}

	return n + m, r
}
1108665
func (s *Scanner) InitWhitespace(w string) {
	s.Whitespace = datastructs.NewBitSet(256)
	for _, c := range w {
		s.Whitespace.Set(int(c))
	}
}
697209
func (l *lexer) lexWhitespace() (int, int) {
	r := l.next()
	indent := 0
	newLines := 0
	for ; isWhitespace(r); r = l.next() {
		switch r {
		case '\r':
			// Ignore.
			break

		case '\n':
			indent = 0
			newLines++
			break

		case ' ':
			indent++
			break

		// This only works for \t at the beginning of lines, but we strip it everywhere else
		// anyway.  The only case where this will cause a problem is spaces followed by \t
		// at the beginning of a line.  However that is rare, ill-advised, and if re-indentation
		// is enabled it will be fixed later.
		case '\t':
			indent += 8
			break
		}
	}
	l.backup()
	return newLines, indent
}
921583
func TrimLeadingSpaces(p []byte) []byte {
	for i := 0; i < len(p); i++ {
		if p[i] != 0x20 && p[i] != '\t' {
			return p[i:]
		}
	}
	// it was all spaces
	return p[:0]
}
1108374
func (s *Service) SpaceDelete(ctx context.Context, spaceIdentity string) (*Space, error) {
	var space Space
	return &space, s.Delete(ctx, &space, fmt.Sprintf("/spaces/%v", spaceIdentity))
}
877500
func (q *Query) Keyspace() string {
	if q.session == nil {
		return ""
	}
	// TODO(chbannis): this should be parsed from the query or we should let
	// this be set by users.
	return q.session.cfg.Keyspace
}
796835
func (a Dimensions) String() string {
	var str []string
	for _, d := range a {
		str = append(str, d.String())
	}
	return strings.Join(str, ", ")
}
881951
func (s *scanner) SkipSpaces() (rune, bool) {
	r, ok := s.Next()
	for unicode.IsSpace(r) && ok {
		r, ok = s.Next()
	}
	return r, ok
}
689046
func (p Space) Equal(u convert.Equaler) bool {
	other, ok := u.(Space)
	if !ok {
		return false
	}
	if !p.Lifecycle.Equal(other.Lifecycle) {
		return false
	}
	if p.ID != other.ID {
		return false
	}
	if p.Version != other.Version {
		return false
	}
	if p.Name != other.Name {
		return false
	}
	if !uuid.Equal(p.SpaceTemplateID, other.SpaceTemplateID) {
		return false
	}
	if p.Description != other.Description {
		return false
	}
	if !uuid.Equal(p.OwnerID, other.OwnerID) {
		return false
	}
	return true
}
762821
func (st *State) AddSpace(name string, providerId network.Id, subnets []string, isPublic bool) (newSpace *Space, err error) {
	defer errors.DeferredAnnotatef(&err, "adding space %q", name)
	if !names.IsValidSpace(name) {
		return nil, errors.NewNotValid(nil, "invalid space name")
	}

	spaceDoc := spaceDoc{
		Life:       Alive,
		Name:       name,
		IsPublic:   isPublic,
		ProviderId: string(providerId),
	}
	newSpace = &Space{doc: spaceDoc, st: st}

	ops := []txn.Op{{
		C:      spacesC,
		Id:     name,
		Assert: txn.DocMissing,
		Insert: spaceDoc,
	}}

	if providerId != "" {
		ops = append(ops, st.networkEntityGlobalKeyOp("space", providerId))
	}

	for _, subnetId := range subnets {
		// TODO:(mfoord) once we have refcounting for subnets we should
		// also assert that the refcount is zero as moving the space of a
		// subnet in use is not permitted.
		ops = append(ops, txn.Op{
			C:      subnetsC,
			Id:     subnetId,
			Assert: bson.D{bson.DocElem{"fan-local-underlay", bson.D{{"$exists", false}}}},
			Update: bson.D{{"$set", bson.D{{"space-name", name}}}},
		})
	}

	if err := st.db().RunTransaction(ops); err == txn.ErrAborted {
		if _, err := st.Space(name); err == nil {
			return nil, errors.AlreadyExistsf("space %q", name)
		}
		for _, subnetId := range subnets {
			subnet, err := st.Subnet(subnetId)
			if errors.IsNotFound(err) {
				return nil, err
			}
			if subnet.FanLocalUnderlay() != "" {
				return nil, errors.Errorf("Can't set space for FAN subnet %q - it's always inherited from underlay", subnet.CIDR())
			}
		}
		if err := newSpace.Refresh(); err != nil {
			if errors.IsNotFound(err) {
				return nil, errors.Errorf("ProviderId %q not unique", providerId)
			}
			return nil, errors.Trace(err)
		}
		return nil, errors.Trace(err)
	} else if err != nil {
		return nil, err
	}
	return newSpace, nil
}
252787
func LastIndexNonSpace(s string) int {
	for i := len(s) - 1; i >= 0; i-- {
		if !unibyte.IsSpace(s[i]) {
			return i
		}
	}

	return -1
}
954540
func IsInt(s string) bool {
	for i, c := range s {
		if (c < '0' || c > '9') && (c != '-' || i != 0) {
			return false
		}
	}
	return true
}
876877
func (l *lexer) maybeSpace() rune {
	for {
		n := l.next()
		if any(n, whitespace) {
			l.acceptRun(whitespace)
			l.emit(itemSpace)
		} else {
			return n
		}
	}
}
105859
func Linspace(lo, hi float64, num int) []float64 {
	res := make([]float64, num)
	if num == 1 {
		res[0] = lo
		return res
	}
	for i := 0; i < num; i++ {
		res[i] = lo + float64(i)*(hi-lo)/float64(num-1)
	}
	return res
}
1310146
func leadingWhitespaceLen(in string) (n int) {
	for _, ch := range in {
		if ch == ' ' || ch == '\t' {
			n++
		} else {
			break
		}
	}
	return
}
1229881
func allSpaceWithNewline(str string) bool {
	var seenNewline = false
	for _, ch := range str {
		if !unicode.IsSpace(ch) {
			return false
		}
		if isEndOfLine(ch) {
			seenNewline = true
		}
	}
	return seenNewline
}
1020464
func TrimWhitespace(b []byte) []byte {
	n := len(b)
	start := n
	for i := 0; i < n; i++ {
		if !IsWhitespace(b[i]) {
			start = i
			break
		}
	}
	end := n
	for i := n - 1; i >= start; i-- {
		if !IsWhitespace(b[i]) {
			end = i + 1
			break
		}
	}
	return b[start:end]
}