Documentation
¶
Index ¶
- func EndsWithNullTerminator(input string) bool
- func EndsWithNullTerminatorUTF16(input []byte) bool
- func EnsureDirExists(dirPath string) error
- func PadStringLeft(input string, padChar string, length int) string
- func PadStringRight(input string, padChar string, length int) string
- func PathSafeString(input string) string
- func RandomBool() bool
- func RandomBytes(length int) []byte
- func RandomInt(min, max int) int
- func RandomString(length int) string
- func ReadUntilNullTerminator(data []byte) ([]byte, int)
- func ReadUntilNullTerminatorUTF16(data []byte) ([]byte, int)
- func ReplaceNonPrintable(input string) string
- func SizeInBytes(size uint64) string
- func TimeStringToTime(timeString string) (*time.Time, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EndsWithNullTerminator ¶ added in v1.0.3
EndsWithNullTerminator checks if the input string ends with a null terminator
Parameters: - input: The input string to check.
Returns: - A boolean indicating if the input string ends with a null terminator.
func EndsWithNullTerminatorUTF16 ¶ added in v1.0.3
EndsWithNullTerminatorUTF16 checks if the input byte slice ends with a null terminator
Parameters: - input: The input string to check.
Returns: - A boolean indicating if the input string ends with a null terminator.
func EnsureDirExists ¶ added in v1.0.4
EnsureDirExists checks if a directory exists and creates it if it doesn't. It uses os.MkdirAll, so it can create parent directories as needed.
Parameters: - dirPath: The path of the directory to ensure existence.
Returns: - An error if the directory could not be created or if there was an issue checking its existence.
func PadStringLeft ¶
Example: PadStringLeft("hello", "*", 8) returns "***hello"
Note: The function adds a space to the input string before padding to ensure proper alignment.
func PadStringRight ¶
PadStringRight pads the input string with the specified padChar on the right side until the string reaches the specified length. If the input string is already longer than or equal to the specified length, it returns the input string as is.
Parameters: - input: The original string to be padded. - padChar: The character to pad the input string with. - length: The desired total length of the output string.
Returns: - A new string that is padded with padChar on the right side to the specified length.
Example: PadStringRight("hello", "*", 8) returns "hello***"
Note: The function adds a space to the input string before padding to ensure proper alignment.
func PathSafeString ¶ added in v1.0.4
PathSafeString returns a string that is safe to use in file paths by replacing unsafe characters.
Parameters: - input: The input string to be sanitized.
Returns: - A string that is safe to use in file paths.
func RandomBool ¶ added in v1.0.4
func RandomBool() bool
RandomBool generates a random boolean value.
Returns: - A random boolean (true or false).
func RandomBytes ¶ added in v1.0.4
RandomBytes generates a random byte slice of the specified length.
Parameters: - length: The length of the byte slice to generate.
Returns: - A byte slice filled with random data.
func RandomInt ¶ added in v1.0.4
RandomInt generates a random integer between min (inclusive) and max (inclusive).
Parameters: - min: The minimum value (inclusive). - max: The maximum value (inclusive).
Returns: - A random integer within the specified range.
func RandomString ¶ added in v1.0.4
RandomString generates a random string of the specified length.
Parameters: - length: The length of the random string to generate.
Returns: - A string of the specified length.
func ReadUntilNullTerminator ¶ added in v1.0.3
ReadUntilNullTerminator reads bytes from a byte slice until it encounters a null byte and returns the data up to (but not including) the null byte.
Parameters: - data: The byte slice to read from
Returns: - A byte slice containing the data up to the first null byte - The number of bytes read (including the null byte)
func ReadUntilNullTerminatorUTF16 ¶ added in v1.0.3
ReadUntilNullTerminatorUTF16 reads bytes from a byte slice until it encounters a UTF-16 null terminator and returns the data up to (but not including) the null terminator.
Parameters: - data: The byte slice to read from
Returns: - A byte slice containing the data up to the first null terminator - The number of bytes read (including the null terminator)
func ReplaceNonPrintable ¶ added in v1.0.7
ReplaceNonPrintable replaces all non-printable characters in the input string with the escape sequence "\xNN" (where NN is the byte value in hexadecimal), and keeps printable characters as is.
Parameters: - input: The input string to process.
Returns: - A new string with non-printable characters replaced by their escape sequences.
func SizeInBytes ¶
SizeInBytes converts a size in bytes to a human-readable string representation using binary prefixes (KiB, MiB, GiB).
Parameters: - size: The size in bytes to be converted.
Returns: - A string representing the size in a human-readable format with binary prefixes.
Example: SizeInBytes(1048576) returns "1.00 MiB"
Note: The function uses binary prefixes where 1 KiB = 1024 bytes, 1 MiB = 1024 KiB, and 1 GiB = 1024 MiB.
func TimeStringToTime ¶ added in v1.0.4
TimeStringToTime parses a time string or returns the current time if the string is empty.
Parameters: - timeString: A string representing the time to be parsed.
Returns: - A pointer to a time.Time object representing the parsed time or the current time if the string is empty. - An error if the time string is not valid.
Types ¶
This section is empty.