simpleshsplit

package module
v0.0.0-...-3034750 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Zlib Imports: 0 Imported by: 3

README

Simpleshsplit

GoDoc

This is a small library for splitting strings on whitespace, such as might be used for a simple shell. By default, the only special character is \, which is used to escape a space or another backslash.

Splitting on a character other than \ is supported as well.

Example

parts := simpleshsplit.Split(`arg1 arg2a\ arg2b arg3a\\arg3b`)
for _, part := range parts {
        fmt.Printf("%v\n", part)
}   

Produces

arg1
arg2a arg2b
arg3a\arg3b

Documentation

Overview

Package simpleshsplit splits strings on whitespace, allowing escaped spaces

Index

Examples

Constants

View Source
const DefaultEscape = '\\'

DefaultEscape is the escape rune used by Split.

Variables

This section is empty.

Functions

func Split

func Split(s string) []string

Split splits b into space-separated substrings. A space may be escaped by preceeding it with a backslash. A backslash may be escaped in the same way.

Example
parts := Split(`arg1 arg2a\ arg2b arg3a\\arg3b`)
for _, part := range parts {
	fmt.Printf("%v\n", part)
}
Output:


arg1
arg2a arg2b
arg3a\arg3b

func SplitOn

func SplitOn(s string, esc rune) []string

SplitOn is similar to Split, but uses the rune in esc instead of backslash.

Types

This section is empty.

Jump to

Keyboard shortcuts

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