Thank you very much, Kasper! Even with an implementation, wow.. I will use
your solution.

cheers
Siemen


On Sat, Oct 22, 2022 at 4:08 PM Kasper Osterbye <kasper.oster...@gmail.com>
wrote:

> I took this a my afternoon code-quiz, so here is a solution if you want it:
> splitCamelCase
>         | str split word|
>         "Split an expanded camelcase word into constituents. Extened camel
> case allow some words to be fully uppercase"
>         "'ZAPMeToo' splitCamelCase >>> #('ZAP' 'Me' 'Too')"
>         str := ReadStream on: self.
>         split := OrderedCollection new.
>         word := WriteStream on: ''.
>         [ str atEnd ] whileFalse: [ | char |
>                 char := str next.
>                 (char isUppercase and: [str atEnd or: [str peek
> isLowercase]])
>                         ifTrue: [ split add: word contents. word :=
> WriteStream on: '' ].
>                 word nextPut: char ].
>         split add: word contents.
>         ^ split asArray
>
> You should then use cute join and asLowercase to go rest of the way.
>
> Best,
>
> Kasper
>
>
>
> > On 22 Oct 2022, at 14.53, Kasper Osterbye <kasper.oster...@gmail.com>
> wrote:
> >
> > My feeling is that it cannot be solved by regular expressions. The
> reason it that there is the regular expressions in smalltalk/pharo does not
> have look-ahead or backtracking. In your example the capital Y is part of
> MY, but C starts a new word. I do not know of anyway to express that in
> smalltalk regular expressions.
> >
> > So I believe this is one of the cases where you add an extension method
> to string which does the job using plain coding.
> >
> > Best,
> >
> > Kasper
> >
> >> On 22 Oct 2022, at 10.56, Siemen Baader <siemenbaa...@gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> I'm looking for an elegant way to convert class names with optional
> namespace prefixes to names for custom html elements.
> >>
> >> MYCustomElement and CustomElement
> >>
> >> to
> >> <my-custom-element> and <custom-element>
> >>
> >> There must be an elegant way to do it with regex or inject, but I'm
> embarrassed to say I can't get my head around it. I can get it to match the
> regex '((:isUppercase:+)*)((:isUppercase::isLowercase:+)*)', (if I recall
> correctly) but can't get a collection of the individual elements 'MY'
> 'Custom" 'Element' to lowercase and join.
> >>
> >> Thanks for any hints!
> >>
> >> cheers
> >> Siemen
> >
>

Reply via email to