Code cleanup

This commit is contained in:
Roshan Ranabhat 2020-04-05 18:55:08 +05:45
parent ac326ac2d7
commit 7a6cec96c2
5 changed files with 25 additions and 21 deletions

View File

@ -2,61 +2,61 @@ package main
import ( import (
"fmt" "fmt"
. "github.com/gobeam/Stringy" stringy "github.com/gobeam/Stringy"
) )
func main() { func main() {
strBetween := New("HelloMyName") strBetween := stringy.New("HelloMyName")
fmt.Println(strBetween.Between("hello", "name").ToUpper()) fmt.Println(strBetween.Between("hello", "name").ToUpper())
teaseString := New("Hello My name is Roshan. I am full stack developer") teaseString := stringy.New("Hello My name is Roshan. I am full stack developer")
fmt.Println(teaseString.Tease(20, "...")) fmt.Println(teaseString.Tease(20, "..."))
replaceFirst := New("Hello My name is Roshan and his name is Alis.") replaceFirst := stringy.New("Hello My name is Roshan and his name is Alis.")
fmt.Println(replaceFirst.ReplaceFirst("name", "nombre")) fmt.Println(replaceFirst.ReplaceFirst("name", "nombre"))
replaceLast := New("Hello My name is Roshan and his name is Alis.") replaceLast := stringy.New("Hello My name is Roshan and his name is Alis.")
fmt.Println(replaceLast.ReplaceLast("name", "nombre")) fmt.Println(replaceLast.ReplaceLast("name", "nombre"))
snakeCase := New("ThisIsOne___messed up string. Can we Really Snake Case It?") snakeCase := stringy.New("ThisIsOne___messed up string. Can we Really Snake Case It?")
fmt.Println(snakeCase.SnakeCase("?", "").Get()) fmt.Println(snakeCase.SnakeCase("?", "").Get())
fmt.Println(snakeCase.SnakeCase("?", "").ToUpper()) fmt.Println(snakeCase.SnakeCase("?", "").ToUpper())
fmt.Println(snakeCase.SnakeCase("?", "").ToLower()) fmt.Println(snakeCase.SnakeCase("?", "").ToLower())
camelCase := New("ThisIsOne___messed up string. Can we Really camel-case It ?##") camelCase := stringy.New("ThisIsOne___messed up string. Can we Really camel-case It ?##")
fmt.Println(camelCase.CamelCase("?", "", "#", "")) fmt.Println(camelCase.CamelCase("?", "", "#", ""))
delimiterString := New("ThisIsOne___messed up string. Can we Really delimeter-case It?") delimiterString := stringy.New("ThisIsOne___messed up string. Can we Really delimeter-case It?")
fmt.Println(delimiterString.Delimited("?").Get()) fmt.Println(delimiterString.Delimited("?").Get())
contains := New("hello mam how are you??") contains := stringy.New("hello mam how are you??")
fmt.Println(contains.ContainsAll("mams", "?")) fmt.Println(contains.ContainsAll("mams", "?"))
lines := New("fòô\r\nbàř\nyolo123") lines := stringy.New("fòô\r\nbàř\nyolo123")
fmt.Println(lines.Lines()) fmt.Println(lines.Lines())
reverse := New("This is only test") reverse := stringy.New("This is only test")
fmt.Println(reverse.Reverse()) fmt.Println(reverse.Reverse())
pad := New("Roshan") pad := stringy.New("Roshan")
fmt.Println(pad.Pad(10, "0", "both")) fmt.Println(pad.Pad(10, "0", "both"))
fmt.Println(pad.Pad(10, "0", "left")) fmt.Println(pad.Pad(10, "0", "left"))
fmt.Println(pad.Pad(10, "0", "right")) fmt.Println(pad.Pad(10, "0", "right"))
shuffleString := New("roshan") shuffleString := stringy.New("roshan")
fmt.Println(shuffleString.Shuffle()) fmt.Println(shuffleString.Shuffle())
cleanString := New("special@#remove%%%%") cleanString := stringy.New("special@#remove%%%%")
fmt.Println(cleanString.RemoveSpecialCharacter()) fmt.Println(cleanString.RemoveSpecialCharacter())
boolString := New("off") boolString := stringy.New("off")
fmt.Println(boolString.Boolean()) fmt.Println(boolString.Boolean())
surroundStr := New("__") surroundStr := stringy.New("__")
fmt.Println(surroundStr.Surround("-")) fmt.Println(surroundStr.Surround("-"))
str := New("hello__man how-Are you??") str := stringy.New("hello__man how-Are you??")
result := str.CamelCase("?", "") result := str.CamelCase("?", "")
fmt.Println(result) // HelloManHowAreYou fmt.Println(result) // HelloManHowAreYou

View File

@ -1,4 +1,4 @@
package string_manipulation package stringy
import ( import (
"errors" "errors"

View File

@ -1,5 +1,6 @@
package string_manipulation package stringy
// const below are used in packages
const ( const (
First = "first" First = "first"
Last = "last" Last = "last"
@ -11,5 +12,8 @@ const (
ReplaceCapital = "$1 $2" ReplaceCapital = "$1 $2"
) )
// False is slice of array for false logical representation in string
var False = []string{"off", "no", "0", "false"} var False = []string{"off", "no", "0", "false"}
// True is slice of array for true logical representation in string
var True = []string{"on", "yes", "1", "True"} var True = []string{"on", "yes", "1", "True"}

View File

@ -1,4 +1,4 @@
package string_manipulation package stringy
import ( import (
"errors" "errors"

View File

@ -1,4 +1,4 @@
package string_manipulation package stringy
import ( import (
"testing" "testing"