<br><br><div class="gmail_quote">On Thu, Mar 11, 2010 at 6:17 PM, Levente Uzonyi <span dir="ltr">&lt;<a href="mailto:leves@elte.hu">leves@elte.hu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Thu, 11 Mar 2010, Travis Griggs wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
(Preamble: I have lurked here without really paying attention much for a year+ now. I thought I&#39;d try to reinvolve myself. The following discussions are some of my favorite/funnest).<br>
<br>
I was looking at someone&#39;s ruby/regex code. I could do the equivalent of what they were doing with the ST Regex library. But I was curious if it could be done tersely/elegantly without using regex. Here&#39;s the challenge.<br>

<br>
Given strings of the form<br>
<br>
&#39;This is a (string) with some (parenthetical fields)&#39;<br>
<br>
turn them into<br>
<br>
&#39;This is a (STRING) with some (PARENTHETICAL FIELDS)&#39;<br>
</blockquote>
<br></div>
(((&#39;This is a (string) with some (parenthetical fields)&#39; findTokens: &#39;()&#39;) collectWithIndex: [ :each :index | index odd ifFalse: [ &#39;(&#39;, each asUppercase, &#39;)&#39; ] ifTrue: [ each ] ]) gather: #yourself) as: String.<br>

<br>
&#39;This is a (string) with some (parenthetical fields)&#39; in: [ :string | | transformation | transformation := #yourself. string collect: [ :each | (transformation := each = $( ifTrue: [ #asUppercase ] ifFalse: [ each = $) ifTrue: [ #yourself ] ifFalse: [ transformation ] ]) value: each ] ].<br>

<br>
&#39;This is a (string) with some (parenthetical fields)&#39; in: [ :string | String streamContents: [ :output | | input | input := string readStream. [ input atEnd ] whileFalse: [ output nextPutAll: (input upTo: $(); nextPut: $(; nextPutAll: (input upTo: $)) asUppercase; nextPut: $) ] ] ].<br>

<br>
Let me know which if your favorite. ;)<br></blockquote><div><br></div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><div>inelegant &amp; obvious but terse:</div>
<div><br></div></span><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">| inp | inp := false. &#39;This is a (string) with some (parenthetical fields)&#39; collect: [:c| (inp := c = $( or: [inp and: [c ~= $)]]) ifTrue: [c asUppercase] ifFalse: [c]]</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "></span> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font color="#888888">
<br>
<br>
Levente</font><div><div></div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
--<br>
Travis Griggs<br>
Objologist<br>
&quot;Dying men never wish they&#39;d spent more time at the office&quot;<br>
<br>
<br>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br>