AppleScript名:&と=で区切られたテキストをrecordに(NSScanner 2) |
— Created 2016-12-12 by Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" set aParamStr to "access_token=XXxxx(XXxXXXXXxxXxxXXx))&expires=86399" set aDict to (parseStrByAmpAndEqual(aParamStr) of me) as record –> {expires:"86399", access_token:"XXxxx(XXxXXXXXxxXxxXXx))"} on parseStrByAmpAndEqual(aParamStr) set theScanner to current application’s NSScanner’s scannerWithString:aParamStr log (theScanner’s scanLocation()) set aDict to current application’s NSMutableDictionary’s |dictionary|() repeat — terminate check, return the result (aDict) to caller set {theResult, theKey} to theScanner’s scanUpToString:"=" intoString:(reference) if theResult as boolean is false then return aDict log (theScanner’s scanLocation()) — skip over separator theScanner’s scanString:"=" intoString:(missing value) set {theResult, theValue} to theScanner’s scanUpToString:"&" intoString:(reference) log (theScanner’s scanLocation()) — skip over separator theScanner’s scanString:"&" intoString:(missing value) aDict’s setObject:theValue forKey:theKey log (theScanner’s scanLocation()) end repeat end parseStrByAmpAndEqual |
More from my site
(Visited 16 times, 1 visits today)