adium 2587:fcdec413dac8: Fixes #10625. Fixes #6539. Emoticon rep...

commits at adium.im commits at adium.im
Wed Aug 12 01:10:53 UTC 2009


details:	http://hg.adium.im/adium/rev/fcdec413dac8
revision:	2587:fcdec413dac8
author:		Stephen Holt <sholt at adium.im>
date:		Thu Aug 06 22:10:02 2009 -0400

Fixes #10625. Fixes #6539. Emoticon replacement issues.

   * Adds the `symbolCharacterSet` to the characters trimmed from the ends of strings
   * Removes characters in the current `replacementString` from the `endingTrimSet`, and stores the set in a static NSDictionary for faster recall later.
   * Improved condition for deciding end-of-string replaceability
   * Corrects a condition where the replacement algorithm may terminate early.
Subject: adium 2588:705099bf70ca: Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789

details:	http://hg.adium.im/adium/rev/705099bf70ca
revision:	2588:705099bf70ca
author:		Stephen Holt <sholt at adium.im>
date:		Tue Aug 11 21:12:55 2009 -0400

Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789

diffs (107 lines):

diff -r cd0e60e81735 -r 705099bf70ca Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.h
--- a/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.h	Sat Aug 08 14:17:42 2009 -0500
+++ b/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.h	Tue Aug 11 21:12:55 2009 -0400
@@ -42,7 +42,7 @@
 
 @class AHMarkedHyperlink;
 
- at interface AHHyperlinkScanner : NSObject
+ at interface AHHyperlinkScanner : NSObject <NSFastEnumeration>
 {
 	NSDictionary				*m_urlSchemes;
 	NSString					*m_scanString;
diff -r cd0e60e81735 -r 705099bf70ca Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m
--- a/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m	Sat Aug 08 14:17:42 2009 -0500
+++ b/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m	Tue Aug 11 21:12:55 2009 -0400
@@ -245,7 +245,7 @@
 	unsigned long scannedLocation = m_scanLocation;
 	
     // scan upto the next whitespace char so that we don't unnecessarity confuse flex
-    // otherwise we end up validating urls that look like this "http://www.adiumx.com/ <--cool"
+    // otherwise we end up validating urls that look like this "http://www.adium.im/ <--cool"
 	[self _scanString:m_scanString charactersFromSet:startSet intoRange:nil fromIndex:&scannedLocation];
 
 	// main scanning loop
@@ -375,10 +375,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]];
@@ -401,6 +401,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
 
 - (NSRange)_longestBalancedEnclosureInRange:(NSRange)inRange
diff -r cd0e60e81735 -r 705099bf70ca Source/AIEmoticonController.m
--- a/Source/AIEmoticonController.m	Sat Aug 08 14:17:42 2009 -0500
+++ b/Source/AIEmoticonController.m	Tue Aug 11 21:12:55 2009 -0400
@@ -276,19 +276,29 @@
 				/* If the emoticon would end the string except for whitespace, newlines, or punctionation at the end, or it begins the string after removing
 				 * whitespace, newlines, or punctuation at the beginning, it is acceptable even if the previous conditions weren't met.
 				 */
-				static NSCharacterSet *endingTrimSet = nil;
-				if (!endingTrimSet) {
+				NSCharacterSet *endingTrimSet = nil;
+				static NSMutableDictionary *endingSetDict = nil;
+				if(!endingSetDict) {
+					endingSetDict = [[NSMutableDictionary alloc] initWithCapacity:10];
+				}
+				if (!(endingTrimSet = [endingSetDict objectForKey:replacementString])) {
 					NSMutableCharacterSet *tempSet = [[NSCharacterSet punctuationCharacterSet] mutableCopy];
 					[tempSet formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
-					endingTrimSet = [tempSet immutableCopy];
+					[tempSet formUnionWithCharacterSet:[NSCharacterSet symbolCharacterSet]];
+					//remove any characters *in* the replacement string from the trimming set
+					[tempSet removeCharactersInString:replacementString];
+					[endingSetDict setObject:[tempSet immutableCopy] forKey:replacementString];
 					[tempSet release];
+					endingTrimSet = [endingSetDict objectForKey:replacementString];
 				}
 
 				NSString	*trimmedString = [messageString stringByTrimmingCharactersInSet:endingTrimSet];
 				NSUInteger trimmedLength = [trimmedString length];
 				if (trimmedLength == (originalEmoticonLocation + textLength)) {
+					// Replace at end of string
 					acceptable = YES;
-				} else if ((originalEmoticonLocation - (messageStringLength - trimmedLength)) == 0) {
+				} else if ([trimmedString characterAtIndex:0] == [replacementString characterAtIndex:0]) {
+					// Replace at start of string
 					acceptable = YES;					
 				}
 			}
@@ -358,6 +368,7 @@
 		//Always increment the loop
 		if (currentLocationNeedsUpdate) {
 			*currentLocation += 1;
+			originalEmoticonLocation = *currentLocation;
 		}
 		
 		[candidateEmoticons release];




More information about the commits mailing list