// cutNewLines() pares down a string to the part before the first "\r" or "\n".
321208
func cutNewLines(s string) string {
	r := strings.SplitN(s, "\r", 2)
	r = strings.SplitN(r[0], "\n", 2)
	return r[0]
}
28488
func stringSliceContains(slice []string, value string) bool {
	for _, elem := range slice {
		if elem == value {
			return true
		}
	}
	return false
}
1293655
func splitSpecial(s string, delimiter string, cutdelimiter bool) (string, string) {
	i := strings.Index(s, delimiter)
	if i < 0 {
		// if delimiter not found return as is.
		return s, ""
	}
	// if delimiter should be removed, remove it.
	if cutdelimiter {
		return s[0:i], s[i+len(delimiter):]
	}
	// return split strings with delimiter
	return s[0:i], s[i:]
}
296433
func (b *Buffer) JoinNextLine(separator string) {
	if !b.Document().OnLastLine() {
		b.cursorPosition += b.Document().GetEndOfLinePosition()
		b.Delete(1)
		// Remove spaces
		b.setText(b.Document().TextBeforeCursor() + separator + strings.TrimLeft(b.Document().TextAfterCursor(), " "))
	}
}
583833
func NewStringLexer(input string, fn LexFn) *StringLexer {
	return &StringLexer{
		input:       input,
		inputLength: len(input),
		start:       0,
		pos:         0,
		line:        1,
		width:       0,
		items:       make(chan LexItem, 1),
		entryPoint:  fn,
	}
}
305589
func trim(chunk string) (string, string, string) {
	code := strings.TrimSpace(chunk)
	wsl := chunk[:strings.Index(chunk, code)]
	wsr := chunk[len(wsl)+len(code):]
	return wsl, code, wsr
}
777044
func (l *Lexer) SkipWhiteSpaces() {
	for rune := l.Next(); unicode.IsSpace(rune); rune = l.Next() {
		if rune == '\n' {
			// New line, lets keep track of line position
			l.line++
			l.linepos = l.pos
		}
	}
	l.backup()
	l.ignore()
}
1180648
func ParseLines(r io.Reader) ([]*Line, string, error) {
	var lines []*Line

	splitter := &lineEndingSplitter{}

	scanner := bufio.NewScanner(r)
	scanner.Split(splitter.ScanLines)
	for scanner.Scan() {
		text := strings.TrimSpace(scanner.Text())
		if len(text) == 0 {
			continue
		}

		var pattern string
		var applied string
		var macro string

		switch text[0] {
		case '#':
			continue
		case '"':
			var err error
			last := strings.LastIndex(text, "\"")
			if last == 0 {
				return nil, "", errors.Errorf("git/gitattr: unbalanced quote: %s", text)
			}
			pattern, err = strconv.Unquote(text[:last+1])
			if err != nil {
				return nil, "", errors.Wrapf(err, "git/gitattr")
			}
			applied = strings.TrimSpace(text[last+1:])
		default:
			splits := strings.SplitN(text, " ", 2)

			if strings.HasPrefix(splits[0], attrPrefix) {
				macro = splits[0][len(attrPrefix):]
			} else {
				pattern = splits[0]
			}
			if len(splits) == 2 {
				applied = splits[1]
			}
		}

		var attrs []*Attr

		for _, s := range strings.Split(applied, " ") {
			if s == "" {
				continue
			}

			var attr Attr

			if strings.HasPrefix(s, "-") {
				attr.K = strings.TrimPrefix(s, "-")
				attr.V = "false"
			} else if strings.HasPrefix(s, "!") {
				attr.K = strings.TrimPrefix(s, "!")
				attr.Unspecified = true
			} else if eq := strings.Index(s, "="); eq > -1 {
				attr.K = s[:eq]
				attr.V = s[eq+1:]
			} else {
				attr.K = s
				attr.V = "true"
			}

			attrs = append(attrs, &attr)
		}

		var matchPattern *wildmatch.Wildmatch
		if pattern != "" {
			matchPattern = wildmatch.NewWildmatch(pattern,
				wildmatch.Basename, wildmatch.SystemCase,
			)
		}

		lines = append(lines, &Line{
			Macro:   macro,
			Pattern: matchPattern,
			Attrs:   attrs,
		})
	}

	if err := scanner.Err(); err != nil {
		return nil, "", err
	}
	return lines, splitter.LineEnding(), nil
}
577739
func StripLow(str string, keepNewLines bool) string {
	chars := ""
	if keepNewLines {
		chars = "\x00-\x09\x0B\x0C\x0E-\x1F\x7F"
	} else {
		chars = "\x00-\x1F\x7F"
	}
	return BlackList(str, chars)
}
600758
func SplitWithNewlines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	return split(true, data, atEOF)
}
1148791
func TrimStrings(items []string) []string {
	ret := make([]string, len(items))
	for i, item := range items {
		ret[i] = strings.TrimSpace(item)
	}
	return ret
}
566313
func (v *View) EditNewLine() {
	v.breakLine(v.cx, v.cy)
	v.ox = 0
	v.cx = 0
	v.MoveCursor(0, 1, true)
}
118083
func (t *Tree) elideNewline() Node {
	token := t.peek()
	if token.typ != itemText {
		t.unexpected(token, "input")
		return nil
	}

	t.next()
	stripped := strings.TrimLeft(token.val, "\n\r")
	diff := len(token.val) - len(stripped)
	if diff > 0 {
		// This is a bit nasty. We mutate the token in-place to remove
		// preceding newlines.
		token.pos += Pos(diff)
		token.val = stripped
	}
	return t.newText(token.pos, token.val)
}
137403
func (d *Document) lineStartIndexes() []int {
	// TODO: Cache, because this is often reused.
	// (If it is used, it's often used many times.
	// And this has to be fast for editing big documents!)
	lc := d.LineCount()
	lengths := make([]int, lc)
	for i, l := range d.Lines() {
		lengths[i] = len(l)
	}

	// Calculate cumulative sums.
	indexes := make([]int, lc+1)
	indexes[0] = 0 // https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/document.py#L189
	pos := 0
	for i, l := range lengths {
		pos += l + 1
		indexes[i+1] = pos
	}
	if lc > 1 {
		// Pop the last item. (This is not a new line.)
		indexes = indexes[:lc]
	}
	return indexes
}
403676
func TrimStartSpaceEmptyLine(src string) (result string, err error) {
	lines := strings.Split(src, "\n")
	buffer := bytes.Buffer{}
	for _, line := range lines {
		if !regexpStartSpaceEmptyLine.MatchString(line) {
			if _, err = buffer.WriteString(line + "\n"); err != nil {
				return
			}
		}
	}
	return buffer.String(), nil
}
528304
func (l *StringLexer) Next() (r rune) {
	if l.pos >= l.inputLen() {
		l.width = 0
		return EOF
	}

	// if the previous char was a new line, then we're at a new line
	if l.pos >= 0 {
		if l.input[l.pos] == '\n' {
			l.line++
		}
	}

	r, l.width = utf8.DecodeRuneInString(l.input[l.pos:])
	l.pos += l.width
	return r
}
1169519
func (a NetworkAddresses) StringSlice() []string {
	var res []string
	for _, el := range a {
		res = append(res, el)
	}
	return res
}