strutil

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Copyright 2023 The acquirecloud Authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes2String

func Bytes2String(val []byte, abet string, bits int) string

Bytes2String transforms bitstream to a string. val contains bytes and only lower bits from any value is used for the calculation. abet - is an alpabet which is used for forming the result string.

func GetRandomString

func GetRandomString(size int, abc string) string

GetRandomString returns the random generated string with the alphabet abc

func RandomString

func RandomString(ln int) string

RandomString returns a pseudo-random string by length ln.

func RemoveDups

func RemoveDups(ss []string) []string

RemoveDups returns a slice where every element from ss meets only once

func SwapEvenOdd

func SwapEvenOdd(ss []string) []string

Swaps (in place) odd and even positions of the given string slice, can be useful in reversing 'map' when represented as slice of {k1,v1,k2,v2}

Examples:
	SwapEvenOdd([]string{1}) returns []string{1}
	SwapEvenOdd([]string{1,2,3}) returns []string{2,1,3}
	SwapEvenOdd([]string{1,2,3,4}) returns []string{2,1,4,3}

func TruncateWithEllipses

func TruncateWithEllipses(s string, maxSize int) string

TruncateWithEllipses truncate string if it doesn't fit into maxLen and add 3 ellipses. Maximum len of resulting string is maxSize

Types

type Hash

type Hash interface {
	Bytes() []byte
	String() string
	// contains filtered or unexported methods
}

Hash type represents a hash value

func CreateHash

func CreateHash(buf []byte) (Hash, error)

CreateHash returns the Hash value by buf

func NewSha256ForData

func NewSha256ForData(data []byte) (Hash, error)

NewSha256ForData returns the sha256 Hash for the data provided

func ParseHash

func ParseHash(h string) (Hash, error)

ParseHash returns the Hash value for the provided string

func RandomHash

func RandomHash() Hash

RandomHash generates a pseudo-random Hash value

func SumHashes

func SumHashes(hashes ...Hash) Hash

SumHashes returns the hash value for the list of hashes

Jump to

Keyboard shortcuts

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