well I got this far.. in my "hokey-baby" xTalk way of coding...but it works well enough to keep one or two donors from "screaming" with all caps in their comments... but someone was entering dates like this: 12.21.2012 in his comments my script munges these to 12212012.. and it doesn't deal well with !bangs... but it's good enough to do what I need for now.

on mouseUp
   local tNewSentence

   put the clipboarddata["text"] into tInput
# I'll change this to input from $POST on the server side script later
   set the linedel to "."
   repeat for each line aSentence in tInput

      ## First we lower case all
      # delete space in front first

      repeat until x <> " "

#I think there is a better trim leading/trailing space function I saw years ago...I have it # somewhere... one day I will master accessing all my code (ha, good luck with that!)

         put char 1 of aSentence into x
         if x = " " then delete char 1 of aSentence
      end repeat
      put toLower(aSentence) into aSentence
      replace "!" with "! " in aSentence

                 # doesn't help unless next word is in my dictionary.
# so I need something to "see" exclamation marks as delimiters, not sure
                 # how to tackle that if dot is already set as delimiter

  put (toUpper(char 1 of aSentence)) into char 1 of aSentence

# next we set upper case words from our mini-dictionary function...

      Repeat for each word theWord in aSentence
         put capitalizeWords(theWord)  into tWord
         put tWord & space after tNewSentence
      end Repeat
      delete char -1 of tNewSentence
      put tNewSentence &". " after tOutPut
      put empty into tNewSentence

   end repeat
   if char 1 of tOutput = "." then delete char 1 of tOutput
   set the clipboarddata["text"] to tOutput
   put tOutput

end mouseUp

function capitalizeWords theWord
put "ganesha, pancha, gurudeva!,gurudev!,Satguru, ganapathi, ganapati, yogaswami, siva, shiva, muruga, bodhinatha,lord, nataraja, aum" into tCapsDictionary

   set the itemdel to comma

   if  tCapsDictionary contains theWord then

      --if theWord is among the items of tCapsDictionary
                ## doesn't work; dunno why...
                # so I used "contains"

     put toUpper(char 1 of theWord) into char 1 of theWord
   end if
   return theWord
end capitalizeWords

On 12/21/11 11:46 AM, Bob Sneidar wrote:
I did something similar recently, where not only was the delimiter important, 
but preserving the exact delimiter was also important. In my case it was 
breaking out the parts of a query that might contain AND or OR. What I did was:

replace " AND " with cr&  " AND "&  cr in theList
replace " OR " with cr&  " OR "&  cr in theList

repeat with theLineCount = 1 to the number of lines of theList step 2
   put line theLineCount of theList into theLine
   put line theLineCount +1 into theDelimiter
   -- do some stuff with whatcha got
   put theLine&  theDelimiter&  cr after theNewList
end repeat

You could modify this to deal with a period and a space, a period and a close parens, a 
period and a character return or a period and anything else that might apply. Just don't 
append CR for a single period and cr, or you will end up with blank lines that were not there 
beforehand. Also, now that I think about it, you should probably also replace "..." 
with an ellipsis before continuing, and any other thing that might come after a period in 
normal text. You should end up with a list of sentences, and whatever came after them. Also, 
now that I think about it some more, you should probably replace 2 cr's with some kind of 
placeholder&  cr before anything else in a repeat loop to account for multiple CR's. That 
would throw your function out of sync if an extra line showed up anywhere along the way.

Bob


On Dec 21, 2011, at 1:02 PM, Sivakatirswami wrote:

OK yes, Title case is easy... It's sentence case I was looking for because a 
period/dot is not part of a word. I guess one could use a dot as a line 
delimiter and then step thru the lines.



On 12/21/11 10:57 AM, Bob Sneidar wrote:
On Dec 21, 2011, at 12:43 PM, Sivakatirswami wrote:

I have a need to take all caps input  and

1) Lower case all but first letter of sentences

2) Upper case words in a small dictionary I will provide to the function.

As anyone cooked up something like this already... if I just had 1) can manage 
2)

Happy Holidays!

Om Shanti
Sivakatirswami

Kauai Aadheenam

__________________________
function titleCase theText, forceIt
     if forceIt is true then
         put tolower(theText) into theText
     end if

     repeat with theWordNum = 1 to the number of words of theText
         put toupper(char 1 of word theWordNum of theText)&   \
                 char 2 to -1 of word theWordNum of theText \
                 into word theWordNum of theText
     end repeat

     return theText
end titleCase


_______________________________________________


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to