text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
end _matchInfoRecord
|
lns3.scpt
|
to _matchRecords(asocString, asocMatchRange, asocStartIndex, textOffset, nonMatchRecordType, matchRecordType)
|
lns3.scpt
|
set asocMatchEnd to asocMatchStart + (asocMatchRange's |length|())
|
lns3.scpt
|
set asocNonMatchRange to {location:asocStartIndex, |length|:asocMatchStart - asocStartIndex}
|
lns3.scpt
|
set {nonMatchInfo, textOffset} to _matchInfoRecord(asocString, asocNonMatchRange, textOffset, nonMatchRecordType)
|
lns3.scpt
|
set {matchInfo, textOffset} to _matchInfoRecord(asocString, asocMatchRange, textOffset, matchRecordType)
|
lns3.scpt
|
return {nonMatchInfo, matchInfo, asocMatchEnd, textOffset}
|
lns3.scpt
|
end _matchRecords
|
lns3.scpt
|
to _matchedGroupList(asocString, asocMatch, textOffset, includeNonMatches)
|
lns3.scpt
|
set subMatchResults to {}
|
lns3.scpt
|
set groupIndexes to (asocMatch's numberOfRanges()) - 1
|
lns3.scpt
|
if groupIndexes > 0 then
|
lns3.scpt
|
set asocFullMatchRange to asocMatch's rangeAtIndex:0
|
lns3.scpt
|
set asocNonMatchStart to asocFullMatchRange's location()
|
lns3.scpt
|
set asocFullMatchEnd to asocNonMatchStart + (asocFullMatchRange's |length|())
|
lns3.scpt
|
repeat with i from 1 to groupIndexes
|
lns3.scpt
|
set {nonMatchInfo, matchInfo, asocNonMatchStart, textOffset} to _matchRecords(asocString, asocMatch's rangeAtIndex:i, asocNonMatchStart, textOffset, _UnmatchedTextType, _MatchedGroupType)
|
lns3.scpt
|
if includeNonMatches then set end of subMatchResults to nonMatchInfo
|
lns3.scpt
|
set end of subMatchResults to matchInfo
|
lns3.scpt
|
if includeNonMatches then
|
lns3.scpt
|
set asocNonMatchRange to {location:asocNonMatchStart, |length|:asocFullMatchEnd - asocNonMatchStart}
|
lns3.scpt
|
set end of subMatchResults to item 1 of _matchInfoRecord(asocString, asocNonMatchRange, textOffset, _UnmatchedTextType)
|
lns3.scpt
|
return subMatchResults
|
lns3.scpt
|
end _matchedGroupList
|
lns3.scpt
|
to _findPattern(theText, patternText, includeNonMatches, includeMatches)
|
lns3.scpt
|
set includeNonMatches to _support's asBooleanParameter(includeNonMatches, "unmatched text")
|
lns3.scpt
|
set includeMatches to _support's asBooleanParameter(includeMatches, "matched text")
|
lns3.scpt
|
set asocPattern to _asNSRegularExpressionParameter(patternText, "for")
|
lns3.scpt
|
set asocString to _support's asNormalizedNSString(theText)
|
lns3.scpt
|
set asocNonMatchStart to 0 -- used to calculate NSRanges for non-matching portions of NSString
|
lns3.scpt
|
set textOffset to 1 -- used to calculate correct AppleScript start and end indexes
|
lns3.scpt
|
set {nonMatchInfo, matchInfo, asocNonMatchStart, textOffset} to _matchRecords(asocString, asocMatch's rangeAtIndex:0, asocNonMatchStart, textOffset, _UnmatchedTextType, _MatchedTextType)
|
lns3.scpt
|
if includeNonMatches then set end of resultList to nonMatchInfo
|
lns3.scpt
|
if includeMatches then
|
lns3.scpt
|
set end of resultList to matchInfo & {foundGroups:_matchedGroupList(asocString, asocMatch, matchInfo's startIndex, includeNonMatches)}
|
lns3.scpt
|
set foundText to (asocString's substringFromIndex:asocNonMatchStart) as text
|
lns3.scpt
|
set end of resultList to {class:_UnmatchedTextType, startIndex:textOffset, endIndex:length of theText, foundText:foundText}
|
lns3.scpt
|
end _findPattern
|
lns3.scpt
|
to _replacePattern(theText, patternText, templateText)
|
lns3.scpt
|
if (count {templateText} each script) = 1 then
|
lns3.scpt
|
script resultList
|
lns3.scpt
|
property _list_ : {}
|
lns3.scpt
|
set asocMatch to (asocMatchArray's objectAtIndex:i) -- a single match
|
lns3.scpt
|
set asocMatchRange to (asocMatch's rangeAtIndex:0) -- the full range of the match
|
lns3.scpt
|
set asocNonMatchRange to {location:asocNonMatchStart, |length|:asocMatchStart - asocNonMatchStart}
|
lns3.scpt
|
set end of resultList's _list_ to (asocString's substringWithRange:asocNonMatchRange) as text -- interstitial text
|
lns3.scpt
|
set foundText to (asocString's substringWithRange:asocMatchRange) as text -- range 0 is full match
|
lns3.scpt
|
set foundGroups to {}
|
lns3.scpt
|
repeat with j from 1 to (asocMatch's numberOfRanges()) - 1 -- ranges above 0 are group matches
|
lns3.scpt
|
set end of foundGroups to (asocString's substringWithRange:(asocMatch's rangeAtIndex:j)) as text
|
lns3.scpt
|
set end of resultList's _list_ to templateText's replacePattern(foundText, foundGroups) as text
|
lns3.scpt
|
error "An error occurred when calling the ‘replacing with’ parameter’s ‘replacePattern’ handler: " & eText number eNumber from eFrom to eTo
|
lns3.scpt
|
set asocNonMatchStart to asocMatchStart + (asocMatchRange's |length|()) -- asocMatchEnd
|
lns3.scpt
|
set end of resultList's _list_ to (asocString's substringFromIndex:asocNonMatchStart) as text -- last interstitial
|
lns3.scpt
|
set resultText to resultList's _list_ as text
|
lns3.scpt
|
return (asocPattern's stringByReplacingMatchesInString:asocString ¬
|
lns3.scpt
|
options:0 range:{0, asocString's |length|()} withTemplate:_parseSearchTemplate(templateText)) as text
|
lns3.scpt
|
end _replacePattern
|
lns3.scpt
|
to _findText(theText, forText, includeNonMatches, includeMatches)
|
lns3.scpt
|
set AppleScript's text item delimiters to forText
|
lns3.scpt
|
set startIndex to 1
|
lns3.scpt
|
set endIndex to length of text item 1 of theText
|
lns3.scpt
|
if startIndex ≤ endIndex then
|
lns3.scpt
|
set foundText to text startIndex thru endIndex of theText
|
lns3.scpt
|
set foundText to ""
|
lns3.scpt
|
set end of resultList to {class:_UnmatchedTextType, startIndex:startIndex, endIndex:endIndex, foundText:foundText}
|
lns3.scpt
|
repeat with i from 2 to count text items of theText
|
lns3.scpt
|
set startIndex to endIndex + 1
|
lns3.scpt
|
set endIndex to (length of theText) - (length of text (text item i) thru (text item -1) of theText)
|
lns3.scpt
|
set end of resultList to {class:_MatchedTextType, startIndex:startIndex, endIndex:endIndex, foundText:foundText, foundGroups:{}}
|
lns3.scpt
|
set endIndex to startIndex + (length of text item i of theText) - 1
|
lns3.scpt
|
end _findText
|
lns3.scpt
|
to _replaceText(theText, forText, newText)
|
lns3.scpt
|
if (count {newText} each script) ≠ 0 then
|
lns3.scpt
|
set {resultList, startIndex, endIndex} to {{}, 1, length of text item 1 of theText}
|
lns3.scpt
|
if startIndex ≤ endIndex then set end of resultList to text startIndex thru endIndex of theText
|
lns3.scpt
|
set end of resultList to newText's replaceText(foundText) as text
|
lns3.scpt
|
error "An error occurred when calling the ‘replacing with’ parameter’s ‘replaceText’ handler: " & eText number eNumber from eFrom to eTo
|
lns3.scpt
|
else -- replace with callback-supplied text
|
lns3.scpt
|
set newText to _support's asTextParameter(newText, "replacing with")
|
lns3.scpt
|
set resultList to theText's text items -- note: TID-based matching uses current considering/ignoring settings
|
lns3.scpt
|
set AppleScript's text item delimiters to newText
|
lns3.scpt
|
set resultText to resultList as text
|
lns3.scpt
|
to search text theText for forText using matchFormat : (case insensitivity) ¬
|
lns3.scpt
|
replacing with newText : (missing value) returning resultFormat : (matched text only)
|
lns3.scpt
|
set forText to _support's asTextParameter(forText, "for")
|
lns3.scpt
|
if forText's length = 0 then _support's throwInvalidParameter(forText, "for", text, "Can’t be empty text.")
|
lns3.scpt
|
if newText is missing value then -- find matches
|
lns3.scpt
|
if theText's length = 0 then
|
lns3.scpt
|
if resultFormat is matched text only then
|
lns3.scpt
|
return {{class:_UnmatchedTextType, startIndex:1, endIndex:0, foundText:""}}
|
lns3.scpt
|
set {includeNonMatches, includeMatches} to {false, true}
|
lns3.scpt
|
else if resultFormat is unmatched text only then
|
lns3.scpt
|
set {includeNonMatches, includeMatches} to {true, false}
|
lns3.scpt
|
else if resultFormat is matched and unmatched text then
|
lns3.scpt
|
set {includeNonMatches, includeMatches} to {true, true}
|
lns3.scpt
|
_support's throwInvalidConstantParameter(resultFormat, "returning")
|
lns3.scpt
|
if matchFormat is case insensitivity then -- the default
|
lns3.scpt
|
return _findText(theText, forText, includeNonMatches, includeMatches)
|
lns3.scpt
|
else if matchFormat is exact matching then
|
lns3.scpt
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.