// Moves to the beginning or end of a space delimited word
182628
func (state *TextEditor) tospc(start int, dir int) int {
	return state.tof(start, dir, unicode.IsSpace)
}
913976
func (d *Document) FindStartOfPreviousWordUntilSeparator(sep string) int {
	if sep == "" {
		return d.FindStartOfPreviousWord()
	}

	x := d.TextBeforeCursor()
	i := strings.LastIndexAny(x, sep)
	if i != -1 {
		return i + 1
	}
	return 0
}
1216457
func positionAfterWhitespace(body []byte, startPosition int) (position int, runePosition int) {
	bodyLength := len(body)
	position = startPosition
	runePosition = startPosition
	for {
		if position < bodyLength {
			code, n := runeAt(body, position)

			// Skip Ignored
			if code == 0xFEFF || // BOM
				// White Space
				code == 0x0009 || // tab
				code == 0x0020 || // space
				// Line Terminator
				code == 0x000A || // new line
				code == 0x000D || // carriage return
				// Comma
				code == 0x002C {
				position += n
				runePosition++
			} else if code == 35 { // #
				position += n
				runePosition++
				for {
					code, n := runeAt(body, position)
					if position < bodyLength &&
						code != 0 &&
						// SourceCharacter but not LineTerminator
						(code > 0x001F || code == 0x0009) && code != 0x000A && code != 0x000D {
						position += n
						runePosition++
						continue
					} else {
						break
					}
				}
			} else {
				break
			}
			continue
		} else {
			break
		}
	}
	return position, runePosition
}
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
}
546357
func (z *Lexer) Lexeme() []byte {
	return z.buf[z.start:z.pos]
}
563360
func (z *StreamLexer) Lexeme() []byte {
	return z.buf[z.start:z.pos]
}
1335216
func (r *TranscribedRecipe) Less(i, j int) bool {
	a, b := (*r)[i].Region, (*r)[j].Region
	if a.Begin() == b.Begin() {
		return a.End() < b.End()
	}
	return a.Begin() < b.Begin()
}
1022536
func splitspace(s string, max int) []string {
	var res []string
	start := -1 // index of field start, or -1 in a region of spaces
	for i, r := range s {
		if unicode.IsSpace(r) {
			if start >= 0 {
				if len(res) == max {
					break // let this field run to the end
				}
				res = append(res, s[start:i])
				start = -1
			}
		} else if start == -1 {
			start = i
		}
	}
	if start >= 0 {
		res = append(res, s[start:])
	}
	return res
}
277261
func TrimTrailingSpaces(p []byte) []byte {
	for i := len(p) - 1; i >= 0; i-- {
		if p[i] != 0x20 && p[i] != '\n' && p[i] != '\t' {
			return p[:i+1]
		}
	}
	// it was all spaces
	return p[:0]
}
862308
func (v *VerbalExpression) EndOfLine() *VerbalExpression {
	if !strings.HasSuffix(v.suffixes, "$") {
		v.suffixes += "$"
	}
	return v
}
163551
func (l *Lexer) Remainder() (string, bool) {
	l.SkipWhiteSpaces()
	if r := l.Peek(); r == ';' {
		l.Next()
	}
	l.SkipWhiteSpaces()
	if l.pos >= len(l.input) {
		return "", false
	}
	input := l.input[l.pos:]
	if len(input) < 5 {
		return "", false
	}
	return input, true
}
866799
func (l *lexer) eatSpaceAndComments() rune {
	for {
		n := l.next()
		if n == '#' {
			l.acceptLine(false)
			l.emit(itemComment)
		} else if any(n, whitespace) {
			l.acceptRun(whitespace)
			l.emit(itemSpace)
		} else {
			return n
		}
	}
}
671125
func doBreakWords(words []string, limit int) []string {
	var result []string

	for _, word := range words {
		if len(word) > limit {
			var parts []string
			var partBuf bytes.Buffer

			for _, char := range word {
				atLimit := partBuf.Len() == limit

				if atLimit {
					parts = append(parts, partBuf.String())

					partBuf.Reset()
				}

				partBuf.WriteRune(char)
			}

			if partBuf.Len() > 0 {
				parts = append(parts, partBuf.String())
			}

			for _, part := range parts {
				result = append(result, part)
			}
		} else {
			result = append(result, word)
		}
	}

	return result
}
1223447
func (l *lexer) whitespace() ([]rune, Error) {
	// read until we hit the first non-whitespace rune
	_ws := make([]rune, 0, 1)

	// loop until there's nothing more to do
	for {
		_next, _err := l.read()
		if _err != nil {
			return _ws, _err
		}

		// what is this next rune?
		switch _next {
		// space or tab is consumed
		case _SPACE:
			fallthrough
		case _TAB:
			break

		// non-whitespace rune
		default:
			// return the rune to the buffer and we're done
			l.unread(_next)
			return _ws, nil
		}

		// add this rune to the whitespace
		_ws = append(_ws, _next)
	}
}
601867
func (p *Lexer) End() bool {
	c, err := p.Byte()

	if err != nil {
		return true
	}

	if IsEndChar(c) {
		return true
	}
	p.UnreadByte()
	return false
}
6222
func (l *lexer) next() rune {
	if int(l.pos.byteNo) >= len(l.input) {
		l.prev = l.pos
		return lexEOF
	}
	r, w := utf8.DecodeRuneInString(l.input[l.pos.byteNo:])
	l.prev = l.pos
	l.pos.byteNo += w
	if r == '\n' {
		l.pos.lineStart = l.pos.byteNo
		l.pos.lineNo++
		l.freshLine = true
	} else if l.freshLine {
		if !isWhitespace(r) {
			l.freshLine = false
		}
	}
	return r
}
796924
func removeSpaceAndSuffix(line string) string {
	parts := strings.Split(line, " ")
	return strings.Join(parts[:len(parts)-1], " ")
}