text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
end resultFrom:captureGroups:fromMatch:replaceTemplate:regularExpression:
|
lns3.scpt
|
on buildSublistFrom:theString captureGroups:captureGroup fromMatch:theMatch regularExpression:theRegex
|
lns3.scpt
|
set rangeCount to theMatch's numberOfRanges()
|
lns3.scpt
|
set subList to NSMutableArray's arrayWithCapacity:rangeCount
|
lns3.scpt
|
if captureGroup is {} then
|
lns3.scpt
|
repeat with i from 0 to rangeCount - 1
|
lns3.scpt
|
set end of captureGroup to i
|
lns3.scpt
|
repeat with aGroup in captureGroup
|
lns3.scpt
|
if aGroup > rangeCount - 1 then error "Capture group out of range. Result has " & rangeCount & " capture groups, you asked for " & aGroup & "."
|
lns3.scpt
|
set replaceTemplate to "$" & aGroup
|
lns3.scpt
|
(subList's addObject:"")
|
lns3.scpt
|
(subList's addObject:oneString)
|
lns3.scpt
|
return subList
|
lns3.scpt
|
end buildSublistFrom:captureGroups:fromMatch:regularExpression:
|
lns3.scpt
|
on regex change theStringOrList search pattern thePattern match case matchCase : false dot matches all dotMatchesAll : false anchors match lines anchorsMatchLines : true Unicode boundaries unicodeBoundaries : false replace template replaceTemplate
|
lns3.scpt
|
if theStringOrList's class is list then
|
lns3.scpt
|
set stringArray to NSArray's arrayWithArray:theStringOrList
|
lns3.scpt
|
set resultArray to NSMutableArray's array()
|
lns3.scpt
|
repeat with aString in stringArray
|
lns3.scpt
|
(resultArray's addObject:(theRegex's stringByReplacingMatchesInString:aString options:0 range:{0, aString's |length|()} withTemplate:replaceTemplate))
|
lns3.scpt
|
return resultArray as list
|
lns3.scpt
|
set theString to NSString's stringWithString:theStringOrList
|
lns3.scpt
|
return (theRegex's stringByReplacingMatchesInString:theString options:0 range:{0, theString's |length|()} withTemplate:replaceTemplate) as text
|
lns3.scpt
|
end regex change
|
lns3.scpt
|
on regex batch theStringOrList change pairs changePairs match case matchCase : false dot matches all dotMatchesAll : false anchors match lines anchorsMatchLines : true Unicode boundaries unicodeBoundaries : false
|
lns3.scpt
|
if theStringOrList's class is not list then
|
lns3.scpt
|
set theStringOrList to NSArray's arrayWithObject:theStringOrList
|
lns3.scpt
|
set isList to false
|
lns3.scpt
|
set theStringOrList to NSArray's arrayWithArray:theStringOrList
|
lns3.scpt
|
set isList to true
|
lns3.scpt
|
repeat with aString in theStringOrList
|
lns3.scpt
|
(resultArray's addObject:(aString's mutableCopy()))
|
lns3.scpt
|
repeat with aPair in changePairs
|
lns3.scpt
|
set {theRegex, theError} to (NSRegularExpression's regularExpressionWithPattern:(item 1 of aPair) options:theOpts |error|:(reference))
|
lns3.scpt
|
repeat with aString in resultArray
|
lns3.scpt
|
(theRegex's replaceMatchesInString:aString options:0 range:{0, aString's |length|()} withTemplate:(item 2 of aPair))
|
lns3.scpt
|
if isList then return resultArray as list
|
lns3.scpt
|
return resultArray's firstObject() as text
|
lns3.scpt
|
end regex batch
|
lns3.scpt
|
on regex split origString search pattern thePattern match case matchCase : false dot matches all dotMatchesAll : false anchors match lines anchorsMatchLines : true Unicode boundaries unicodeBoundaries : false
|
lns3.scpt
|
set theString to NSString's stringWithString:origString
|
lns3.scpt
|
set tempString to theRegex's stringByReplacingMatchesInString:theString options:0 range:{0, theString's |length|()} withTemplate:theSentinal
|
lns3.scpt
|
set theMatches to tempString's componentsSeparatedByString:theSentinal
|
lns3.scpt
|
return (theMatches as list)
|
lns3.scpt
|
end regex split
|
lns3.scpt
|
on escape for regex theString template style isTemplate : false
|
lns3.scpt
|
if isTemplate then return (NSRegularExpression's escapedTemplateForString:theString) as text
|
lns3.scpt
|
return (NSRegularExpression's escapedPatternForString:theString) as text
|
lns3.scpt
|
end escape for regex
|
lns3.scpt
|
on common prefix of origString with string otherString match case matchCase : false
|
lns3.scpt
|
return (theString's commonPrefixWithString:otherString options:((not matchCase) as integer)) as text
|
lns3.scpt
|
end common prefix of
|
lns3.scpt
|
on percent encode theString encoded set allowedSet : path characters encoded characters allowedChars : missing value
|
lns3.scpt
|
if allowedChars is not missing value then
|
lns3.scpt
|
set allowedSet to (NSCharacterSet's characterSetWithCharactersInString:allowedChars)'s invertedSet()
|
lns3.scpt
|
else if allowedSet = path characters then
|
lns3.scpt
|
set allowedSet to NSCharacterSet's URLPathAllowedCharacterSet()
|
lns3.scpt
|
else if allowedSet = host characters then
|
lns3.scpt
|
set allowedSet to NSCharacterSet's URLHostAllowedCharacterSet()
|
lns3.scpt
|
else if allowedSet = query characters then
|
lns3.scpt
|
set allowedSet to NSCharacterSet's URLQueryAllowedCharacterSet()
|
lns3.scpt
|
else if allowedSet = fragment characters then
|
lns3.scpt
|
set allowedSet to NSCharacterSet's URLFragmentAllowedCharacterSet()
|
lns3.scpt
|
else if allowedSet = password characters then
|
lns3.scpt
|
set allowedSet to NSCharacterSet's URLPasswordAllowedCharacterSet()
|
lns3.scpt
|
else if allowedSet = user characters then
|
lns3.scpt
|
set allowedSet to NSCharacterSet's URLUserAllowedCharacterSet()
|
lns3.scpt
|
else -- fall back
|
lns3.scpt
|
return (theString's stringByAddingPercentEncodingWithAllowedCharacters:allowedSet) as text
|
lns3.scpt
|
end percent encode
|
lns3.scpt
|
on percent decode theString
|
lns3.scpt
|
return theString's stringByRemovingPercentEncoding() as text
|
lns3.scpt
|
end percent decode
|
lns3.scpt
|
on ICU transform theString transform name nameOfTransform reverse transform reverseTransform : false
|
lns3.scpt
|
return (theString's stringByApplyingTransform:nameOfTransform |reverse|:reverseTransform) as text
|
lns3.scpt
|
end ICU transform
|
lns3.scpt
|
on decimal encode theString
|
lns3.scpt
|
return (theString's stringByApplyingTransform:"[^\\x20-\\x7e]-Hex/XML10" |reverse|:false) as text
|
lns3.scpt
|
end decimal encode
|
lns3.scpt
|
on hex decode theString
|
lns3.scpt
|
return (theString's stringByApplyingTransform:"Hex-Any" |reverse|:false) as text
|
lns3.scpt
|
end hex decode
|
lns3.scpt
|
on hex encode theString
|
lns3.scpt
|
return (theString's stringByApplyingTransform:"[^\\x20-\\x7e]-Hex/XML" |reverse|:false) as text
|
lns3.scpt
|
end hex encode
|
lns3.scpt
|
use AppleScript version "2.5" -- El Capitan (10.11) or later
|
lns3.scpt
|
use script "SQLite Lib2" version "1.0.0"
|
lns3.scpt
|
set theList to {¬
{"Christopher", "Froome", "Britain", 1}, ¬
|
lns3.scpt
|
{"Fabio", "Aru", "Italy", 2}, ¬
|
lns3.scpt
|
{"Romain", "Bardet", "France", 3}, ¬
|
lns3.scpt
|
{"Rigoberto", "Uran", "Colombia", 4}, ¬
|
lns3.scpt
|
{"Jakob", "Fuglsang", "Denmark", 5}}
|
lns3.scpt
|
set theDb to «event ©±SQ©±Od» with «class ©±Cc» given «class ©±If»:"~/desktop/TestDB.db"
|
lns3.scpt
|
«event ©±SQ©±Eu» theDb given «class ©±Cq»:"drop table if exists standings"
|
lns3.scpt
|
«event ©±SQ©±Eu» theDb given «class ©±Cq»:"create table standings (firstname, lastname, country, position integer)"
|
lns3.scpt
|
«event ©±SQ©±Cb» theDb
|
lns3.scpt
|
repeat with anEntry in theList
|
lns3.scpt
|
«event ©±SQ©±Eu» theDb given «class ©±Cq»:"insert into standings values (?, ?, ?, ?)", «class ©±Cg»:anEntry
|
lns3.scpt
|
«event ©±SQ©±Ct» theDb
|
lns3.scpt
|
set result1 to «event ©±SQ©±Ce» theDb given «class ©±Cq»:"select * from standings"
|
lns3.scpt
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.