From 174dd408c5c09c99e1b5dca2ceaca0866681688a Mon Sep 17 00:00:00 2001 From: wulfheart Date: Sat, 20 Feb 2021 11:28:09 +0100 Subject: [PATCH 1/9] Outline --- .idea/.gitignore | 8 +++ .idea/modules.xml | 8 +++ .idea/support.iml | 8 +++ .idea/vcs.xml | 6 ++ str/str.go | 170 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/support.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..15c91df --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../../:\code\confetti\dev\support\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8efe1e3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/support.iml b/.idea/support.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/support.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/str/str.go b/str/str.go index fcdb32c..0a04634 100644 --- a/str/str.go +++ b/str/str.go @@ -19,3 +19,173 @@ func InSlice(input interface{}, expects ...interface{}) bool { } return false } + +func After(subject string, search string) string { + // TODO + return "" +} + +func AfterLast(subject string, search string) string { + // TODO + return "" +} + +func Before(subject string, search string) string { + // TODO + return "" +} + +func BeforeLast(subject string, search string) string { + // TODO + return "" +} + +func Between(subject string, from string, to string) string { + // TODO + return "" +} + +func Contains(haystack string, needle string) bool { + // TODO + return false +} + +func ContainsInSlice(haystack string, needle []string) bool { + // TODO + return false +} + +func ContainsAllInSlice(haystack string, needle []string) bool { + // TODO + return false +} + +func EndsWith(haystack string, needle string) bool { + // TODO + return false +} + +func Finish(value string, cap string) string { + // TODO + return "" +} + +func Kebab(vale string) string { + // TODO + return "" +} + +func Length(value string) int { + // TODO + return 0 +} + +func LimitCharacters(value string, limit int, end string) string{ + // TODO + return "" +} + +func LimitWords(value string, limit int, end string) string{ + // TODO + return "" +} + +func Lower(value string) string { + // TODO + return "" +} + +func PadBoth(value string, length int, pad string) string { + // TODO + return "" +} + +func PadLeft(value string, length int, pad string) string { + // TODO + return "" +} + +func PadRight(value string, length int, pad string) string { + // TODO + return "" +} + +func ReplaceArray(search string, replace []string, subject string) string { + // TODO + return "" +} + +func ReplaceFirst(search string, replace string, subject string) string { + // TODO + return "" +} + +func ReplaceLast(search string, replace string, subject string) string { + // TODO + return "" +} + +func Start(value string, prefix string) string { + // TODO + return "" +} + +func Slug(value string) string { + // TODO + return "" +} +func SlugWithDelimiter(value string, delimiter string) string { + // TODO + return "" +} + +func Snake(value string) string { + // TODO + return "" +} + +func SnakeWithDelimiter(value string, delimiter string) string { + // TODO + return "" +} + +func StartsWith(haystack string, needle string) string { + // TODO + return "" +} + +func Studly(value string) string { + // TODO + return "" +} + +func Upper(value string) string { + // TODO + return "" +} + +func Title(value string) string { + // TODO + return "" +} + + + + + + + + + + + + + + + + + + + + + From cf2a4ce28009adf49a6709381538748405432c6e Mon Sep 17 00:00:00 2001 From: wulfheart Date: Sat, 20 Feb 2021 12:02:23 +0100 Subject: [PATCH 2/9] After Issues --- .gitignore | 3 +++ str/str.go | 25 +++++++++++++++++++++++-- str/str_test.go | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 str/str_test.go diff --git a/.gitignore b/.gitignore index 8dd807d..5105a17 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ # Dependency directories vendor + +# IDE Files +.idea diff --git a/str/str.go b/str/str.go index 0a04634..70df62d 100644 --- a/str/str.go +++ b/str/str.go @@ -1,6 +1,9 @@ package str -import "unicode" +import ( + "strings" + "unicode" +) func UpperFirst(input string) string { if len(input) == 0 { @@ -20,9 +23,22 @@ func InSlice(input interface{}, expects ...interface{}) bool { return false } +// Return the remainder of a string after the first occurrence of a given value. func After(subject string, search string) string { // TODO - return "" + l := len(search) + if l == 0 { + return subject + } + + strs := strings.Index(subject, search) + if strs == -1 { + return subject + } + runes := []rune(subject) + + result := string(runes[strs + l:]) + return result } func AfterLast(subject string, search string) string { @@ -159,6 +175,11 @@ func Studly(value string) string { return "" } +func UcFirst(value string) string { + // TODO + return "" +} + func Upper(value string) string { // TODO return "" diff --git a/str/str_test.go b/str/str_test.go new file mode 100644 index 0000000..c7b75c0 --- /dev/null +++ b/str/str_test.go @@ -0,0 +1,18 @@ +package str + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestAfter(t *testing.T) { + + assert.Equal(t, "nah", After("hannah", "han")) + assert.Equal(t, "nah", After("hannah", "n")) + assert.Equal(t, "nah", After("eee hannah", "han")) + assert.Equal(t, "nah", After("ééé hannah", "han")) + assert.Equal(t, "hannah", After("hannah", "xxxx")) + assert.Equal(t, "hannah", After("hannah", "")) + assert.Equal(t, "nah", After("han0nah", "0")) + assert.Equal(t, "nah", After("han2nah", "2")) +} From 813e797733322b82fab51f9d33c25469abdffce5 Mon Sep 17 00:00:00 2001 From: wulfheart Date: Sat, 20 Feb 2021 12:52:09 +0100 Subject: [PATCH 3/9] StringAfter Passing --- str/str.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/str/str.go b/str/str.go index 70df62d..a980761 100644 --- a/str/str.go +++ b/str/str.go @@ -31,13 +31,15 @@ func After(subject string, search string) string { return subject } - strs := strings.Index(subject, search) - if strs == -1 { + + byteIndex := strings.Index(subject, search) + if byteIndex == -1 { return subject } - runes := []rune(subject) + byteSubject := []byte(subject) + byteSearch := []byte(search) - result := string(runes[strs + l:]) + result := string(byteSubject[byteIndex+ len(byteSearch):]) return result } From c9ffa56aa2bb687286e9146297a9b84d9be7053b Mon Sep 17 00:00:00 2001 From: wulfheart Date: Sat, 20 Feb 2021 12:56:07 +0100 Subject: [PATCH 4/9] AfterLast Working --- str/str.go | 21 +++++++++++++++++---- str/str_test.go | 13 +++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/str/str.go b/str/str.go index a980761..fe27ef0 100644 --- a/str/str.go +++ b/str/str.go @@ -25,17 +25,16 @@ func InSlice(input interface{}, expects ...interface{}) bool { // Return the remainder of a string after the first occurrence of a given value. func After(subject string, search string) string { - // TODO l := len(search) if l == 0 { return subject } - byteIndex := strings.Index(subject, search) if byteIndex == -1 { return subject } + byteSubject := []byte(subject) byteSearch := []byte(search) @@ -43,9 +42,23 @@ func After(subject string, search string) string { return result } +// Return the remainder of a string after the last occurrence of a given value. func AfterLast(subject string, search string) string { - // TODO - return "" + l := len(search) + if l == 0 { + return subject + } + + byteIndex := strings.LastIndex(subject, search) + if byteIndex == -1 { + return subject + } + + byteSubject := []byte(subject) + byteSearch := []byte(search) + + result := string(byteSubject[byteIndex+ len(byteSearch):]) + return result } func Before(subject string, search string) string { diff --git a/str/str_test.go b/str/str_test.go index c7b75c0..7b23ed8 100644 --- a/str/str_test.go +++ b/str/str_test.go @@ -16,3 +16,16 @@ func TestAfter(t *testing.T) { assert.Equal(t, "nah", After("han0nah", "0")) assert.Equal(t, "nah", After("han2nah", "2")) } + +func TestAfterLast(t *testing.T) { + assert.Equal(t,"tte", AfterLast("yvette", "yve")) + assert.Equal(t,"e", AfterLast("yvette", "t")) + assert.Equal(t,"e", AfterLast("ééé yvette", "t")) + assert.Equal(t,"", AfterLast("yvette", "tte")) + assert.Equal(t,"yvette", AfterLast("yvette", "xxxx")) + assert.Equal(t,"yvette", AfterLast("yvette", "")) + assert.Equal(t,"te", AfterLast("yv0et0te", "0")) + assert.Equal(t,"te", AfterLast("yv0et0te", "0")) + assert.Equal(t,"te", AfterLast("yv2et2te", "2")) + assert.Equal(t,"foo", AfterLast("----foo", "---")) +} From 682fdb173809af29db71824716bd54b31146e48f Mon Sep 17 00:00:00 2001 From: wulfheart Date: Sat, 20 Feb 2021 13:04:43 +0100 Subject: [PATCH 5/9] Between added --- str/str.go | 39 +++++++++++++++++++++++++++++++++------ str/str_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/str/str.go b/str/str.go index fe27ef0..d65b321 100644 --- a/str/str.go +++ b/str/str.go @@ -61,19 +61,46 @@ func AfterLast(subject string, search string) string { return result } +// Get the portion of a string before the first occurrence of a given value. func Before(subject string, search string) string { - // TODO - return "" + l := len(search) + if l == 0 { + return subject + } + + byteIndex := strings.Index(subject, search) + if byteIndex == -1 { + return subject + } + + byteSubject := []byte(subject) + + result := string(byteSubject[:byteIndex]) + return result } func BeforeLast(subject string, search string) string { - // TODO - return "" + l := len(search) + if l == 0 { + return subject + } + + byteIndex := strings.LastIndex(subject, search) + if byteIndex == -1 { + return subject + } + + byteSubject := []byte(subject) + + result := string(byteSubject[:byteIndex]) + return result } func Between(subject string, from string, to string) string { - // TODO - return "" + if len(from) == 0 || len(to) == 0 { + return subject + } + return BeforeLast(After(subject, from), to) } func Contains(haystack string, needle string) bool { diff --git a/str/str_test.go b/str/str_test.go index 7b23ed8..8ae8f2c 100644 --- a/str/str_test.go +++ b/str/str_test.go @@ -29,3 +29,40 @@ func TestAfterLast(t *testing.T) { assert.Equal(t,"te", AfterLast("yv2et2te", "2")) assert.Equal(t,"foo", AfterLast("----foo", "---")) } + +func TestBefore(t *testing.T) { + assert.Equal(t, "han", Before("hannah", "nah")) + assert.Equal(t, "ha", Before("hannah", "n")) + assert.Equal(t, "ééé ", Before("ééé hannah", "han")) + assert.Equal(t, "hannah", Before("hannah", "xxxx")) + assert.Equal(t, "hannah", Before("hannah", "")) + assert.Equal(t, "han", Before("han0nah", "0")) + assert.Equal(t, "han", Before("han0nah", "0")) + assert.Equal(t, "han", Before("han2nah", "2")) +} + +func TestBeforeLast(t *testing.T) { + assert.Equal(t,"yve", BeforeLast("yvette", "tte")) + assert.Equal(t,"yvet", BeforeLast("yvette", "t")) + assert.Equal(t,"ééé ", BeforeLast("ééé yvette", "yve")) + assert.Equal(t,"", BeforeLast("yvette", "yve")) + assert.Equal(t,"yvette", BeforeLast("yvette", "xxxx")) + assert.Equal(t,"yvette", BeforeLast("yvette", "")) + assert.Equal(t,"yv0et", BeforeLast("yv0et0te", "0")) + assert.Equal(t,"yv0et", BeforeLast("yv0et0te", "0")) + assert.Equal(t,"yv2et", BeforeLast("yv2et2te", "2")) +} + +func TestBetween(t *testing.T) { + assert.Equal(t,"abc", Between("abc", "", "c")) + assert.Equal(t,"abc", Between("abc", "a", "")) + assert.Equal(t,"abc", Between("abc", "", "")) + assert.Equal(t,"b", Between("abc", "a", "c")) + assert.Equal(t,"b", Between("dddabc", "a", "c")) + assert.Equal(t,"b", Between("abcddd", "a", "c")) + assert.Equal(t,"b", Between("dddabcddd", "a", "c")) + assert.Equal(t,"nn", Between("hannah", "ha", "ah")) + assert.Equal(t,"a]ab[b", Between("[a]ab[b]", "[", "]")) + assert.Equal(t,"foo", Between("foofoobar", "foo", "bar")) + assert.Equal(t,"bar", Between("foobarbar", "foo", "bar")) +} From b8c8bd7bd6b6234c3dae1e3135081950443d40ae Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 20 Feb 2021 13:05:19 +0100 Subject: [PATCH 6/9] Delete vcs.xml --- .idea/vcs.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 6249fd2f7335cb45ba4bb713786804f1c75e15f0 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 20 Feb 2021 13:05:33 +0100 Subject: [PATCH 7/9] Delete .idea directory --- .idea/.gitignore | 8 -------- .idea/modules.xml | 8 -------- .idea/support.iml | 8 -------- 3 files changed, 24 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/modules.xml delete mode 100644 .idea/support.iml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 15c91df..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/../../../../../../:\code\confetti\dev\support\.idea/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 8efe1e3..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/support.iml b/.idea/support.iml deleted file mode 100644 index c956989..0000000 --- a/.idea/support.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file From 5d7008707722afcf8c2a9cb8c288774634878cc0 Mon Sep 17 00:00:00 2001 From: wulfheart Date: Sat, 20 Feb 2021 13:07:42 +0100 Subject: [PATCH 8/9] Gitignore update --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5105a17..414e4d9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,4 @@ vendor # IDE Files -.idea +.idea/ From 01573e5656e67b16fd310572cca4e61efdb12968 Mon Sep 17 00:00:00 2001 From: wulfheart Date: Sat, 13 Mar 2021 21:01:01 +0100 Subject: [PATCH 9/9] Still some things to do --- str/str.go | 11 +++++------ str/str_test.go | 14 ++++++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/str/str.go b/str/str.go index d65b321..cc6fadc 100644 --- a/str/str.go +++ b/str/str.go @@ -27,7 +27,7 @@ func InSlice(input interface{}, expects ...interface{}) bool { func After(subject string, search string) string { l := len(search) if l == 0 { - return subject + return "" } byteIndex := strings.Index(subject, search) @@ -46,7 +46,7 @@ func After(subject string, search string) string { func AfterLast(subject string, search string) string { l := len(search) if l == 0 { - return subject + return "" } byteIndex := strings.LastIndex(subject, search) @@ -104,16 +104,15 @@ func Between(subject string, from string, to string) string { } func Contains(haystack string, needle string) bool { - // TODO - return false + return strings.Index(haystack, needle) == -1 } -func ContainsInSlice(haystack string, needle []string) bool { +func ContainsFromSlice(haystack string, needle []string) bool { // TODO return false } -func ContainsAllInSlice(haystack string, needle []string) bool { +func ContainsAllFromSlice(haystack string, needle []string) bool { // TODO return false } diff --git a/str/str_test.go b/str/str_test.go index 8ae8f2c..c4226e3 100644 --- a/str/str_test.go +++ b/str/str_test.go @@ -6,24 +6,29 @@ import ( ) func TestAfter(t *testing.T) { - + // TODO: What if nothing is found? + assert.Equal(t, "", After("", "")) + assert.Equal(t, "", After("hannah", "")) + assert.Equal(t, "", After("", "han")) assert.Equal(t, "nah", After("hannah", "han")) assert.Equal(t, "nah", After("hannah", "n")) assert.Equal(t, "nah", After("eee hannah", "han")) assert.Equal(t, "nah", After("ééé hannah", "han")) assert.Equal(t, "hannah", After("hannah", "xxxx")) - assert.Equal(t, "hannah", After("hannah", "")) assert.Equal(t, "nah", After("han0nah", "0")) assert.Equal(t, "nah", After("han2nah", "2")) } func TestAfterLast(t *testing.T) { + // TODO: What if nothing is found? + assert.Equal(t, "", After("", "")) + assert.Equal(t, "", After("hannah", "")) + assert.Equal(t, "", After("", "han")) assert.Equal(t,"tte", AfterLast("yvette", "yve")) assert.Equal(t,"e", AfterLast("yvette", "t")) assert.Equal(t,"e", AfterLast("ééé yvette", "t")) assert.Equal(t,"", AfterLast("yvette", "tte")) assert.Equal(t,"yvette", AfterLast("yvette", "xxxx")) - assert.Equal(t,"yvette", AfterLast("yvette", "")) assert.Equal(t,"te", AfterLast("yv0et0te", "0")) assert.Equal(t,"te", AfterLast("yv0et0te", "0")) assert.Equal(t,"te", AfterLast("yv2et2te", "2")) @@ -35,7 +40,6 @@ func TestBefore(t *testing.T) { assert.Equal(t, "ha", Before("hannah", "n")) assert.Equal(t, "ééé ", Before("ééé hannah", "han")) assert.Equal(t, "hannah", Before("hannah", "xxxx")) - assert.Equal(t, "hannah", Before("hannah", "")) assert.Equal(t, "han", Before("han0nah", "0")) assert.Equal(t, "han", Before("han0nah", "0")) assert.Equal(t, "han", Before("han2nah", "2")) @@ -66,3 +70,5 @@ func TestBetween(t *testing.T) { assert.Equal(t,"foo", Between("foofoobar", "foo", "bar")) assert.Equal(t,"bar", Between("foobarbar", "foo", "bar")) } + +