qsplit

package module
v2.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2020 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Package qsplit (short for "quoted split") performs a Unix shell style split-on-whitespace of its input. Its functions return the non-whitespace "chunks" contained in their input, treating text within balanced quotes as a single chunk.

Whitespace, according to qsplit, is the ASCII space and horizontal tab characters.

By default, qsplit is aware only of the ASCII single and double quote characters as chunk delineators. This can be changed with `SetQuotes`.

These are the rules used to delineate quoted chunks:

  • Quotes begin only at a word boundary
  • Quotes extend to the first closing quotation mark which matches the opening quote, which may or may not be at a word boundary.
  • Quotes do not nest

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Locations

func Locations(b []byte) [][2]int

Locations returns the beginning and end points of all text chunks in its input.

func LocationsOnce

func LocationsOnce(b []byte) [3]int

LocationsOnce returns the beginning and end point of the first chunk, and the beginning of the next chunk. If this is all you need, LocationsOnce is significantly faster than Locations.

If no chunks are found, the 1st element of the returned array will be -1. If only one chunk is found, the 3rd element will be -1.

func Once

func Once(b []byte) [][]byte

Once performs a single quoted split, returning the first chunk found in the input byteslice, and the remainder of the byteslice

func SetQuotes added in v2.4.0

func SetQuotes(qopen, qclose []rune)

SetQuotes sets the list of runes which will be considered quote-open and quote-close characters. As an example, to emulate the behavior of old versions of qsplit, the call would be:

SetQuotes([]rune{'\'', '"', '`', '‹', '«', '「', '『'},
          []rune{'\'', '"', '`', '›', '»', '」', '』'})

func ToBytes

func ToBytes(b []byte) [][]byte

ToBytes performs a quoted split to a slice of byteslices.

func ToStringBytes

func ToStringBytes(b []byte) (string, [][]byte)

ToStringBytes performs a quoted split, returning the first chunk as a string and the rest as a slice of byteslices.

func ToStrings

func ToStrings(b []byte) []string

ToStrings performs a quoted split to a slice of strings.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL