whitespace

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 1 Imported by: 0

README

whitespace

GoDoc Build Status Go Report Card Coverage Status

Whitespace implements blank checking and whitespace removal for strings. There are times when you only need to make sure your string arguments are not empty. However, there are other times when you need to not only make sure they aren't empty, but also not blank or made up of whitespace. This is where the whitespace package can help.

Installation

If you do not have Go installed yet, you can find installation instructions here.

To pull the most recent version of whitespace, use go get.

go get github.com/Henry-Sarabia/whitespace

Then import the package into your project.

import "github.com/Henry-Sarabia/whitespace"

Usage

Whitespace Removal

This package considers whitespace to be any of these common characters: space, tab, newline, and return.

To remove the whitespace from a string, use the Remove(string) function.

phrase := "this is a phrase"

str := whitespace.Remove(phrase)

fmt.Println(str)
// output: "thisisaphrase"
Blank checking

This package considers a string to be blank if it is solely made up of whitespace.

As an example, assume you are creating a search function that takes a string argument as the search query. You want to avoid searching for any empty queries. This includes both empty strings and blank strings. The first case can be resolved by comparing the string against the empty string. The second case is where the whitespace package and the IsBlank(string) function is most useful.

func search(qry string) error {
	if len(qry) == 0 {
		// return some error
	}
	
	if whitespace.IsBlank(qry) {
		// return some other error
	}
	
	// rest of code
}

Similarly, the HasBlank([]string) function can check an entire slice of strings for blanks.

Contributions

If you would like to contribute to this project, please adhere to the following guidelines.

  • Submit an issue describing the problem.
  • Fork the repo and add your contribution.
  • Add appropriate tests.
  • Run go fmt, go vet, and golint.
  • Prefer idiomatic Go over non-idiomatic code.
  • Follow the basic Go conventions found here.
  • If in doubt, try to match your code to the current codebase.
  • Create a pull request with a description of your changes.

I'll review pull requests as they come in and merge them if everything checks out.

Any and all contributions are greatly appreciated. Thank you!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasBlank

func HasBlank(slice []string) bool

HasBlank returns true if any of the strings in the provided slice is empty or consists of whitespace. If the slice is nil, returns true as well. Returns false otherwise.

func IsBlank

func IsBlank(str string) bool

IsBlank returns true if the provided string is empty or only consists of whitespace. Returns false otherwise.

func Remove

func Remove(str string) string

Remove returns the provided string with all of the whitespace removed. This includes spaces, tabs, newlines, returns, and form feeds.

Types

This section is empty.

Jump to

Keyboard shortcuts

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