gosplitargs

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

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

Go to latest
Published: Dec 5, 2024 License: ISC Imports: 1 Imported by: 8

README

gosplitargs

Splits strings into tokens by given separator except treating quoted part as a single token.

#Installation go get -u github.com/elgs/gosplitargs

#Usage

package main

import (
	"fmt"
	"github.com/elgs/gosplitargs"
)

func main() {
	i1 := "I said 'I am sorry.', and he said \"it doesn't matter.\""
	o1, _ := gosplitargs.SplitArgs(i1, "\\s")
	for _, s := range o1 {
		fmt.Println(s)
	}
	/*
	   [ 'I',
	     'said',
	     'I am sorry.,',
	     'and',
	     'he',
	     'said',
	     'it doesn\'t matter.' ]
	*/

	i2 := "I said \"I am sorry.\", and he said \"it doesn't matter.\""
	o2, _ := gosplitargs.SplitArgs(i2, "\\s")
	for _, s := range o2 {
		fmt.Println(s)
	}
	/*
	   [ 'I',
	     'said',
	     'I am sorry.,',
	     'and',
	     'he',
	     'said',
	     'it doesn\'t matter.' ]
	*/

	i3 := `I said "I am sorry.", and he said "it doesn't matter."`
	o3, _ := gosplitargs.SplitArgs(i3, "\\s")
	for _, s := range o3 {
		fmt.Println(s)
	}
	/*
	   [ 'I',
	     'said',
	     'I am sorry.,',
	     'and',
	     'he',
	     'said',
	     'it doesn\'t matter.' ]
	*/

	i4 := `I said 'I am sorry.', and he said "it doesn't matter."`
	o4, _ := gosplitargs.SplitArgs(i4, "\\s")
	for _, s := range o4 {
		fmt.Println(s)
	}
	/*
	   [ 'I',
	     'said',
	     'I am sorry.,',
	     'and',
	     'he',
	     'said',
	     'it doesn\'t matter.' ]
	*/
}

Documentation

Overview

gosplitargs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitArgs

func SplitArgs(input string, separator string, keepQuotes bool) ([]string, error)

func SplitSQL

func SplitSQL(input string, separator string, keepQuotes bool) ([]string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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