exutf8

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 1 Imported by: 5

Documentation

Overview

Package exutf8 用于改善标准库 utf8 包,提升操作多字节字符的性能及便利性,避免转换 []rune 类型。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RuneIndex

func RuneIndex(p []byte, n int) (int, bool)

RuneIndex 返回 p 中第 n 个字符的位置索引,可以通过索引位置截取 []byte 如果 n 超过 p 中字符的数量,则第二个参数返回 false 错误的或短的编码被当做宽度为一个字节的单一字符。

func RuneIndexInString

func RuneIndexInString(s string, n int) (int, bool)

RuneIndexInString 返回 s 中第 n 个字符的位置索引,可以通过索引位置截取字符串 如果 n 超过 s 中字符的数量,则第二个参数返回 false 错误的或短的编码被当做宽度为一个字节的单一字符。

func RuneSub

func RuneSub(p []byte, start, length int) []byte

RuneSub 提供符文数量截取字节数组的方法,针对多字节字符安全高效的截取 如果 start 是非负数,返回的字符串将从 string 的 start 位置开始,从 0 开始计算。例如,在字符串 “abcdef” 中,在位置 0 的字符是 “a”,位置 2 的字符串是 “c” 等等。 如果 start 是负数,返回的字符串将从 string 结尾处向前数第 start 个字符开始。 如果 string 的长度小于 start,将返回空字符串。

如果提供了正数的 length,返回的字符串将从 start 处开始最多包括 length 个字符(取决于 string 的长度)。 如果提供了负数的 length,那么 string 末尾处的 length 个字符将会被省略(若 start 是负数则从字符串尾部算起)。如果 start 不在这段文本中,那么将返回空字符串。 如果提供了值为 0 的 length,返回的子字符串将从 start 位置开始直到字符串结尾。

func RuneSubString

func RuneSubString(s string, start, length int) string

RuneSubString 提供符文数量截取字符串的方法,针对多字节字符安全高效的截取 如果 start 是非负数,返回的字符串将从 string 的 start 位置开始,从 0 开始计算。例如,在字符串 “abcdef” 中,在位置 0 的字符是 “a”,位置 2 的字符串是 “c” 等等。 如果 start 是负数,返回的字符串将从 string 结尾处向前数第 start 个字符开始。 如果 string 的长度小于 start,将返回空字符串。

如果提供了正数的 length,返回的字符串将从 start 处开始最多包括 length 个字符(取决于 string 的长度)。 如果提供了负数的 length,那么 string 末尾处的 length 个字符将会被省略(若 start 是负数则从字符串尾部算起)。如果 start 不在这段文本中,那么将返回空字符串。 如果提供了值为 0 的 length,返回的子字符串将从 start 位置开始直到字符串结尾。

Types

This section is empty.

Jump to

Keyboard shortcuts

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