kstrings

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 11 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 ToBoolNoThrow added in v0.4.5

func ToBoolNoThrow(str string) (bool, bool)

func ToDateTime added in v0.4.5

func ToDateTime(str string) (*time.Time, bool)

func ToDateTimeByFormat added in v0.4.5

func ToDateTimeByFormat(str string, format string) (*time.Time, bool)

func ToDateTimeByFormatWithLocation added in v0.4.5

func ToDateTimeByFormatWithLocation(str string, format string, offset int) (*time.Time, bool)

ToDateTimeByFormatWithLocation 根据指定的格式和时区偏移量将字符串转换为时间对象

该函数会先去除字符串两端的空白字符,然后使用指定的时区偏移量来解析时间字符串。 如果解析成功,返回时间对象和true;如果解析失败,返回nil和false。

@param str 要解析的时间字符串
@param time.ParseInLocation函数使用的格式字符串
@param offset 时区偏移量,单位为秒(东八区为+28800)
@return 解析成功返回*time.Time对象,失败返回nil
@return 解析成功返回true,失败返回false

func ToFloat32

func ToFloat32(str string) (float32, error)

func ToFloat32NoThrow added in v0.4.5

func ToFloat32NoThrow(str string) (float32, bool)

func ToFloat64

func ToFloat64(str string) (float64, error)

func ToFloat64NoThrow added in v0.4.5

func ToFloat64NoThrow(str string) (float64, bool)

func ToInt

func ToInt(str string) (int, error)

func ToInt8

func ToInt8(str string) (int8, error)

func ToInt8NoThrow added in v0.4.5

func ToInt8NoThrow(str string) (int8, bool)

func ToInt16

func ToInt16(str string) (int16, error)

func ToInt16NoThrow added in v0.4.5

func ToInt16NoThrow(str string) (int16, bool)

func ToInt32

func ToInt32(str string) (int32, error)

func ToInt32NoThrow added in v0.4.5

func ToInt32NoThrow(str string) (int32, bool)

func ToInt64

func ToInt64(str string) (int64, error)

func ToInt64NoThrow added in v0.4.5

func ToInt64NoThrow(str string) (int64, bool)

func ToIntNoThrow added in v0.4.5

func ToIntNoThrow(str string) (int, bool)

func ToTimestamp added in v0.4.5

func ToTimestamp(str string) (uint64, bool)

func ToTimestampForMilli added in v0.4.5

func ToTimestampForMilli(str string) (uint64, bool)

func ToUint

func ToUint(str string) (uint, error)

func ToUint8

func ToUint8(str string) (uint8, error)

func ToUint8NoThrow added in v0.4.5

func ToUint8NoThrow(str string) (uint8, bool)

func ToUint16

func ToUint16(str string) (uint16, error)

func ToUint16NoThrow added in v0.4.5

func ToUint16NoThrow(str string) (uint16, bool)

func ToUint32

func ToUint32(str string) (uint32, error)

func ToUint32NoThrow added in v0.4.5

func ToUint32NoThrow(str string) (uint32, bool)

func ToUint64

func ToUint64(str string) (uint64, error)

func ToUint64NoThrow added in v0.4.5

func ToUint64NoThrow(str string) (uint64, bool)

func ToUintNoThrow added in v0.4.5

func ToUintNoThrow(str string) (uint, bool)

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