runes

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 2 Imported by: 0

README

pkg runes

Go pkg inspried by strings package, for runes.

Although strings and unicode/utf8 pkg is great, but some of them are behaving weirdly.

For example,

  • If the byte slice is incomplete, then utf8.CountXXX counts the length of bytes and add them.

  • strings.Index returns 0 if passing empty string "" to its parameter substr.

With this pkg, these points are fixed.

Test GoDoc Go Report Card

Installation

go get github.com/Qs-F/runes

Usage

See GoDoc

License

MIT

Documentation

Overview

pkg `runes` is the golang lib package for runes, which is inspired by standard lib `strings`.

Although `strings` and `unicode/utf8` pkg is great, but some of them are behaving weirdly.

For example,

- If the byte slice is incomplete, then `utf8.CountXXX` counts the length of bytes and add them.

- `strings.Index` returns `0` if passing empty string `""` to its parameter `substr`.

With this pkg, these points are fixed.

Index

Constants

View Source
const MAX_BYTE_UTF8 = 6 // 6 is the max value of utf8 byte

Variables

This section is empty.

Functions

func Before

func Before(s string, bytepos int) int

Before returns the byte start position of before valid rune. If the before valid rune is not found, returns given bytepos.

func Count

func Count(str string, bytecnt int) int

Count returns the number of str in rune. If bytecnt >= 0, then counts str[:bytescnt]. If bytecnt < 0 (mostly -1), then counts all the str.

func CountByte

func CountByte(str string, runecnt int) int

Count returns the number of str to runecnt in byte. If runecnt >= 0, then counts str[:runecnt]. If runecntj < 0 (mostly -1), then counts all the str.

func Index

func Index(s, substr string) int

Index returns index number in rune

func IndexAll

func IndexAll(s, substr string) []int

IndexAll returns the list of all index number in rune

func Next

func Next(s string, bytepos int) int

Next returns the byte start position of next valid rune. If the next valid rune is not found, returns given bytepos.

Types

This section is empty.

Jump to

Keyboard shortcuts

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