• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: A question on technique
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question on technique


  • Subject: Re: A question on technique
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 15 Mar 2015 17:24:03 -0500

On Mar 15, 2015, at 16:33, Gil Dawson <email@hidden> wrote:
I wish to translate a sequence of codes into corresponding mnemonics.  
…
but is there another, perhaps faster, way to do this?
______________________________________________________________________

Hey Gil,

In general linked-lists and records are a PITA to use and maintain, so I nearly always prefer to construct a lookup-table.

-------------------------------------------------------------------------------------------

property lookupTable : text 2 thru -2 of "
9420 RCL
94ae ENM
94d0 ReW
942f EOC
942C EDM
9470 RfW
"

-------------------------------------------------------------------------------------------

# TIDs
on lookupMnemonic(_mnemoic)
  set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {_mnemoic & tab}}
  text items of lookupTable
  set _output to paragraph 1 of text item 2 of lookupTable
  set AppleScript's text item delimiters to oldTIDS
  return _output
end lookupMnemonic

lookupMnemonic("94d0")

-------------------------------------------------------------------------------------------

# Satimage.osax { http://tinyurl.com/dc3soh }
on lookupMnemonicSIO(_mnemoic)
  try
    set _mnemoic to "^" & _mnemoic & "\\t(.+$)"
    find text _mnemoic using "\\1" in lookupTable with regexp and string result without case sensitive
  on error
    return false
  end try
end lookupMnemonicSIO

lookupMnemonicSIO("94d0")

-------------------------------------------------------------------------------------------

I prefer to use the Satimage.osax and regex for lookups, but the TIDs method is robust and fast.

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >A question on technique (From: Gil Dawson <email@hidden>)

  • Prev by Date: Re: A question on technique
  • Next by Date: Re: A question on technique
  • Previous by thread: Re: A question on technique
  • Next by thread: Re: A question on technique
  • Index(es):
    • Date
    • Thread