text
stringlengths
0
15.7k
source
stringlengths
6
112
set b to ""
lns3.scpt
set theString to a & b
lns3.scpt
end deleteCharacters
lns3.scpt
on convertListToString(aList, delim) --> string (only reads)
lns3.scpt
set oldSep to AppleScript's text item delimiters
lns3.scpt
set AppleScript's text item delimiters to delim
lns3.scpt
set aString to aList as string
lns3.scpt
set AppleScript's text item delimiters to oldSep
lns3.scpt
end convertListToString
lns3.scpt
on getTokens(delim) --> list (only reads)
lns3.scpt
end getTokens
lns3.scpt
on setTokens(aList, delim) --> string
lns3.scpt
set theString to convertListToString(aList, delim)
lns3.scpt
end setTokens
lns3.scpt
on firstToken(delim) --> string (only reads)
lns3.scpt
return NthToken(1, delim)
lns3.scpt
end firstToken
lns3.scpt
on lastToken(delim) --> string
lns3.scpt
return NthToken(-1, delim)
lns3.scpt
end lastToken
lns3.scpt
on NthToken(n, delim) --> string
lns3.scpt
if n = 0 then error "Cannot get delim zero"
lns3.scpt
set t to getTokens(delim)
lns3.scpt
if t = {} then return ""
lns3.scpt
set numItems to number of items of t
lns3.scpt
if n > numItems then error "Cannot get delim " & n & ", only " & numItems & " of tokens"
lns3.scpt
return item n of t
lns3.scpt
end NthToken
lns3.scpt
on deleteNthToken(n, delim) --> string
lns3.scpt
if n = 0 then error "Cannot delete token zero"
lns3.scpt
set aList to getTokens(delim)
lns3.scpt
set m to number of items of aList
lns3.scpt
if n < 0 then set n to m + n + 1
lns3.scpt
if n < 1 then error "Cannot delete tokens before the first token"
lns3.scpt
set aList to items 2 thru m of aList
lns3.scpt
else if n = m then
lns3.scpt
set aList to items 1 thru (m - 1) of aList
lns3.scpt
set aList to (items 1 thru (n - 1) of aList) & (items (n + 1) thru m of aList)
lns3.scpt
set theString to aList as string
lns3.scpt
on error theMsg number theNum
lns3.scpt
error theMsg number theNum
lns3.scpt
end deleteNthToken
lns3.scpt
on deleteFirstToken(delim) --> string
lns3.scpt
deleteNthToken(1, delim)
lns3.scpt
end deleteFirstToken
lns3.scpt
on deleteLastToken(delim) --> string
lns3.scpt
deleteNthToken(-1, delim)
lns3.scpt
end deleteLastToken
lns3.scpt
on keepFirstToken(delim) --> string
lns3.scpt
setString(NthToken(1, delim))
lns3.scpt
end keepFirstToken
lns3.scpt
on keepLastToken(delim) --> string
lns3.scpt
setString(NthToken(-1, delim))
lns3.scpt
end keepLastToken
lns3.scpt
on keepNthToken(n, delim) --> string
lns3.scpt
setString(NthToken(n, delim))
lns3.scpt
end keepNthToken
lns3.scpt
on eachTokenContaining(thisString, delim) --> list (only reads)
lns3.scpt
set theList to getTokens(delim)
lns3.scpt
repeat with theItem in theList
lns3.scpt
if contents of theItem contains thisString then
lns3.scpt
copy theItem to end of newList
lns3.scpt
end eachTokenContaining
lns3.scpt
on getTokenRange(startIndex, endIndex, delim) --> list (only reads)
lns3.scpt
set n to number of items of theList
lns3.scpt
if abs(startIndex) > n or startIndex = 0 then error "Bad startIndex in getTokenRange"
lns3.scpt
if abs(endIndex) > n or endIndex = 0 then error "Bad endIndex in getTokenRange"
lns3.scpt
if startIndex > endIndex then error "startIndex > endIndex in getTokenRange"
lns3.scpt
end getTokenRange
lns3.scpt
on deleteTokenRange(startIndex, endIndex, delim) --> string
lns3.scpt
if abs(startIndex) > n or startIndex = 0 then error "Bad startIndex in deleteTokenRange"
lns3.scpt
if abs(endIndex) > n or endIndex = 0 then error "Bad endIndex in deleteTokenRange"
lns3.scpt
if startIndex > endIndex then error "startIndex > endIndex in deleteTokenRange"
lns3.scpt
if startIndex < 0 then set startIndex to n + startIndex + 1
lns3.scpt
if endIndex < 0 then set endIndex to n + endIndex + 1
lns3.scpt
if endIndex = n then
lns3.scpt
set theList to items (endIndex + 1) thru n of theList
lns3.scpt
else if endIndex = n then
lns3.scpt
set theList to items 1 thru (startIndex - 1) of theList
lns3.scpt
set theList to (items 1 thru (startIndex - 1) of theList) & (items (endIndex + 1) thru n of theList)
lns3.scpt
setTokens(theList, delim)
lns3.scpt
end deleteTokenRange
lns3.scpt
on keepTokenRange(startIndex, endIndex, delim) --> string
lns3.scpt
set theList to getTokenRange(startIndex, endIndex, delim)
lns3.scpt
end keepTokenRange
lns3.scpt
on beforeToken(token, delim) --> string (only reads)
lns3.scpt
repeat with i from 2 to n
lns3.scpt
if item i of theList = token then
lns3.scpt
set aList to items 1 thru (i - 1) of theList
lns3.scpt
return convertListToString(aList, delim)
lns3.scpt
end beforeToken
lns3.scpt
on afterToken(token, delim) --> string (only reads)
lns3.scpt
repeat with i from 1 to (n - 1)
lns3.scpt
set aList to items (i + 1) thru n of theList
lns3.scpt
end afterToken
lns3.scpt
on trimWhitespace() --> string
lns3.scpt
set lf to character id 10
lns3.scpt
set twoReturns to return & return
lns3.scpt
repeat while theString contains twoReturns
lns3.scpt
replaceString(twoReturns, return)
lns3.scpt