[maccode] r285 committed - Support NSFastEnumeration protocol

1 view
Skip to first unread message

codesite...@google.com

unread,
Aug 11, 2009, 7:42:08 PM8/11/09
to mac...@googlegroups.com
Revision: 285
Author: stephen.holt
Date: Tue Aug 11 16:41:46 2009
Log: Support NSFastEnumeration protocol

http://code.google.com/p/maccode/source/detail?r=285

Modified:
/trunk/Utilities/AutoHyperlinks Framework/Source/AHHyperlinkScanner.h
/trunk/Utilities/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m

=======================================
--- /trunk/Utilities/AutoHyperlinks Framework/Source/AHHyperlinkScanner.h
Sun Jul 26 10:38:19 2009
+++ /trunk/Utilities/AutoHyperlinks Framework/Source/AHHyperlinkScanner.h
Tue Aug 11 16:41:46 2009
@@ -42,7 +42,7 @@

@class AHMarkedHyperlink;

-@interface AHHyperlinkScanner : NSObject
+@interface AHHyperlinkScanner : NSObject <NSFastEnumeration>
{
NSDictionary *m_urlSchemes;
NSString *m_scanString;
@@ -51,8 +51,6 @@
unsigned long m_scanLocation;
unsigned long m_scanStringLength;
}
-
-+ (void)initialize;

/*!
* @brief Allocs and inits a new lax AHHyperlinkScanner with the given
NSString
=======================================
--- /trunk/Utilities/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m
Sun Jul 26 10:48:18 2009
+++ /trunk/Utilities/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m
Tue Aug 11 16:41:46 2009
@@ -343,10 +343,10 @@
}

//for each SHMarkedHyperlink, add the proper URL to the proper range in
the string.
- while((markedLink = [self nextURI])) {
+ for(markedLink in self) {
NSURL *markedLinkURL;
_didFindLinks = YES;
- if((markedLinkURL = [markedLink URL])){
+ if((markedLinkURL = [markedLink URL])) {
[linkifiedString addAttribute:NSLinkAttributeName
value:markedLinkURL
range:[markedLink range]];
@@ -368,6 +368,24 @@
{
m_scanLocation = location;
}
+
+#pragma mark NSFastEnumeration
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
objects:(id *)stackbuf count:(NSUInteger)len
+{
+ AHMarkedHyperlink *currentLink;
+
+ NSUInteger fastEnumCount = 0;
+ while (fastEnumCount < len && nil != (currentLink = [self nextURI])) {
+ stackbuf[fastEnumCount] = currentLink;
+ ++fastEnumCount;
+ }
+
+ state->state = (nil == currentLink)? (NSUInteger)currentLink : NSNotFound;
+ state->itemsPtr = stackbuf;
+ state->mutationsPtr = (unsigned long *)self;
+
+ return fastEnumCount;
+}

#pragma mark Below Here There Be Private Methods

Reply all
Reply to author
Forward
0 new messages