runestr

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 2 Imported by: 1

README

What is runestr?

Runestr is a library designed for manipulating strings at the rune level.

Functions

  • Length: Returns the count of Unicode code points (runes) within a string.
  • PadRight: Pads a string on the right side with a specified fill pattern until it reaches the provided width.
  • Left: Retrieves the leftmost n runes from a string.
  • Right: Retrieves the rightmost n runes from a string.
  • SplitOnNearestSpace: Divides a string into two parts at the nearest space character to the n-th position.
  • RuneAtPosition: Fetches the Unicode code point (rune) at the specified position in a string or returns the specified default value if the position is out of bounds.

Usage

import (
    "github.com/tpfeiffer67/runestr"
)

License

This repository is licensed under the MIT License. See the LICENSE file for more information.

Author

Documentation

Overview

The runestr package offers several functions that operate on strings at the rune level. These functions allow for tasks such as calculating the length of a string (count the number of runes), padding a string on the right side, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Left

func Left(s string, n int) string

Left returns the leftmost n runes of a string.

func Length

func Length(s string) int

Length returns the number of Unicode code points (runes) in a string.

func PadRight

func PadRight(s string, fillPattern string, width int) string

PadRight pads a string on the right side with a fill pattern until it reaches the given width. If the fill pattern doesn't fit exactly, the last character(s) of the fill pattern are repeated.

func Right(s string, n int) string

Right returns the rightmost n runes of a string.

func RuneAtPosition

func RuneAtPosition(s string, pos int, def rune) rune

RuneAtPosition returns the Unicode code point (rune) at the specified position in a string, or the specified default value if the position is out of bounds.

func SplitOnNearestSpace

func SplitOnNearestSpace(s string, max int) (first string, second string)

SplitOnNearestSpace splits a string into two parts at the nearest space character to the n-th position. The first part includes all characters up to (but not including) the space character. If there is no space character, the word can be truncated. The second part includes the rest of the stringwith leading and trailing spaces removed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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