text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
end newInstanceFromRecord
|
map.applescript
|
on hasJsonSupport()
|
map.applescript
|
if not std's appExists("com.vidblishen.jsonhelper") then return false
|
map.applescript
|
set json to std's import("json")
|
map.applescript
|
end hasJsonSupport
|
map.applescript
|
on newInstanceFromJson(jsonString)
|
map.applescript
|
if hasJsonSupport() is false then
|
map.applescript
|
error "The app 'JSON Helper' available in the App Store is required for this operation."
|
map.applescript
|
set jsonRecord to json's fromJsonString(jsonString)
|
map.applescript
|
return newInstanceFromRecord(jsonRecord)
|
map.applescript
|
set keyList to __keys of jsonRecord
|
map.applescript
|
set newRecord to new()
|
map.applescript
|
repeat with nextKey in keyList
|
map.applescript
|
newRecord's putValue(nextKey, |nextKey| of jsonRecord)
|
map.applescript
|
newRecord
|
map.applescript
|
end newInstanceFromJson
|
map.applescript
|
on fromRecord(theRecord as record)
|
map.applescript
|
set objCDictionary to current application's NSDictionary's dictionaryWithDictionary:theRecord
|
map.applescript
|
set allKeys to objCDictionary's allKeys()
|
map.applescript
|
repeat with theKey in allKeys
|
map.applescript
|
set nextValue to (objCDictionary's valueForKey:theKey) as text
|
map.applescript
|
if theKey as text is equal to "DOMAIN" then set theKey to "domain" -- fix an issue where domain is being converted to upper case automatically.
|
map.applescript
|
theMap's putValue(theKey as text, nextValue)
|
map.applescript
|
end fromRecord
|
map.applescript
|
script ASDictionary
|
map.applescript
|
property __keys : {}
|
map.applescript
|
property __values : {}
|
map.applescript
|
property __checkDataIntegrity : true
|
map.applescript
|
on isEmpty()
|
map.applescript
|
(number of getKeys()) is 0
|
map.applescript
|
to putValue(theKey as text, theValue)
|
map.applescript
|
setValueForKey(theValue, theKey)
|
map.applescript
|
end putValue
|
map.applescript
|
to getValue(theKey as text)
|
map.applescript
|
valueForKey(theKey)
|
map.applescript
|
to removeValue(theKey as text)
|
map.applescript
|
removeValueForKey(theKey)
|
map.applescript
|
end removeValue
|
map.applescript
|
removeAllValues()
|
map.applescript
|
to hasKey(aKey) -- (object) as boolean
|
map.applescript
|
set keyValueIndex to __getIndexForKey(aKey) of me
|
map.applescript
|
if keyValueIndex is missing value then
|
map.applescript
|
end hasKey
|
map.applescript
|
to getKeys() -- (void) as list
|
map.applescript
|
return __keys
|
map.applescript
|
to getValues() -- (void) as list
|
map.applescript
|
return __values
|
map.applescript
|
to setValueForKey(aValue, aKey) -- (object, object) as boolean
|
map.applescript
|
set end of __values to aValue
|
map.applescript
|
set end of __keys to aKey
|
map.applescript
|
set keyValuePairsCount to count __keys
|
map.applescript
|
my __setKeyAndIndexToHash(aKey, keyValuePairsCount)
|
map.applescript
|
set item keyValueIndex of __values to aValue
|
map.applescript
|
to removeValueForKey(aKey) -- (string) as void
|
map.applescript
|
set theIndex to __getIndexForKey(aKey)
|
map.applescript
|
if theIndex = missing value then
|
map.applescript
|
set item theIndex of __values to missing value
|
map.applescript
|
set item theIndex of __keys to missing value
|
map.applescript
|
set lastChr to (count aKey)
|
map.applescript
|
set currentNode to __keyIndexHash of me
|
map.applescript
|
repeat with chr from 1 to lastChr
|
map.applescript
|
set nodeIdx to __chrToHashIndex(item chr of aKey) of me
|
map.applescript
|
set currentNode to __getGlyphInNode(currentNode, nodeIdx)
|
map.applescript
|
if currentNode is missing value then
|
map.applescript
|
if chr = lastChr then
|
map.applescript
|
set index of currentNode to missing value
|
map.applescript
|
to removeValuesForKeys(keys) -- (list) as void
|
map.applescript
|
set lastKey to (count keys)
|
map.applescript
|
repeat with thisKey from 1 to lastKey
|
map.applescript
|
set theKey to item thisKey of keys
|
map.applescript
|
my removeValueForKey(theKey)
|
map.applescript
|
end removeValuesForKeys
|
map.applescript
|
to removeAllValues() -- (void) as void)
|
map.applescript
|
set __keys to {}
|
map.applescript
|
set __values to {}
|
map.applescript
|
set __keyIndexHash to {}
|
map.applescript
|
end removeAllValues
|
map.applescript
|
to valueForKey(aKey) -- (object) as object or (missing value)
|
map.applescript
|
return item keyValueIndex of __values
|
map.applescript
|
to valueForIndex(anIndex) -- (integer) as object or (missing value)
|
map.applescript
|
set keysCount to count __keys
|
map.applescript
|
if (anIndex < 1) or (anIndex > keysCount) then
|
map.applescript
|
return item anIndex of __values
|
map.applescript
|
end valueForIndex
|
map.applescript
|
to addValuesForKeys(someValues, someKeys) -- (list, list) -- as boolean
|
map.applescript
|
set keysCount to (count someKeys)
|
map.applescript
|
set valuesCount to (count someValues)
|
map.applescript
|
repeat with thisKey from 1 to keysCount
|
map.applescript
|
set theKey to item thisKey of someKeys
|
map.applescript
|
set theValue to item thisKey of someValues
|
map.applescript
|
set theResult to setValueForKey(theValue, theKey) of me
|
map.applescript
|
end addValuesForKeys
|
map.applescript
|
set resultBuilder to "{"
repeat with nextKey in getKeys()
set isFirst to resultBuilder is equal to "{"
if not isFirst then set resultBuilder to resultBuilder & ", "
set resultBuilder to resultBuilder & nextKey & ": " & getValue(nextKey)
end repeat
set resultBuilder to resultBuilder & "}"
|
map.applescript
|
on toStringPretty()
|
map.applescript
|
set resultBuilder to "{
"
repeat with nextKey in getKeys()
set isFirst to resultBuilder is equal to "{
"
if not isFirst then set resultBuilder to resultBuilder & ",
"
set resultBuilder to resultBuilder & " " & nextKey & ": " & getValue(nextKey)
end repeat
set resultBuilder to resultBuilder & "
}"
|
map.applescript
|
set keyList to getKeys()
|
map.applescript
|
set mainJsonBuilder to sb's new("{")
repeat with i from 1 to count of keyList
if i is not 1 then
mainJsonBuilder's append(", ")
end if
set nextKey to item i of keyList
set nextValue to getValue(nextKey)
set end of nameValueList to nextKey
set end of nameValueList to nextValue
mainJsonBuilder's append("\"" & nextKey & "\": ")
if nextValue is missing value then
mainJsonBuilder's append("null")
else if {integer, real, boolean} contains class of nextValue then
|
map.applescript
|
mainJsonBuilder's append(nextValue)
|
map.applescript
|
mainJsonBuilder's append("\"" & nextValue & "\"")
|
map.applescript
|
mainJsonBuilder's append("}")
|
map.applescript
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.