• 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: Is there a way to prepare NSAttaributedString like "attribute runs"?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a way to prepare NSAttaributedString like "attribute runs"?


  • Subject: Re: Is there a way to prepare NSAttaributedString like "attribute runs"?
  • From: "Nigel Garvey" <email@hidden>
  • Date: Mon, 11 Dec 2017 21:03:02 +0000

Shane Stanley wrote on Mon, 11 Dec 2017 22:33:19 +1100:

>On 11 Dec 2017, at 7:34 pm, Takaaki Naganoya <email@hidden>
wrote:

>> Is there a way to prepare NSAttributedString like “attribute runs”?

>set theLength to attString's |length|()
>set startIndex to 0
>repeat
>       set {theAtts, theRange} to attString's attributesAtIndex:startIndex
>longestEffectiveRange:(reference) inRange:{0, attString's |length|()}
>       -- do stuff with theAtts here
>       set rangeEnd to current application's NSMaxRange(theRange)
>       if rangeEnd ≥ theLength - 1 then exit repeat
>       set startIndex to rangeEnd + 1
>end repeat

Shouldn't startIndex be set directly to the NSMaxRange result?

  set theLength to attString's |length|()
  set startIndex to 0
  repeat until (startIndex = theLength)
    set {theAtts, theRange} to attString's attributesAtIndex:startIndex
longestEffectiveRange:(reference) inRange:{startIndex, theLength - startIndex}
    -- do stuff with theAtts here
    set startIndex to current application's NSMaxRange(theRange)
    -- Or faster:
    -- set startIndex to (theRange's location()) + (theRange's |length|())
  end repeat


NG
 _______________________________________________
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

  • Follow-Ups:
    • Re: Is there a way to prepare NSAttaributedString like "attribute runs"?
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Is there a way to prepare NSAttaributedString like "attribute runs"?
  • Next by Date: Re: Trouble escaping @
  • Previous by thread: Re: Is there a way to prepare NSAttaributedString like "attribute runs"?
  • Next by thread: Re: Is there a way to prepare NSAttaributedString like "attribute runs"?
  • Index(es):
    • Date
    • Thread