kstrings

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: Apache-2.0 Imports: 10 Imported by: 11

Documentation

Index

Constants

View Source
const (
	DELIM_START = '{'
	DELIM_STOP  = '}'
	DELIM_STR   = "{}"
	ESCAPE_CHAR = '\\'
)
View Source
const (
	DATETIME_FORMATTER          = "2006-01-02 15:04:05"
	DATETIME_FORMATTER_Mill     = "2006-01-02 15:04:05.000"
	DATETIME_TIMEZONE_FORMATTER = "2006-01-02 15:04:05 -0700"
)

Variables

View Source
var (
	ErrSampleString = fmt.Errorf("%s", "sample string")
)

Functions

func Debug

func Debug(messagePattern string, args ...any)

func Debugf

func Debugf(messagePattern string, args ...any)

func Errorf

func Errorf(messagePattern string, args ...any) error

func FormatString

func FormatString(messagePattern string, args ...any) string

func IndexOf

func IndexOf(str, substr string, index int) int

从字符串str的index位置开始查找第一个出现的subStr位置

func Print

func Print(messagePattern string, args ...any)

func Printf

func Printf(messagePattern string, args ...any)

func Println

func Println(messagePattern string, args ...any)

func Sprintf

func Sprintf(messagePattern string, args ...any) string

func ThrowableCandidate

func ThrowableCandidate(args []any) error

func ToBool

func ToBool(str string) (bool, error)

func ToFloat32

func ToFloat32(str string) (float32, error)

func ToFloat64

func ToFloat64(str string) (float64, error)

func ToInt

func ToInt(str string) (int, error)

func ToInt8

func ToInt8(str string) (int8, error)

func ToInt16

func ToInt16(str string) (int16, error)

func ToInt32

func ToInt32(str string) (int32, error)

func ToInt64

func ToInt64(str string) (int64, error)

func ToUint

func ToUint(str string) (uint, error)

func ToUint8

func ToUint8(str string) (uint8, error)

func ToUint16

func ToUint16(str string) (uint16, error)

func ToUint32

func ToUint32(str string) (uint32, error)

func ToUint64

func ToUint64(str string) (uint64, error)

func TrimSpace

func TrimSpace(str string) string

func TrimmedCopy

func TrimmedCopy(args []any) ([]any, error)

@bref Helper method to get all but the last element of an array

  • @param argArray The arguments from which we want to remove the last element
  • @return a copy of the array without the last element

Types

type FormattingTuple

type FormattingTuple struct {
	// contains filtered or unexported fields
}

func ArrayFormat

func ArrayFormat(messagePattern string, argArray []any) *FormattingTuple

func ArrayFormatWithError

func ArrayFormatWithError(messagePattern string, argArray []any, throwable error) *FormattingTuple

func Format

func Format(messagePattern string, arg any) *FormattingTuple

@bref Performs single argument substitution for the 'messagePattern' passed as parameter.

  • For example,
  • -- MessageFormatter.format("Hi {}.", "there");
  • -- will return the string "Hi there.".
  • @param messagePattern The message pattern which will be parsed and formatted
  • @param arg The argument to be substituted in place of the formatting anchor
  • @return The formatted message

func FormatArgs

func FormatArgs(messagePattern string, arg1, arg2 any) *FormattingTuple

Performs a two argument substitution for the 'messagePattern' passed as parameter.

  • For example,
  • -- MessageFormatter.format("Hi {}. My name is {}.", "Alice", "Bob");
  • -- will return the string "Hi Alice. My name is Bob.".
  • @param messagePattern The message pattern which will be parsed and formatted
  • @param arg1 The argument to be substituted in place of the first formatting anchor
  • @param arg2 The argument to be substituted in place of the second formatting anchor
  • @return The formatted message

func NewFormattingTuple

func NewFormattingTuple(message string, args []any, throwable error) *FormattingTuple

func SliceFormat

func SliceFormat(messagePattern string, args ...any) *FormattingTuple

func (*FormattingTuple) Args

func (its *FormattingTuple) Args() []any

func (*FormattingTuple) Message

func (its *FormattingTuple) Message() string

func (*FormattingTuple) Throwable

func (its *FormattingTuple) Throwable() error

type KParameter

type KParameter string

func (KParameter) Type

func (that KParameter) Type() TYPE

func (KParameter) TypeString

func (that KParameter) TypeString() string

type StringParams

type StringParams struct {
	// contains filtered or unexported fields
}

字符串参数解析与处理

  • 例如: "hello word ${param1}! i'm $(param3), fuck off ${param2}..."
  • - ${param1} ${} 代表变量
  • - $(param3) $() 代表方法

func Parse

func Parse(str string) *StringParams

解析表达式

func (*StringParams) Build

func (that *StringParams) Build() string

将包含变量的表达式编译成字符串

func (*StringParams) Get

func (that *StringParams) Get() *klists.KList[string]

func (*StringParams) GetFuncName

func (that *StringParams) GetFuncName() *klists.KList[string]

func (*StringParams) GetVarName

func (that *StringParams) GetVarName() *klists.KList[string]

func (*StringParams) Set

func (that *StringParams) Set(param string, value string) *StringParams

指定一个变量的值, 如变量不存在, 不做任何操作

func (*StringParams) SetFunc

func (that *StringParams) SetFunc(param string, value string) *StringParams

指定一个方法的值, 如方法不存在, 不做任何操作

func (*StringParams) SetVar

func (that *StringParams) SetVar(param string, value string) *StringParams

指定一个变量的值, 如变量不存在, 不做任何操作

type TYPE

type TYPE uint
const (
	NONE_TYPE TYPE = 0
	VAR_TYPE  TYPE = 1
	FUNC_TYPE TYPE = 2
)

Jump to

Keyboard shortcuts

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