Skip to content

Commit

Permalink
Merge pull request #21 from Henry-Sarabia/dev
Browse files Browse the repository at this point in the history
Major update v3.0.0
  • Loading branch information
Henry Sarabia authored Jul 31, 2019
2 parents b7c9f51 + 4212a32 commit 00aa240
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 39 deletions.
85 changes: 51 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# blank

[![GoDoc](https://godoc.org/github.com/Henry-Sarabia/blank?status.svg)](https://godoc.org/github.com/Henry-Sarabia/blank) [![Build Status](https://travis-ci.com/Henry-Sarabia/blank.svg?branch=master)](https://travis-ci.com/Henry-Sarabia/blank) [![Go Report Card](https://goreportcard.com/badge/github.com/Henry-Sarabia/blank)](https://goreportcard.com/report/github.com/Henry-Sarabia/blank) [![Coverage Status](https://coveralls.io/repos/github/Henry-Sarabia/blank/badge.svg?branch=master)](https://coveralls.io/github/Henry-Sarabia/blank?branch=master)
[![GoDoc](https://godoc.org/github.com/Henry-Sarabia/blank?status.svg)](https://godoc.org/github.com/Henry-Sarabia/blank)
[![Build Status](https://travis-ci.com/Henry-Sarabia/blank.svg?branch=master)](https://travis-ci.com/Henry-Sarabia/blank)
[![Go Report Card](https://goreportcard.com/badge/github.com/Henry-Sarabia/blank)](https://goreportcard.com/report/github.com/Henry-Sarabia/blank)
[![Coverage Status](https://coveralls.io/repos/github/Henry-Sarabia/blank/badge.svg?branch=master)](https://coveralls.io/github/Henry-Sarabia/blank?branch=master)

The **Blank** package offers two main functionalities.

**Blank** can remove whitespace from a string.
The package defines whitepsace as a character that is not typically visible.
These characters range anywhere from the ordinary space to a less common vertical tab.

**Blank** can check if a string is blank.
The package considers a string to be blank if it is comprised solely of whitespace.

Blank 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 blank package can help.

## Installation

If you do not have Go installed yet, you can find installation instructions
[here](https://golang.org/doc/install).

To pull the most recent version of blank, use `go get`.
To pull the most recent version of **Blank**, use `go get`.

```
go get github.com/Henry-Sarabia/blank
go get -u github.com/Henry-Sarabia/blank
```

Then import the package into your project.
Expand All @@ -26,52 +34,61 @@ import "github.com/Henry-Sarabia/blank"

## Usage

### Blank checking
### Whitespace Removal

The package considers whitespace to be any character that is not typically visible.
The most common of these characters are: space, tab, newline, return, formfeed, nonbreaking space, and vertical tab.
For more information, visit the [unicode package](https://golang.org/pkg/unicode/#IsSpace) and the [unicode seperator category](http://www.fileformat.info/info/unicode/category/Zs/list.htm).

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

```go
phrase := "this is a phrase"

str := blank.Remove(phrase)

fmt.Println(str)
// output: "thisisaphrase"
```

### Blank Detection

This package considers a string to be blank if it is solely made up of whitespace.
The package considers a string to be blank if it is comprised solely 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 blank package and the `Is(string)` function is most useful.
For example, assume we are creating a search function that takes a string as a search query.
We want to avoid searching for blank queries.
Blank queries can be detected using the `Is` function.

```go
func search(qry string) error {
if len(qry) == 0 {
// return some error
}

if blank.Is(qry) {
// return some other error
// return error
}

// rest of code
}
```

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

### Whitespace Removal
Similarly, the `Has` function can process an entire slice of strings; it will check if any of the strings are blank.

This package considers whitespace to be any of these common characters: space, tab, newline, and
return. Other uncommon whitespace characters such as nonbreaking space and vertical tab are now supported
as well.

To remove the whitespace from a string, use the `Remove(string)` function.
Let's slightly alter our example.
Assume the search function takes a slice of strings as a list of queries.
We still want to avoid seraching for blank queries.
Blank queries can be detected using the `Has` function.

```go
phrase := "this is a phrase"

str := blank.RemoveSpace(phrase)

fmt.Println(str)
// output: "thisisaphrase"
func search(qrs []string) error {
if blank.Has(qrs) {
// return error
}

// rest of code
}
```

## Contributions

If you would like to contribute to this project, please adhere to the following
guidelines.
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.
Expand Down
6 changes: 3 additions & 3 deletions blank.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"unicode"
)

// RemoveSpace returns the provided string with all of the whitespace removed.
// Remove returns the provided string with all whitespace removed.
// This includes spaces, tabs, newlines, returns, form feeds and other
// space-like characters.
//
// For more information on what is considered whitespace, visit:
// https://golang.org/pkg/unicode/#IsSpace
func RemoveSpace(str string) string {
func Remove(str string) string {
var out []rune
for _, r := range str {
if !unicode.IsSpace(r) {
Expand All @@ -24,7 +24,7 @@ func RemoveSpace(str string) string {
// Is returns true if the provided string is empty or consists only of
// whitespace. Returns false otherwise.
func Is(str string) bool {
if RemoveSpace(str) == "" {
if Remove(str) == "" {
return true
}

Expand Down
4 changes: 2 additions & 2 deletions blank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package blank

import "testing"

func TestRemoveSpace(t *testing.T) {
func TestRemove(t *testing.T) {
tests := []struct {
name string
input string
Expand All @@ -29,7 +29,7 @@ func TestRemoveSpace(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
s := RemoveSpace(test.input)
s := Remove(test.input)

if s != test.want {
t.Errorf("got: <%v>, want: <%v>", s, test.want)
Expand Down

0 comments on commit 00aa240

Please # to comment.