Skip to content

Commit

Permalink
Merge pull request #9 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.3.1
  • Loading branch information
andyone committed Dec 27, 2015
2 parents af6475b + 6711cbb commit ee32369
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

#### v1.3.1

* `[strutil]` Added method Head for subtraction first symbols from the string
* `[strutil]` Added method Tail for subtraction last symbols from the string

#### v1.3

* `[system]` Fixed major bug with OS X compatibility
Expand Down
30 changes: 30 additions & 0 deletions strutil/strutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,33 @@ func Ellipsis(s string, maxSize int) string {

return s
}

// Head return n first symbols from given string
func Head(s string, n int) string {
if s == "" || n <= 0 {
return ""
}

l := len(s)

if l <= n {
return s
}

return s[:n]
}

// Tail return n last symbols from given string
func Tail(s string, n int) string {
if s == "" || n <= 0 {
return ""
}

l := len(s)

if l <= n {
return s
}

return s[n:]
}
16 changes: 16 additions & 0 deletions strutil/strutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ func (s *StrUtilSuite) TestEllipsis(c *C) {
c.Assert(Ellipsis("Test1234", 8), Equals, "Test1234")
c.Assert(Ellipsis("Test1234test", 8), Equals, "Test1...")
}

func (s *StrUtilSuite) TestHead(c *C) {
c.Assert(Head("", 1), Equals, "")
c.Assert(Head("ABCD1234", 0), Equals, "")
c.Assert(Head("ABCD1234", -10), Equals, "")
c.Assert(Head("ABCD1234", 4), Equals, "ABCD")
c.Assert(Head("ABCD1234", 100), Equals, "ABCD1234")
}

func (s *StrUtilSuite) TestTail(c *C) {
c.Assert(Tail("", 1), Equals, "")
c.Assert(Tail("ABCD1234", 0), Equals, "")
c.Assert(Tail("ABCD1234", -10), Equals, "")
c.Assert(Tail("ABCD1234", 4), Equals, "1234")
c.Assert(Tail("ABCD1234", 100), Equals, "ABCD1234")
}

0 comments on commit ee32369

Please sign in to comment.