strings

package
v0.0.0-...-c778a73 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 6 Imported by: 0

README

Strings

  • SubstringSearch: Searches for substrings in a string with customizable options.
  • Title: Converts a string to title case (capitalizes the first letter of each word).
  • ToTitle: Converts a string to title case, ignoring specified words.
  • Tokenize: Splits a string into tokens using specified delimiters.
  • Rot13Encode: Encodes a string using the ROT13 cipher.
  • Rot13Decode: Decodes a string using the ROT13 cipher.
  • CaesarEncrypt: Encrypts a string using the Caesar cipher with a given shift.
  • CaesarDecrypt: Decrypts a string encrypted using the Caesar cipher.
  • IsValidEmail: Checks if a string is a valid email address.
  • SanitizeEmail: Removes leading and trailing spaces from an email string.
  • Reverse: Reverses the characters in a string.
  • CommonPrefix: Finds the longest common prefix of a set of strings.
  • CommonSuffix: Finds the longest common suffix of a set of strings.
  • RunLengthEncode Encodes a string using Run-length-encoding.
  • RunLengthDecode Decodes a string that has been encoded using Run-length-encoding. Ruturns the original string and an error if the encoding failed
  • Truncate Shortens a string to a maximum length and appends an omission suffix if truncated.

Examples:

For examples of each function, please checkout EXAMPLES.md


Documentation

Overview

Package strings defines strings helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaesarDecrypt

func CaesarDecrypt(input string, shift int) string

CaesarDecrypt decrypts a string encrypted with the Caesar cipher and a given shift.

func CaesarEncrypt

func CaesarEncrypt(input string, shift int) string

CaesarEncrypt encrypts a string using the Caesar cipher with a given shift.

func CommonPrefix

func CommonPrefix(input ...string) string

CommonPrefix returns the longest common prefix of the given strings. If no strings are provided, it returns an empty string. If only one string is provided, it returns that string. For example, CommonPrefix("nation", "national", "nasty") returns "na".

func CommonSuffix

func CommonSuffix(input ...string) string

CommonSuffix returns the longest common suffix of the given strings. If no strings are provided, it returns an empty string. If only one string is provided, it returns that string. For example, CommonSuffix("testing", "running", "jumping") returns "ing".

func IsValidEmail

func IsValidEmail(email string) bool

IsValidEmail checks if a given string is a valid email address.

func Reverse

func Reverse(input string) string

Reverse returns a reversed version of the input string. It correctly handles Unicode characters. For example:

Reverse("hello") returns "olleh"
Reverse("世界") returns "界世"

func Rot13Decode

func Rot13Decode(input string) string

Rot13Decode decodes a string encoded with the ROT13 cipher.

func Rot13Encode

func Rot13Encode(input string) string

Rot13Encode encodes a string using the ROT13 cipher.

func RunLengthDecode

func RunLengthDecode(encoded string) (string, error)

RunLengthDecode takes a Run-Length Encoded string and returns the decoded string or an error + the orignal encoded string

func RunLengthEncode

func RunLengthEncode(input string) string

RunLengthEncode takes a string and returns its Run-Length Encoded representation or the original string if the encoding did not achieve any compression

func SanitizeEmail

func SanitizeEmail(email string) string

SanitizeEmail removes leading and trailing whitespace from an email address.

func SubstringSearch

func SubstringSearch(input, substring string, options SubstringSearchOptions) []string

SubstringSearch performs substring search in a string and optionally returns indexes.

func Title

func Title(input string) string

Title return string in title case with English language-specific title

func ToTitle

func ToTitle(input string, exceptions []string) string

ToTitle converts a string to title case, capitalizing the first letter of each word. It excludes exceptions specified in the exceptions slice.

func Tokenize

func Tokenize(input string, customDelimiters string) []string

Tokenize splits a given string into words based on whitespace and custom delimiters.

func Truncate

func Truncate(input string, opts *TruncateOptions) string

Truncate shortens a given input string based on provided options. Parameters: - input: the original string to truncate. - opts: optional settings to specify truncation length and omission suffix. If opts is nil or certain fields are unspecified, defaults are applied: Length defaults to 12 and Omission defaults to "...".

Types

type SubstringSearchOptions

type SubstringSearchOptions struct {
	CaseInsensitive bool // Perform case-insensitive search
	ReturnIndexes   bool // Return the starting indexes of found substrings
}

SubstringSearchOptions contains options for substring search.

type TruncateOptions

type TruncateOptions struct {
	Length   int
	Omission string
}

TruncateOptions represents optional parameters for the Truncate function.

Jump to

Keyboard shortcuts

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