single

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2022 License: MIT Imports: 1 Imported by: 1

README

single build Go Reference Coverage Code to Test Ratio Test Execution Time

single package provides single.Quote and single.Unquote for quoting/unquoting with single quotes.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrSyntax = errors.New("invalid syntax")

Functions

func Quote

func Quote(s string) string

Quote returns a single-quoted Go string literal representing s. But, nothing else escapes.

Example
package main

import (
	"fmt"

	"github.com/k1LoW/single"
)

func main() {
	s := single.Quote(`"Fran & Freddie's Diner	☺"`)
	fmt.Println(s)
	s = single.Quote(`rock'n'roll`)
	fmt.Println(s)
}
Output:

'"Fran & Freddie\'s Diner	☺"'
'rock\'n\'roll'

func Unquote

func Unquote(s string) (string, error)

Unquote interprets s as a single-quoted Go string literal, returning the string value that s quotes.

Example
package main

import (
	"fmt"

	"github.com/k1LoW/single"
)

func main() {
	s, err := single.Unquote("You can't unquote a string without quotes")
	fmt.Printf("%q, %v\n", s, err)
	s, err = single.Unquote("\"The string must be either double-quoted\"")
	fmt.Printf("%q, %v\n", s, err)
	s, err = single.Unquote("`or backquoted.`")
	fmt.Printf("%q, %v\n", s, err)
	s, err = single.Unquote("'\u263a'")
	fmt.Printf("%q, %v\n", s, err)
	s, err = single.Unquote("'\u2639\u2639'")
	fmt.Printf("%q, %v\n", s, err)
	s, err = single.Unquote("'\\'The string must be either single-quoted\\''")
	fmt.Printf("%q, %v\n", s, err)
}
Output:

"", invalid syntax
"", invalid syntax
"", invalid syntax
"☺", <nil>
"☹☹", <nil>
"'The string must be either single-quoted'", <nil>

Types

This section is empty.

Jump to

Keyboard shortcuts

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