<br><br><div class="gmail_quote">On Thu, Mar 11, 2010 at 6:17 PM, Levente Uzonyi <span dir="ltr"><<a href="mailto:leves@elte.hu">leves@elte.hu</a>></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'd try to reinvolve myself. The following discussions are some of my favorite/funnest).<br>
<br>
I was looking at someone'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's the challenge.<br>
<br>
Given strings of the form<br>
<br>
'This is a (string) with some (parenthetical fields)'<br>
<br>
turn them into<br>
<br>
'This is a (STRING) with some (PARENTHETICAL FIELDS)'<br>
</blockquote>
<br></div>
((('This is a (string) with some (parenthetical fields)' findTokens: '()') collectWithIndex: [ :each :index | index odd ifFalse: [ '(', each asUppercase, ')' ] ifTrue: [ each ] ]) gather: #yourself) as: String.<br>
<br>
'This is a (string) with some (parenthetical fields)' in: [ :string | | transformation | transformation := #yourself. string collect: [ :each | (transformation := each = $( ifTrue: [ #asUppercase ] ifFalse: [ each = $) ifTrue: [ #yourself ] ifFalse: [ transformation ] ]) value: each ] ].<br>
<br>
'This is a (string) with some (parenthetical fields)' 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 & 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. 'This is a (string) with some (parenthetical fields)' 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>
"Dying men never wish they'd spent more time at the office"<br>
<br>
<br>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br>