utility

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2016 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package utility contains utility functions used by the whole Documize ecosystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeautifyFilename

func BeautifyFilename(fn string) string

BeautifyFilename takes a filename and attempts to turn it into a readable form, as TitleCase natural language, suitable for the top level of a Document.

func Close

func Close(f interface{})

Close is a convenience function to close an io.Closer, usually in a defer.

func CommandWithTimeout

func CommandWithTimeout(command *exec.Cmd, timeout time.Duration) ([]byte, error)

CommandWithTimeout runs a command but stops it if it does not finish within the timout above.

func DecodeBase64

func DecodeBase64(b []byte) ([]byte, error)

DecodeBase64 is a convenience function to decode using StdEncoding.

func DecryptAES

func DecryptAES(text []byte) ([]byte, error)

DecryptAES decrypts an AES encoded []byte, using a hard-wired key value, suitable for use when reading an authentication token.

func EncodeBase64

func EncodeBase64(b []byte) []byte

EncodeBase64 is a convenience function to encode using StdEncoding.

func EscapeHTMLcomplexChars

func EscapeHTMLcomplexChars(s string) string

EscapeHTMLcomplexChars looks for "complex" characters within HTML and replaces them with the HTML escape codes which describe them. "Complex" characters are those encoded in more than one byte by UTF8.

func EscapeHTMLcomplexCharsByte

func EscapeHTMLcomplexCharsByte(b []byte) []byte

EscapeHTMLcomplexCharsByte looks for "complex" characters within HTML and replaces them with the HTML escape codes which describe them. "Complex" characters are those encoded in more than one byte by UTF8.

func MakeAES

func MakeAES(secret string) ([]byte, error)

MakeAES creates an AES encryption of of a given string, using a hard-wired key value, suitable for use as an authentication token.

func MakeInitials

func MakeInitials(firstname, lastname string) string

MakeInitials returns user initials from firstname and lastname.

func MakeSlug

func MakeSlug(str string) string

MakeSlug creates a slug, suitable for use in a URL, from a string

func Words

func Words(ch HTML, inSqBr int, testMode bool) ([]string, int, error)

Words returns a slice of words, where each word contains no whitespace, and each item of punctuation is its own word. This functionality is provided to enable verification of the text extraction algorithem across different implemntations.

Types

type HTML

type HTML string

HTML describes a chunk of HTML, Text() method returns plain text.

func (HTML) Text

func (ch HTML) Text(isTest bool) (string, error)

Text returns only the plain text elements of the HTML Chunk, concatanated with "\n", for use in the TOC or for text indexing.

Jump to

Keyboard shortcuts

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