• 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: unichar for hyperlink?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unichar for hyperlink?


  • Subject: Re: unichar for hyperlink?
  • From: Jeremy Dronfield <email@hidden>
  • Date: Wed, 25 Feb 2004 22:11:15 +0000

On 25 Feb 2004, at 7:51 pm, Douglas Davidson wrote:


On Feb 25, 2004, at 11:33 AM, Jeremy Dronfield wrote:

That's what I was afraid of. What I'm doing is cycling through the characters in a text storage object looking for attachments and hyperlinks. For attachments I can simply check for the character, but looking for NSLinkAttributeName I'm going to have to hunt through the attributes of every character. Damn.

It's often more efficient to iterate through the attributes, because they are typically unchanged for long runs, and the APIs return them per run. You can get both attachments and links by iterating through the attributes, looking for the attachment and link attributes. Attribute fixing makes sure that the attachment attribute is not applied to non-attachment characters.

Douglas Davidson

Good suggestion. Since attributeRuns is so thinly documented, I have one other question. Given that I've got my array of attribute runs, I'm iterating through them, I've found a run with a link attribute, like so:

NSArray *attRuns = [[entryView textStorage] attributeRuns];
int runCount = [attRuns count];
int runs = 0;

for (runs = 0; runs < runCount; runs++) {
NSRange range;
NSAttributedString *localAtts = [attRuns objectAtIndex:runs];
if ([localAtts attribute:NSLinkAttributeName atIndex:0 effectiveRange:&range] != nil) {
NSLog([localAtts description]); <=just checking

}
}

Is there a way for me to get the range of localAtts within [entryView textStorage]? -rangeOfString:[localAtts string] won't be much use, because it might pounce on a different occurrence of that substring. (What I'm trying to do is insert html tags in the string, so I need to be able to replace, say, "ADC Home" with "<a href=\"http://developer.apple.com/\";>ADC Home</a>".)

-Jeremy

========================================
email@hidden

theLocustFarm.net:
- fractious fiction at http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: unichar for hyperlink?
      • From: Douglas Davidson <email@hidden>
References: 
 >unichar for hyperlink? (From: Jeremy Dronfield <email@hidden>)
 >Re: unichar for hyperlink? (From: Douglas Davidson <email@hidden>)
 >Re: unichar for hyperlink? (From: Jeremy Dronfield <email@hidden>)
 >Re: unichar for hyperlink? (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: import regex -> can't instantiate Java class any more
  • Next by Date: Re: unichar for hyperlink?
  • Previous by thread: Re: unichar for hyperlink?
  • Next by thread: Re: unichar for hyperlink?
  • Index(es):
    • Date
    • Thread