util

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package util holds various utilities used all over gggb

Index

Examples

Constants

View Source
const (
	RPL_LOGGEDIN    = "900"
	RPL_LOGGEDOUT   = "901"
	RPL_NICKLOCKED  = "902"
	RPL_SASLSUCCESS = "903"
	RPL_SASLFAIL    = "904"
	RPL_SASLTOOLONG = "905"
	RPL_SASLABORTED = "906"
	RPL_SASLALREADY = "907"
	RPL_SASLMECHS   = "908"
)

IRC SASL numerics

Variables

This section is empty.

Functions

func AddZwsp

func AddZwsp(s string) string

AddZwsp adds a zero width space to the given string if its length is greater than two

func AnyMaskMatch

func AnyMaskMatch(toCheck string, masks []string) bool

AnyMaskMatch returns whether or not the given match

func CleanSplitOnSpace

func CleanSplitOnSpace(s string) []string

CleanSplitOnSpace splits the given string on space specifically without adding empty strings to the resulting array for repeated spaces

func EscapeString

func EscapeString(s string) string

EscapeString escapes commonly (ab)used strings

func GenerateSASLString

func GenerateSASLString(nick, saslUsername, saslPasswd string) string

GenerateSASLString generates a base64 encoded string from the given parameters that can be used for SASL PLAIN authentication with an IRC server

func GlobToRegexp

func GlobToRegexp(mask string) *regexp.Regexp

GlobToRegexp converts a mask glob string to a regexp that will only allow the wildcards * and ? to have any special meaning.

func IdxOrEmpty

func IdxOrEmpty(slice []string, idx int) string

IdxOrEmpty returns the given slice index, or an empty string

Example
s := []string{"test", "string", "is", "testy"}

fmt.Printf("%q\n", IdxOrEmpty(s, 0))
fmt.Printf("%q\n", IdxOrEmpty(s, 5))
//nolint:gocritic // its output :P
Output:

"test"
""

func JoinToMaxLength

func JoinToMaxLength(toJoin []string, sep string, maxLength int) []string

JoinToMaxLength takes a string slice and joins it on sep until the joined string cannot be made larger without crossing maxLength length. If any entry in the slice to be joined is larger than maxLength, it will be added on its own to an entry in the resulting slice

Example
fmt.Printf("%#v", JoinToMaxLength([]string{"this", "is", "a", "test"}, ", ", 10))
Output:

[]string{"this, is", "a, test"}

func MakeSimpleIRCLine

func MakeSimpleIRCLine(command string, args ...string) ircmsg.IrcMessage

MakeSimpleIRCLine is a helper function that creates an ircmsg.IrcMessage with no tags and no prefix.

func ReverseIdx

func ReverseIdx(toIdx []string, idx int) string

ReverseIdx returns either the given index, or, if the given index is negative, that index starting from the end of the slice. Much like a python lists behaviour when indexed with a negative number

Example
fmt.Println(ReverseIdx([]string{"have", "an", "example", "string", "slice"}, -2))
Output:

string

func StripAll

func StripAll(s string) string

StripAll strips any extra weird ascii control codes

Example
fmt.Println(StripAll("Some string with \x01 control characters\u200b in it"))
Output:

Some string with  control characters in it

func UserHost2Canonical

func UserHost2Canonical(uh ircutils.UserHost) string

UserHost2Canonical returns the nickname!username@host representation of the given ircutils.UserHost

func WordEol

func WordEol(s string, wordIdx int) string

WordEol returns the given string with wordIdx words (space separations) removed

Types

This section is empty.

Directories

Path Synopsis
Package systemstats holds code to query the status of the current system
Package systemstats holds code to query the status of the current system

Jump to

Keyboard shortcuts

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