strings

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

README

strings GoDoc

Usage

local inspect = require("inspect")
local strings = require("strings")

-- strings.split(string, sep)
local result = strings.split("a b c d", " ")
print(inspect(result, {newline="", indent=""}))
-- Output: { "a", "b", "c", "d" }

-- strings.has_prefix(string, prefix)
local result = strings.has_prefix("abcd", "a")
-- Output: true

-- strings.has_suffix(string, suffix)
local result = strings.has_suffix("abcd", "d")
-- Output: true

-- strings.trim(string, cutset)
local result = strings.trim("abcd", "d")
-- Output: abc

-- strings.contains(string, substring)
local result = strings.contains("abcd", "d")
-- Output: true
Reader/Writer classes often used with json+yaml Encoder/Decoder
reader = strings.new_reader([[{"foo":"bar","baz":"buz"}]])
assert(reader:read("*a") == [[{"foo":"bar","baz":"buz"}]])

writer = strings.new_builder()
writer:write("foo", "bar", 123)
assert(writer:string() == "foobar123")

Documentation

Overview

Package strings implements golang package strings functionality for lua.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckStringsBuilder added in v0.1.6

func CheckStringsBuilder(L *lua.LState, n int) *strings.Builder

func CheckStringsReader added in v0.1.6

func CheckStringsReader(L *lua.LState, n int) *strings.Reader

func Contains

func Contains(L *lua.LState) int

Contains lua strings.contains(string, cutset) Port of go string.Contains() returns bool

Example

strings.contains(string, substring)

state := lua.NewState()
Preload(state)
source := `
    local strings = require("strings")
    local result = strings.contains("abcd", "d")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

true

func Fields

func Fields(L *lua.LState) int

Fields lua strings.fields(string) Port of go string.Fields() returns table

Example

strings.fields(string)

state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
	local strings = require("strings")
	local result = strings.fields("a b c d")
    print(inspect(result, {newline="", indent=""}))
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

a b c d

func HasPrefix

func HasPrefix(L *lua.LState) int

HasPrefix lua strings.has_prefix(string, suffix): port of go string.HasPrefix() return bool

Example

strings.has_prefix(string, prefix)

state := lua.NewState()
Preload(state)
source := `
    local strings = require("strings")
    local result = strings.has_prefix("abcd", "a")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

true

func HasSuffix

func HasSuffix(L *lua.LState) int

HasSuffix lua strings.has_suffix(string, prefix): port of go string.HasSuffix() returns bool

Example

strings.has_suffix(string, suffix)

state := lua.NewState()
Preload(state)
source := `
    local strings = require("strings")
    local result = strings.has_suffix("abcd", "d")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

true

func LVStringsBuilder added in v0.1.6

func LVStringsBuilder(L *lua.LState, builder *strings.Builder) lua.LValue

func LVStringsReader added in v0.1.6

func LVStringsReader(L *lua.LState, reader *strings.Reader) lua.LValue

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

Preload adds strings to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local strings = require("strings")

func Split

func Split(L *lua.LState) int

Split lua strings.split(string, sep): port of go string.Split() returns table

Example

strings.split(string, sep)

state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
    local inspect = require("inspect")
    local strings = require("strings")
    local result = strings.split("a b c d", " ")
    print(inspect(result, {newline="", indent=""}))
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

{ "a", "b", "c", "d" }

func Trim

func Trim(L *lua.LState) int

Trim lua strings.trim(string, cutset) Port of go string.Trim() returns string

Example

strings.trim(string, cutset)

state := lua.NewState()
Preload(state)
source := `
    local strings = require("strings")
    local result = strings.trim("abcd", "d")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

abc

func TrimPrefix

func TrimPrefix(L *lua.LState) int

TrimPrefix lua strings.trim_prefix(string, cutset) Port of go string.TrimPrefix() returns string

Example

strings.trim_prefix(string, cutset)

state := lua.NewState()
Preload(state)
source := `
    local strings = require("strings")
    local result = strings.trim_prefix("abcd", "d")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

abcd

func TrimSuffix

func TrimSuffix(L *lua.LState) int

TrimSuffix lua strings.trim_suffix(string, cutset) Port of go string.TrimSuffix() returns string

Example

strings.trim_suffix(string, cutset)

state := lua.NewState()
Preload(state)
source := `
    local strings = require("strings")
    local result = strings.trim_suffix("abcd", "d")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

abc

Types

This section is empty.

Jump to

Keyboard shortcuts

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