Re: [go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-06 Thread Steven Hartland
You other option is: splittable == v != ' ' && v == unicode.ToLower(v), depends what you want to happen with non-word characters? On 06/09/2017 16:15, Michael Jones wrote: Precisely, though probably a renaming is in order: https://play.golang.org/p/AZ7Ptg4HYP On Wed, Sep 6, 2017 at 6:58 AM, S

Re: [go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-06 Thread Michael Jones
Precisely, though probably a renaming is in order: https://play.golang.org/p/AZ7Ptg4HYP On Wed, Sep 6, 2017 at 6:58 AM, Steven Hartland wrote: > Numbers don't match IsLower so how about: > https://play.golang.org/p/Z6q9dJZ7QK > > > On 06/09/2017 14:12, Tong Sun wrote: > > Almost, https://play.go

Re: [go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-06 Thread Steven Hartland
Numbers don't match IsLower so how about: https://play.golang.org/p/Z6q9dJZ7QK On 06/09/2017 14:12, Tong Sun wrote: Almost, https://play.golang.org/p/6Zl_EKqFqT But thanks a lot! It's significantly shorter/better than my initial version. On Tue, Sep 5, 2017 at 6:18 PM, Michael Jones

Re: [go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-06 Thread Tong Sun
Almost, https://play.golang.org/p/6Zl_EKqFqT But thanks a lot! It's significantly shorter/better than my initial version. On Tue, Sep 5, 2017 at 6:18 PM, Michael Jones wrote: > Like this? > > https://play.golang.org/p/OIE8jdWVGB > > On Tue, Sep 5, 2017 at 12:33 PM, Tong Sun wrote: > >> >> I'll

Re: [go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-05 Thread Michael Jones
Like this? https://play.golang.org/p/OIE8jdWVGB On Tue, Sep 5, 2017 at 12:33 PM, Tong Sun wrote: > > I'll be religiously avoiding "*unicode.IsUpper*()" as something mystery > happened in the past: > https://groups.google.com/d/msg/golang-nuts/714WQs85H3w/KEqKgmAqAAAJ > > BTW, *for my case*, I d

Re: [go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-05 Thread Tong Sun
I'll be religiously avoiding "*unicode.IsUpper*()" as something mystery happened in the past: https://groups.google.com/d/msg/golang-nuts/714WQs85H3w/KEqKgmAqAAAJ BTW, *for my case*, I do need the string, "FooBarBaz GNU PYTHON Standard" to be split exactly to be "Foo Bar Baz GNU PYTHON Standard

Re: [go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-05 Thread Florian Florensen
I've just joined the group and had to get activated, that's why my answer took so long. Should have waited until then. Thank you for the notice! I fixed it in the playground: https://play.golang.org/p/kuk6FxesDq. Although I wrote a benchmark (https://play.golang.org/p/YpnI257SHD), I didn't writ

Re: [go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-04 Thread Tong Sun
Oh thanks a lot Florian! I wished I had received it earlier (my email header said, Created at: Sun, Sep 3, 2017 at 6:03 PM (Delivered after 89531 seconds)), because my own version is embarrassingly complicated: https://github.com/go-dedup/text/blob/3d0d998bef3db3937496933778c55e4f01cab5e4/text.go

[go-nuts] Re: Splitting CamelCaseWords in Go

2017-09-04 Thread Florian Florensen
Hi, two approaches would be: func camelAppend(str string) string { w := []rune(str) for i := len(w) - 1; i > 1; i-- { if unicode.IsUpper(w[i]) { w = append(w[:i], append([]rune{' '}, w[i:]...)...) } } return string(w) } func camelRegexp(str string) string { re := regexp.Mu