// Strip newlines and spaces around newlines.
770524
func trimAroundNewlines(v []byte) string {
	var b strings.Builder
	for {
		i := bytes.IndexByte(v, '\n')
		if i < 0 {
			writeContinued(&b, v)
			break
		}
		writeContinued(&b, v[:i])
		v = v[i+1:]
	}

	return b.String()
}
876575
func (l *Lexer) SkipWhiteSpacesNewLine() bool {
	rune := l.Next()
	hasNewLine := false
	for {
		if rune == '\n' {
			hasNewLine = true
			// New line, lets keep track of line position
			l.line++
			l.linepos = 0
		} else if !unicode.IsSpace(rune) {
			break
		}
		rune = l.Next()
	}
	l.backup()
	l.ignore()
	return hasNewLine
}
1210720
func (pctx *parseCtx) skipWhiteSpaces() {
	for {
		switch t := pctx.peek(); t.Type {
		case SPACE, COMMENT_IDENT:
			pctx.advance()
			continue
		default:
			return
		}
	}
}
1051749
func StripFormat(s string) string {
	r := regexp.MustCompile(reFormat)
	return r.ReplaceAllString(s, "")
}
1281900
func Clean(s string) string {
	return replace(func(r rune) rune {
		if r >= 32 && r != 127 { // Values below 32 (and 127) are special non printing characters (i.e. DEL, ESC, carriage return).
			return r
		} else if r == '\n' || r == '\t' { // Allow newlines and tabs.
			return r
		} else if r == rune(keyEscape) {
			// Start of a vt100 escape sequence. If not a color, we will
			// substitute it with '^[' (this is how it is usually shown, i.e.
			// in vim).
			return -1
		}
		return -2
	}, s)
}
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
		}
	}
}
60127
func StripComments(file []byte) []byte {
	stripped := file
	stripped, err := yaml.ToJSON(stripped)
	if err != nil {
		stripped = ManualStrip(file)
	}
	return stripped
}
1252959
func StripDefaultNS(v string) string {
	if idx := strings.IndexByte(v, '/'); idx > 0 {
		if v[:idx] == api.IntentionDefaultNamespace {
			return v[:idx+1]
		}
	}

	return v
}
1167978
func TrimSpaceSlice(a []string) []string {
	other := make([]string, 0, len(a))
	for _, s := range a {
		s = strings.TrimSpace(s)
		if s == "" {
			continue
		}
		other = append(other, s)
	}
	return other
}
209667
func NewLine(args ...interface{}) Composer {
	m := &lineMessenger{}
	for _, arg := range args {
		if arg != nil {
			m.lines = append(m.lines, arg)
		}
	}

	return m
}
486521
func (z *Tokenizer) skipWhiteSpace() {
	if z.err != nil {
		return
	}
	for {
		c := z.readByte()
		if z.err != nil {
			return
		}
		switch c {
		case ' ', '\n', '\r', '\t', '\f':
			// No-op.
		default:
			z.raw.end--
			return
		}
	}
}
132348
func cleanListing(text string) string {
	lines := strings.Split(text, "\n")

	// remove minimum number of leading tabs from all non-blank lines
	tabs := 999
	for i, line := range lines {
		if strings.TrimSpace(line) == "" {
			lines[i] = ""
		} else {
			if n := leadingTabs(line); n < tabs {
				tabs = n
			}
		}
	}
	for i, line := range lines {
		if line != "" {
			line := line[tabs:]
			lines[i] = line // remove leading tabs
		}
	}

	// remove leading blank lines
	for len(lines) > 0 && lines[0] == "" {
		lines = lines[1:]
	}
	// remove trailing blank lines
	for len(lines) > 0 && lines[len(lines)-1] == "" {
		lines = lines[:len(lines)-1]
	}
	return strings.Join(lines, "\n")
}
758818
func stripNewline(buf []byte) []byte {
	if n := len(buf); n > 0 {
		if n > 1 && buf[n-2] == '\r' {
			return buf[:n-2]
		}
		if buf[n-1] == '\n' {
			return buf[:n-1]
		}
	}
	return buf
}
1181400
func manualStrip(file []byte) []byte {
	stripped := []byte{}
	for _, line := range bytes.Split(file, []byte("\n")) {
		if bytes.HasPrefix(bytes.TrimSpace(line), []byte("#")) {
			continue
		}
		stripped = append(stripped, line...)
		stripped = append(stripped, '\n')
	}
	return stripped
}
376592
func stripBraces(str string) string {
	bs := []byte(str)
	const lb = byte('{')
	const rb = byte('}')
	start := 0
	for i := 0; i < len(bs); i++ {
		switch bs[i] {
		case lb:
			start = i + 1
		case rb:
			return `\$` + str[start:i]
		}
	}
	return str[start:]
}
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
}
416298
func trimSpaces(k AST) AST {
	// trim left hand side of spaces
	for i := 0; i < len(k.Root.raw); i++ {
		if !isWhitespace(k.Root.raw[i]) {
			break
		}

		k.Root.raw = k.Root.raw[1:]
		i--
	}

	// trim right hand side of spaces
	for i := len(k.Root.raw) - 1; i >= 0; i-- {
		if !isWhitespace(k.Root.raw[i]) {
			break
		}

		k.Root.raw = k.Root.raw[:len(k.Root.raw)-1]
	}

	return k
}