On 29/11/08 at 14:33 +0100 Melitón Cardona Torres apparently wrote:
Works fine on my mac; I wonder whether it be the same a PC. Any hints?
Thanks in advance,
Ton Cardona
function toCapitals aText
--Works on a mac environement
put "ÁÉÍÓÚÑÄËÏÖÜÂÊÎÔÛÇÆØÅ" into unusualCapitals
put "áéíóúñäëïöüâêîôûçæø¦å" into unusualSmall
repeat with y= 1 to the length of aText
put char y of aText into aChar
put chartonum(aChar) into itsNumber
--Line feed
if itsNumber = 10 then
put cr after newWord
next repeat
end if
--Already capital
if itsNumber>64 and itsNumber<91 then
put aChar after newWord
next repeat
end if
-- Not capital without accent
if itsNumber >96 and itsNumber <123 then
put numtochar(itsNumber-32) after newWord
next repeat
end if
-- Foreseen unusual characters
if aChar is among the chars of unusualSmall then
put false into detected
repeat with g= 1 to 22
if char g of unusualSmall is aChar then
put char g of unusualCapitals after newWord
put true into detected
exit repeat
end if
end repeat
if detected then next repeat
end if
--Space, numbers and others
if ((itsNumber >31) and (itsNumber <65)) or
((itsNumber>90) and (itsNumber<97)) then
put aChar after newWord
next repeat
end if
--Unforeseen unusual characters
if itsNumber>122 and aChar is not in unusualSmall then
put aChar after newWord
next repeat
end if
end repeat
return newWord
end toCapitals_______________________________________________
It should work on PC, although I can't actually
test for you. However, there are a few things you
could optimize in the above code. This may be
just an exercise as I suspect that you convert
short words so performance improvement won't be
really visible.
function toCapitals aText
--Works on a mac environement
put "ÁÉÍÓÚÑÄËÏÖÜÂÊÎÔÛÇÆØÅ" into unusualCapitals
put "áéíóúñäëïöüâêîôûçæø¦å" into unusualSmall
put empty into newWord -- init
##repeat with y= 1 to the length of aText
repeat for each char aChar in aText -- faster loop
## put char y of aText into aChar -- not needed
put chartonum(aChar) into itsNumber
--Line feed
if itsNumber = 10 then
put cr after newWord
next repeat
end if
--Already capital
if itsNumber>64 and itsNumber<91 then
put aChar after newWord
next repeat
end if
-- Not capital without accent
if itsNumber >96 and itsNumber <123 then
put numtochar(itsNumber-32) after newWord
next repeat
end if
--Space, numbers and others
if ((itsNumber >31) and (itsNumber <65)) or
((itsNumber>90) and (itsNumber<97)) then
put aChar after newWord
next repeat
end if
--Unforeseen unusual characters
if itsNumber>122 and aChar is not in unusualSmall then
put aChar after newWord
next repeat
end if
end repeat
## special chars outside the loop
-- Foreseen unusual characters
set the casesensitive to true
repeat with g=1 to length(unusualSmall)
replace (char g of unusualCapitals) with
(char g of unusualCapitals) in newWord
end repeat
return newWord
end toCapitals_______________________________________________
I wonder actually, whether you could use the
toUpper instead of the big repeat and deal with
special cases afterwards. It may be still faster.
Robert
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution