Documentation ¶
Overview ¶
This package is a library containing some useful string-related fucntions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
UPSErrTooSmall error = errors.New("This function does not generate strings less than 32 " +
"characters.")
)
Functions ¶
func MonthToNum ¶
MonthToNum () returns the numerical value of a month.
Inputs ¶
input 0: The full name of the month (capitalizing only the first letter of the month name, e.g. April).
Outpts ¶
outpt 0: The numerical value of the month. If input 0 is invalid, value would be 0.
func PrependTillN ¶
PrependTillN () repeatedly prepends a prepend to a subject, until the length of the subject is at least N chars in size.
Inputs ¶
input 0: The subject.
input 1: The prepend. If value is an empty string, input 0 is returned.
input 2: Mininum length (N) input 0 must attain before the function stops preprending input 1 to input 0. The highest value of N is the highest value of type int. However, when the value of N is very high (like 1000000000 (1 billion)), this function could block indefinitely, due to the way Go works (behaviour has been confirmed in Go versions <= 1.12.4). If this function starts to block with high values of N, you can lower your N, but increase the number of times the function is called. So, instead of this:
text = str.PrependTillN (text, "hi!", 1000000000)
you can do this:
text = str.PrependTillN (text, "hi!", 500000000)
text = str.PrependTillN (text, "hi!", 500000000)
Outpts ¶
outpt 0: Result of operation.
func PrintEtr ¶
func PrintEtr(output interface{}, oType, printer string)
PrintEtr () which stands for "print easier-to-read", helps print texts that would be easier to read.
Inputs ¶
input 0: The item to the be printed.
input 1: The type of data input 0 is. Possible values are: "std" which represents a normal data, "wrn" which represents a warning data, and "err" which represents an error data. If value is invalid, "std" would be used.
input 2: The name or ID of the printer of the text.
func UniquePredsafeStr ¶
UniquePredsafeStr () generates a string that is unique, and also safe from prediction (i.e. it is difficult to precisely predict what a string generated, by this function, at anytime would be).
Inputs ¶
input 0: The length of the string to be generated. Value can not be less than 32.
Outpts ¶
outpt 0: If generation succeeds, value would be the generated string; an alpha-numeric string (case-insensitive). If generation should fail, value could be anything. Use outpt 1 to determine success or failure of the function.
outpt 1: If generation succeeds, value would be a nil error. If generation should fail, value would be an error describing the reason for the failure. If value of input 0 is less than 32, value would be error str.UPSErrTooSmall.
Notes on Current Implementation ¶
This function relies on your system's local time (golang's package "time"). If your system should go back in time, all strings generated till your system goes back to the present, may be unique, but not guaranteed to be unique.
In short, for this function to generate unique strings, at all time (till the end of the year 9999), your system's time must be accurate at all times you call this function.
This function builds upon golang's package "crypto/rand", so its prediction-safeness is dependent on the package.
Types ¶
This section is empty.