Word 1 to -1 Truncating Entire Paragraphs?

Ken Ray kray at sonsothunder.com
Fri Nov 11 18:21:53 EST 2005


On 11/11/05 1:57 PM, "Sivakatirswami" <katir at hindu.org> wrote:

> I have test this by simply commenting out this line:
> 
>     -- put word 1 to -1 of fld "transcript" into tFinalTranscript
>          put fld "transcript" into tFinalTranscript
> 
> and the entire transcript is delivered to the variable.. it's that "
> word 1 to -1" which is chopping of entire blocks of text...
> 
> This seems like a bug to me... or am I missing something?

Well, one thing I discovered is that the "word 1 to -1" doesn't work well
when you have unbalanced double quotation marks, because of the unique way
that Rev sees "words" when you have double quotes, and is worse if you don't
use parentheses. For example:

  put the number of words of (quote & "This is a test" & quote)
  --> 1
  put the number of words of quote & "This is a test" & quote
  --> 1This is a test"

Now take away the trailing quote an you get this:

  put the number of words of (quote & "This is a test")
  --> 1
  put the number of words of quote & "This is a test"
  --> 1This is a test"

Now the above makes it really obvious of what's going on. But suppose you
didn't know the above... look at this, with spaces added before the trailing
quote:

  put word 1 to -1 of (quote & "This is a test     " & quote)
  --> "This is a test     "
  put word 1 to -1 of quote & "This is a test    " & quote
  --> "This is a test     "

Looks like the same thing, right? But now remove the trailing quote, and you
get this (I put in the "^" to show you the end of the string):

  put word 1 to -1 of (quote & "This is a test     ")
  --> "This is a test^
  put word 1 to -1 of quote & "This is a test    "
  --> "This is a test     ^

So, although it is a bit ugly and only twice as slow*, I still prefer using
this:

 function trim what
  if the platform is "MacOS" then put numToChar(202) into tHardSpc
  else put numToChar(160) into tHardSpc
  put (space & tab & cr & linefeed & tHardSpc) into tWhiteSpc
  repeat
    if char 1 of what is not in tWhiteSpc then exit repeat
    else delete char 1 of what
  end repeat
  repeat
    if char -1 of what is not in tWhiteSpc then exit repeat
    else delete char -1 of what
  end repeat
  return what
end trim

* word 1 to -1: 0.0002 ticks/run; repeat: 0.0004 ticks/run
  (According to 10000 iterations of each in RevBench)

Just my 2 cents,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list