Giter VIP home page Giter VIP logo

goutils's People

Contributors

aokoli avatar chiseok avatar dbarranco avatar josephmilla avatar mattfarina avatar mattlorimor avatar technosophos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goutils's Issues

IsEmpty

Use IsEmpty where appropriate (to replace str=="")

randNumeric returns values that are interpreted as octal

randNumeric returns values that are interpreted as octal. This causes problems when randNumeric returns numbers that are invalid octal numbers, like 08 and 09. Errors related to this happen silently when passed to mul and div, resulting in random numbers that are heavily weighted to 0.

EG: when running 1000 iterations of {{ mul (randNumeric 2) 6 }}, the top 5 chosen numbers and their count were:

number times chosen
30 16
156 17
24 17
468 18
0 36

When attempting things like {{ mul 08 6 }}, {{ div 09 3 }} a parse error arises, but when the octal numbers are generated by randNumeric the octal numbers are accepted and no error is seen.

Implement "useful" StringUtils methods

Implement some "fun/useful" methods from Java Apache Commons StringUtils. Methods such as:

  • abbreviate (COMPLETED)
  • indexOfDifference (COMPLETED)
  • deleteWhitespace (COMPLETED)
  • IndexOf (CharSeq, int, int) (COMPLETED)
  • IsEmpty (COMPLETED)
  • isBlank (COMPLETED)

We don't have to worry about "null safety" methods, as in Golang, strings cannot be assigned nil. Hence, there is no need to duplicate methods already located in the Go strings package for "null safety" considerations.

Bug for DeleteWhiteSpace when str is other utf8 string, eg. chinese

func TestDeleteWhiteSpace(t *testing.T) {

	// Test 1
	str := " a b c "
	out := "abc"

	if x := DeleteWhiteSpace(str); x != out {
		t.Errorf("IndexOf(%v) = %v, want %v", str, x, out)
	}

	// Test 2
	str = "    "
	out = ""

	if x := DeleteWhiteSpace(str); x != out {
		t.Errorf("IndexOf(%v) = %v, want %v", str, x, out)
	}

	// Test 3
	str = " 测试 测试 测试 "
	out = "测试测试测试"

	if x := DeleteWhiteSpace(str); x != out {
		t.Errorf("IndexOf(%v) = %v, want %v", str, x, out)
	}
}
$ go test

--- FAIL: TestDeleteWhiteSpace (0.00s)
    stringutils_test.go:157: IndexOf( 测试 测试 测试 ) = æµ�è¯�æµ�è¯�æµ�è¯�, want 测试测试测试
FAIL
exit status 1
FAIL    _/Users/xxxx/Github/goutils       0.371s

Check blank strings properly

Scan code base (mainly wordutils.go) for certain instances of str == "", and replace with goutils.IsBlank(str) IF there is no need to process str that is solely whitespace. (goutils.IsBlank(str) in addition to checking for str == "", ensures that a whitespace string, such as " " isn't used as str for further processing)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.