Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m
author Matthew Kotila
Mon, 14 Dec 2015 00:37:29 -0800
changeset 5949 334dc418b409
parent 5586 551c610ece99
permissions -rw-r--r--
Transition Adium from SenTestingKit to XCTest.

In order to build on OS X 10.11, Xcode 7.2, several changes have been made that are outlined:
- Unit tests Target Build Settings modified:
* 'Wrapper Extension' set to 'xctest'
* 'Enable Modules (C and Objective-C)' set to 'Yes'
- UnitTests Target of AutoHyperlink.framework Build Settings modified:
* 'Wrapper Extension' set to 'xctest'
* 'Enable Modules (C and Objective-C)' set to 'Yes'
* 'Other Linker Flags' removed '-framework SenTestingKit'
- 'SenTestingKit.framework' removed from Adium -> Linked Frameworks -> System
- 'SenTestingKit.framework' removed from Adium -> Linked Frameworks -> AutoHyperlinks.framework.xcodeproj -> External Frameworks and Libraries -> Linked Frameworks
- Find and Replace within 'Adium/Unit tests' && 'Adium/Linked Frameworks/Others/AutoHyperlinks.framework.xcodeproj/UnitTests'
* '<SenTestingKit/SenTestingKit.h>' to '<XCTest/XCTest.h>'
* 'SenTestCase' to 'XCTestCase'
* 'STAssert' to 'XCTAssert'
* 'XCTAssertEquals(' to 'XCTAssertEqual('
* regex '(\[\[\[)([^\]]*\][^\]]*\])(\ autorelease\]);' to '[[$2;'
* regex '(\[)([^\]]*\][^\]]*)(\ autorelease\])' to '$2'
- modified AutoHyperlinks.framework.xcodeproj -> project.pbxproj
* line 331: ?productType = "com.apple.product-type.bundle.ocunit-test";' to 'productType = "com.apple.product-type.bundle.unit-test";'
- AIWebKitMessageViewController.h
* forward declare WebUIDelegate, WebFrameLoadDelegate protocols
* add WebUIDelegate, WebFrameLoadDelegate protocols to 'AIWebKitMessageViewController' class
- AIFacebookXMPPOAuthWebViewWindowController.m lines 107 && 108
* '[[domDoc getElementById:@"email"] setValue:self.autoFillUsername];' to '[domDoc getElementById:@"email"].innerHTML = self.autoFillUsername;'
* '[[domDoc getElementById:@"pass"] setValue:self.autoFillPassword];' to '[domDoc getElementById:@"pass"].innerHTML = self.autoFillPassword;'
- XCTAssertEqual for NSRanges modified to ?XCTAssertTrue(NSEqualRanges(range1, range2)), ...)' in Unit tests
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     1
/*
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     2
 * The AutoHyperlinks Framework is the legal property of its developers (DEVELOPERS), whose names are listed in the
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     3
 * copyright file included with this source distribution.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     4
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     5
 * Redistribution and use in source and binary forms, with or without
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     6
 * modification, are permitted provided that the following conditions are met:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     7
 *     * Redistributions of source code must retain the above copyright
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     8
 *       notice, this list of conditions and the following disclaimer.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     9
 *     * Redistributions in binary form must reproduce the above copyright
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    10
 *       notice, this list of conditions and the following disclaimer in the
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    11
 *       documentation and/or other materials provided with the distribution.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    12
 *     * Neither the name of the AutoHyperlinks Framework nor the
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    13
 *       names of its contributors may be used to endorse or promote products
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    14
 *       derived from this software without specific prior written permission.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    15
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    16
 * THIS SOFTWARE IS PROVIDED BY ITS DEVELOPERS ``AS IS'' AND ANY
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    17
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    19
 * DISCLAIMED. IN NO EVENT SHALL ITS DEVELOPERS BE LIABLE FOR ANY
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    20
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    26
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    27
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    28
#import "AHHyperlinkScanner.h"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    29
#import "AHMarkedHyperlink.h"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    30
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    31
#define DEFAULT_URL_SCHEME @"http://"
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    32
#define ENC_INDEX_KEY @"encIndex"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    33
#define ENC_CHAR_KEY @"encChar"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    34
5584
1031c3d6b70e When scanning for links, the current location wasn't being updated before checking/creating a link leading to the next pass starting from before the last URL ended. This fixes #16217 and #16413.
Frank Dowsett <wixardy@adium.im>
parents: 5231
diff changeset
    35
#define MIN_LINK_LENGTH 4
5204
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
    36
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    37
@interface AHHyperlinkScanner (PRIVATE)
3107
ad12d0d854b9 Make the current scan location a property. Less code is good. Atomicy is good.
Stephen Holt <sholt@adium.im>
parents: 3106
diff changeset
    38
- (AHMarkedHyperlink *)nextURIFromLocation:(unsigned long *)_scanLocation;
3242
baccda5d58e9 Fixes #14106. Change some definition checks for iOS builds that were confusing the build with a 10.6 sdk. Oops.
Stephen Holt <sholt@adium.im>
parents: 3183
diff changeset
    39
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    40
- (NSString *)_createLinkifiedString;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    41
#else
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
    42
- (NSAttributedString *)_createLinkifiedString;
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    43
#endif
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    44
- (NSRange)_longestBalancedEnclosureInRange:(NSRange)inRange;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    45
- (BOOL)_scanString:(NSString *)inString upToCharactersFromSet:(NSCharacterSet *)inCharSet intoRange:(NSRange *)outRangeRef fromIndex:(unsigned long *)idx;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    46
- (BOOL)_scanString:(NSString *)inString charactersFromSet:(NSCharacterSet *)inCharSet intoRange:(NSRange *)outRangeRef fromIndex:(unsigned long *)idx;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    47
@end
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    48
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    49
@implementation AHHyperlinkScanner
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    50
#pragma mark static variables
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    51
	static NSCharacterSet	*skipSet = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    52
	static NSCharacterSet	*endSet = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    53
	static NSCharacterSet	*startSet = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    54
	static NSCharacterSet	*puncSet = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    55
	static NSCharacterSet	*hostnameComponentSeparatorSet = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    56
	static NSArray			*enclosureStartArray = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    57
	static NSCharacterSet	*enclosureSet = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    58
	static NSArray			*enclosureStopArray = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    59
	static NSArray			*encKeys = nil;
3107
ad12d0d854b9 Make the current scan location a property. Less code is good. Atomicy is good.
Stephen Holt <sholt@adium.im>
parents: 3106
diff changeset
    60
ad12d0d854b9 Make the current scan location a property. Less code is good. Atomicy is good.
Stephen Holt <sholt@adium.im>
parents: 3106
diff changeset
    61
@synthesize scanLocation = m_scanLocation;
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
    62
@dynamic linkifiedString;
3107
ad12d0d854b9 Make the current scan location a property. Less code is good. Atomicy is good.
Stephen Holt <sholt@adium.im>
parents: 3106
diff changeset
    63
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    64
#pragma mark runtime initialization
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    65
+ (void)initialize
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    66
{
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    67
	if (self == [AHHyperlinkScanner class]){
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    68
		NSMutableCharacterSet *mutableSkipSet = [[NSMutableCharacterSet alloc] init];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    69
		[mutableSkipSet formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    70
		[mutableSkipSet formUnionWithCharacterSet:[NSCharacterSet illegalCharacterSet]];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    71
		[mutableSkipSet formUnionWithCharacterSet:[NSCharacterSet controlCharacterSet]];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    72
		[mutableSkipSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    73
		skipSet = [[NSCharacterSet characterSetWithBitmapRepresentation:[mutableSkipSet bitmapRepresentation]] retain];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    74
		[mutableSkipSet release];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    75
		
4910
95e6b347f547 Merge adium-1.5.3 into default.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4897
diff changeset
    76
		endSet = [[NSCharacterSet characterSetWithCharactersInString:@"\"'????????????,:;>)]}??????.????!@"] retain];
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    77
		
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    78
		NSMutableCharacterSet *mutableStartSet = [[NSMutableCharacterSet alloc] init];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    79
		[mutableStartSet formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
4862
4f1da722ffaf Fix the encoding for AHHyperlinkScanner and remove some duplicate characters that were added in 3f3c8fd24679.
Frank Dowsett <wixardy@adium.im>
parents: 4775
diff changeset
    80
		[mutableStartSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"\"'????????????.???,:;<?!-??????@"]];
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    81
		startSet = [[NSCharacterSet characterSetWithBitmapRepresentation:[mutableStartSet bitmapRepresentation]] retain];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    82
		[mutableStartSet release];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    83
		
4910
95e6b347f547 Merge adium-1.5.3 into default.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4897
diff changeset
    84
		puncSet = [[NSCharacterSet characterSetWithCharactersInString:@"\"'????????????.???,:;??????<?!"] retain];
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    85
		hostnameComponentSeparatorSet = [[NSCharacterSet characterSetWithCharactersInString:@"./"] retain];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    86
		enclosureStartArray = [[NSArray arrayWithObjects:@"(",@"[",@"{",nil] retain];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    87
		enclosureSet = [[NSCharacterSet characterSetWithCharactersInString:@"()[]{}"] retain];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    88
		enclosureStopArray = [[NSArray arrayWithObjects:@")",@"]",@"}",nil] retain];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    89
		encKeys = [[NSArray arrayWithObjects:ENC_INDEX_KEY, ENC_CHAR_KEY, nil] retain];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    90
	}
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    91
}
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
    92
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    93
#pragma mark Class Methods
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    94
+ (id)hyperlinkScannerWithString:(NSString *)inString
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    95
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    96
	return [[[[self class] alloc] initWithString:inString usingStrictChecking:NO] autorelease];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    97
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    98
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    99
+ (id)strictHyperlinkScannerWithString:(NSString *)inString
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   100
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   101
	return [[[[self class] alloc] initWithString:inString usingStrictChecking:YES] autorelease];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   102
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   103
3242
baccda5d58e9 Fixes #14106. Change some definition checks for iOS builds that were confusing the build with a 10.6 sdk. Oops.
Stephen Holt <sholt@adium.im>
parents: 3183
diff changeset
   104
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   105
+ (id)hyperlinkScannerWithAttributedString:(NSAttributedString *)inString
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   106
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   107
	return [[[[self class] alloc] initWithAttributedString:inString usingStrictChecking:NO] autorelease];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   108
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   109
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   110
+ (id)strictHyperlinkScannerWithAttributedString:(NSAttributedString *)inString
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   111
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   112
	return [[[[self class] alloc] initWithAttributedString:inString usingStrictChecking:NO] autorelease];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   113
}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   114
#endif
680
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   115
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   116
#pragma mark Init/Dealloc
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   117
- (id)init
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   118
{
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   119
	if((self = [super init])){
3107
ad12d0d854b9 Make the current scan location a property. Less code is good. Atomicy is good.
Stephen Holt <sholt@adium.im>
parents: 3106
diff changeset
   120
		self.scanLocation = 0;
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   121
		m_linkifiedString = nil;
3242
baccda5d58e9 Fixes #14106. Change some definition checks for iOS builds that were confusing the build with a 10.6 sdk. Oops.
Stephen Holt <sholt@adium.im>
parents: 3183
diff changeset
   122
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   123
		m_scanAttrString = nil;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   124
#endif
5204
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   125
        m_openEnclosureStack = [[NSMutableArray alloc] init];
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   126
	}
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   127
	return self;
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   128
}
680
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   129
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   130
- (id)initWithString:(NSString *)inString usingStrictChecking:(BOOL)flag
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   131
{
5204
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   132
	if((self = [self init])){
680
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   133
		m_scanString = [inString retain];
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   134
		m_urlSchemes = [[NSDictionary alloc] initWithObjectsAndKeys:
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   135
						@"ftp://", @"ftp",
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   136
						nil];
680
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   137
		m_strictChecking = flag;
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   138
		m_scanStringLength = [m_scanString length];
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   139
	}
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   140
	return self;
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   141
}
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   142
3242
baccda5d58e9 Fixes #14106. Change some definition checks for iOS builds that were confusing the build with a 10.6 sdk. Oops.
Stephen Holt <sholt@adium.im>
parents: 3183
diff changeset
   143
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
680
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   144
- (id)initWithAttributedString:(NSAttributedString *)inString usingStrictChecking:(BOOL)flag
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   145
{
5204
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   146
	if((self = [self init])){
680
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   147
		m_scanString = [[inString string] retain];
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   148
		m_scanAttrString = [inString retain];
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   149
		m_urlSchemes = [[NSDictionary alloc] initWithObjectsAndKeys:
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   150
						@"ftp://", @"ftp",
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   151
						nil];
680
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   152
		m_strictChecking = flag;
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   153
		m_scanStringLength = [m_scanString length];
1b12d3358ae3 * Fix unpaired external enclosure characters around strings to be linkified. Fixes #11175
Evan Schoenberg
parents: 332
diff changeset
   154
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   155
	return self;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   156
}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   157
#endif
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   158
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   159
- (void)dealloc
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   160
{
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   161
	self.scanLocation = 0;
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   162
	[m_linkifiedString release];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   163
	[m_scanString release];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   164
	[m_urlSchemes release];
5204
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   165
    [m_openEnclosureStack release];
3242
baccda5d58e9 Fixes #14106. Change some definition checks for iOS builds that were confusing the build with a 10.6 sdk. Oops.
Stephen Holt <sholt@adium.im>
parents: 3183
diff changeset
   166
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   167
	if(m_scanAttrString) [m_scanAttrString release];
3242
baccda5d58e9 Fixes #14106. Change some definition checks for iOS builds that were confusing the build with a 10.6 sdk. Oops.
Stephen Holt <sholt@adium.im>
parents: 3183
diff changeset
   168
#endif
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   169
	[super dealloc];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   170
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   171
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   172
#pragma mark URI Verification
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   173
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   174
- (BOOL)isValidURI
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   175
{
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   176
	return [AHHyperlinkScanner isStringValidURI:m_scanString usingStrict:m_strictChecking fromIndex:nil withStatus:nil schemeLength:nil];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   177
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   178
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   179
+ (BOOL)isStringValidURI:(NSString *)inString usingStrict:(BOOL)useStrictChecking fromIndex:(unsigned long *)sIndex withStatus:(AH_URI_VERIFICATION_STATUS *)validStatus schemeLength:(unsigned long *)schemeLength
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   180
{
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   181
    AH_BUFFER_STATE	 buf;  // buffer for flex to scan from
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   182
	yyscan_t		 scanner; // pointer to the flex scanner opaque type
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   183
	const char		*inStringEnc;
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   184
    unsigned long	 encodedLength;
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   185
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   186
	if(!validStatus){
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   187
		AH_URI_VERIFICATION_STATUS newStatus = AH_URL_INVALID;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   188
		validStatus = &newStatus;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   189
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   190
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   191
	*validStatus = AH_URL_INVALID; // assume the URL is invalid
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   192
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   193
	// Find the fastest 8-bit wide encoding possible for the c string
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   194
	NSStringEncoding stringEnc = [inString fastestEncoding];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   195
	if([@" " lengthOfBytesUsingEncoding:stringEnc] > 1U)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   196
		stringEnc = NSUTF8StringEncoding;
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   197
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   198
	if (!(inStringEnc = [inString cStringUsingEncoding:stringEnc])) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   199
		return NO;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   200
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   201
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   202
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   203
	encodedLength = strlen(inStringEnc); // length of the string in utf-8
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   204
    
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   205
	// initialize the buffer (flex automatically switches to the buffer in this function)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   206
	AHlex_init(&scanner);
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   207
    buf = AH_scan_string(inStringEnc, scanner);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   208
	
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   209
    // call flex to parse the input
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   210
    *validStatus = (AH_URI_VERIFICATION_STATUS)AHlex(scanner);
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   211
	if(sIndex) *sIndex += AHget_leng(scanner);
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   212
	if(schemeLength) *schemeLength = AHget_extra(scanner).schemeLength;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   213
	
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   214
    // condition for valid URI's
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   215
    if(*validStatus == AH_URL_VALID || *validStatus == AH_MAILTO_VALID || *validStatus == AH_FILE_VALID){
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   216
        AH_delete_buffer(buf, scanner); //remove the buffer from flex.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   217
        buf = NULL; //null the buffer pointer for safty's sake.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   218
        
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   219
        // check that the whole string was matched by flex.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   220
        // this prevents silly things like "blah...com" from being seen as links
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   221
        if(AHget_leng(scanner) == encodedLength){
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   222
			AHlex_destroy(scanner);
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   223
            return YES;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   224
        }
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   225
		// condition for degenerate URL's (A.K.A. URI's sans specifiers), requres strict checking to be NO.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   226
    }else if((*validStatus == AH_URL_DEGENERATE || *validStatus == AH_MAILTO_DEGENERATE || *validStatus == AH_URL_TENTATIVE) && !useStrictChecking){
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   227
        AH_delete_buffer(buf, scanner);
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   228
        buf = NULL;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   229
        if(AHget_leng(scanner) == encodedLength){
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   230
			AHlex_destroy(scanner);
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   231
            return YES;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   232
        }
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   233
		// if it ain't vaild, and it ain't degenerate, then it's invalid.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   234
    }else{
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   235
        AH_delete_buffer(buf, scanner);
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   236
        buf = NULL;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   237
		AHlex_destroy(scanner);
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   238
        return NO;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   239
    }
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   240
    // default case, if the range checking above fails.
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   241
	AHlex_destroy(scanner);
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   242
    return NO;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   243
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   244
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   245
#pragma mark Accessors
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   246
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   247
- (AHMarkedHyperlink *)nextURI
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   248
{
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   249
	NSRange	scannedRange;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   250
	unsigned long scannedLocation = m_scanLocation;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   251
	
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   252
    // scan upto the next whitespace char so that we don't unnecessarity confuse flex
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   253
    // otherwise we end up validating urls that look like this "http://www.adium.im/ <--cool"
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   254
	[self _scanString:m_scanString charactersFromSet:startSet intoRange:nil fromIndex:&scannedLocation];
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   255
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   256
	// main scanning loop
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   257
	while([self _scanString:m_scanString upToCharactersFromSet:skipSet intoRange:&scannedRange fromIndex:&scannedLocation]) {
5204
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   258
        if (MIN_LINK_LENGTH < scannedRange.length) {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   259
            // Check for and filter  enclosures.  We can't add (, [, etc. to the skipSet as they may be in a URI
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   260
            NSString *topEncChar = [m_openEnclosureStack lastObject];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   261
            if(topEncChar || [enclosureSet characterIsMember:[m_scanString characterAtIndex:scannedRange.location]]){
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   262
                unsigned long encIdx = [enclosureStartArray indexOfObject:topEncChar? topEncChar : [m_scanString substringWithRange:NSMakeRange(scannedRange.location, 1)]];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   263
                NSRange encRange;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   264
                if(NSNotFound != encIdx) {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   265
                    encRange = [m_scanString rangeOfString:[enclosureStopArray objectAtIndex:encIdx] options:NSBackwardsSearch range:scannedRange];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   266
                    if(NSNotFound != encRange.location){
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   267
                         scannedRange.length--;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   268
                        if (topEncChar) {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   269
                            [m_openEnclosureStack removeLastObject];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   270
                        } else {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   271
                            scannedRange.location++;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   272
                            scannedRange.length--;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   273
                        }
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   274
                    } else {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   275
                        [m_openEnclosureStack addObject:[enclosureStartArray objectAtIndex:encIdx]];
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   276
                    }
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   277
                }
5204
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   278
            }
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   279
            if(!scannedRange.length) break;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   280
            
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   281
            // Find balanced enclosure chars
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   282
            NSRange longestEnclosure = [self _longestBalancedEnclosureInRange:scannedRange];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   283
            while (scannedRange.length > 2 && [endSet characterIsMember:[m_scanString characterAtIndex:(scannedRange.location + scannedRange.length - 1)]]) {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   284
                if((longestEnclosure.location + longestEnclosure.length) < scannedRange.length){
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   285
                    scannedRange.length--;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   286
                }else break;
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   287
            }
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   288
            
5584
1031c3d6b70e When scanning for links, the current location wasn't being updated before checking/creating a link leading to the next pass starting from before the last URL ended. This fixes #16217 and #16413.
Frank Dowsett <wixardy@adium.im>
parents: 5231
diff changeset
   289
            // Update the scan location
1031c3d6b70e When scanning for links, the current location wasn't being updated before checking/creating a link leading to the next pass starting from before the last URL ended. This fixes #16217 and #16413.
Frank Dowsett <wixardy@adium.im>
parents: 5231
diff changeset
   290
            m_scanLocation = scannedRange.location;
1031c3d6b70e When scanning for links, the current location wasn't being updated before checking/creating a link leading to the next pass starting from before the last URL ended. This fixes #16217 and #16413.
Frank Dowsett <wixardy@adium.im>
parents: 5231
diff changeset
   291
            
5204
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   292
            // if we have a valid URL then save the scanned string, and make a SHMarkedHyperlink out of it.
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   293
            // this way, we can preserve things like the matched string (to be converted to a NSURL),
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   294
            // parent string, its validation status (valid, file, degenerate, etc), and its range in the parent string
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   295
            AH_URI_VERIFICATION_STATUS	 validStatus;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   296
            NSString					*_scanString = nil;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   297
            unsigned long				 schemeLength = 0;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   298
            if(MIN_LINK_LENGTH < scannedRange.length) _scanString = [m_scanString substringWithRange:scannedRange];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   299
            if((MIN_LINK_LENGTH < scannedRange.length) && [[self class] isStringValidURI:_scanString usingStrict:m_strictChecking fromIndex:&m_scanLocation withStatus:&validStatus schemeLength:&schemeLength]){
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   300
                AHMarkedHyperlink	*markedLink;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   301
                BOOL				 makeLink = TRUE;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   302
                //insert typical specifiers if the URL is degenerate
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   303
                switch(validStatus){
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   304
                    case AH_URL_DEGENERATE:
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   305
                    {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   306
                        NSString *scheme = DEFAULT_URL_SCHEME;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   307
                        unsigned long i = 0;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   308
                        
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   309
                        NSRange  firstComponent;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   310
                        [self		  _scanString:_scanString
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   311
                       upToCharactersFromSet:hostnameComponentSeparatorSet
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   312
                                   intoRange:&firstComponent
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   313
                                   fromIndex:&i];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   314
                        
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   315
                        if(NSNotFound != firstComponent.location) {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   316
                            NSString *hostnameScheme = [m_urlSchemes objectForKey:[_scanString substringWithRange:firstComponent]];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   317
                            if(hostnameScheme) scheme = hostnameScheme;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   318
                        }
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   319
                        
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   320
                        _scanString = [scheme stringByAppendingString:_scanString];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   321
                        
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   322
                        break;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   323
                    }
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   324
                        
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   325
                    case AH_MAILTO_DEGENERATE:
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   326
                        _scanString = [@"mailto:" stringByAppendingString:_scanString];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   327
                        break;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   328
                    case AH_URL_TENTATIVE:
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   329
                    {
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   330
                        NSString *scheme = [_scanString substringToIndex:schemeLength];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   331
                        NSArray *apps = (NSArray *)LSCopyAllHandlersForURLScheme((CFStringRef)scheme);
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   332
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   333
                        if(!apps.count)
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   334
                            makeLink = FALSE;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   335
                        [apps release];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   336
                        break;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   337
                    }
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   338
                    default:
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   339
                        break;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   340
                }
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   341
                
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   342
                if(makeLink){
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   343
                    //make a marked link
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   344
                    markedLink = [[AHMarkedHyperlink alloc] initWithString:_scanString
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   345
                                                      withValidationStatus:validStatus
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   346
                                                              parentString:m_scanString
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   347
                                                                  andRange:scannedRange];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   348
                    return [markedLink autorelease];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   349
                }
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   350
            }
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   351
            
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   352
            //step location after scanning a string
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   353
            NSRange startRange = [m_scanString rangeOfCharacterFromSet:puncSet options:NSLiteralSearch range:scannedRange];
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   354
            if (startRange.location != NSNotFound)
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   355
                m_scanLocation = startRange.location + startRange.length;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   356
            else
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   357
                m_scanLocation += scannedRange.length;
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   358
            
92c9c36c10a3 Integrate changes from mainline AutoHyperlinks which fixes some issues with enclosure tracking.
Stephen Holt <sholt@adium.im>
parents: 5154
diff changeset
   359
            scannedLocation = m_scanLocation;
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   360
        }
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   361
    }
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   362
	
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   363
    // if we're here, then NSScanner hit the end of the string
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   364
    // set AHStringOffset to the string length here so we avoid potential infinite looping with many trailing spaces.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   365
    m_scanLocation = m_scanStringLength;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   366
    return nil;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   367
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   368
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   369
-(NSArray *)allURIs
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   370
{
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   371
    NSMutableArray		*rangeArray = [NSMutableArray array];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   372
    AHMarkedHyperlink	*markedLink;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   373
	unsigned long		 _holdOffset = m_scanLocation; // store location for later restoration;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   374
	m_scanLocation = 0; //set the offset to 0.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   375
    
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   376
    //build an array of marked links.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   377
	while((markedLink = [self nextURI])){
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   378
		[rangeArray addObject:markedLink];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   379
	}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   380
    m_scanLocation = _holdOffset; // reset scanLocation
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   381
	return rangeArray;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   382
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   383
3242
baccda5d58e9 Fixes #14106. Change some definition checks for iOS builds that were confusing the build with a 10.6 sdk. Oops.
Stephen Holt <sholt@adium.im>
parents: 3183
diff changeset
   384
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   385
-(NSString *)_createLinkifiedString
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   386
{
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   387
	NSMutableString       *_linkifiedString;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   388
	AHMarkedHyperlink     *markedLink;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   389
	unsigned long          _scanLocationCache = self.scanLocation;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   390
	NSEnumerator          *linkEnumerator = [[self allURIs] reverseObjectEnumerator];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   391
	
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 5586
diff changeset
   392
	_linkifiedString = [[NSMutableString alloc] initWithString:m_scanString];
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   393
	
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   394
	while ((markedLink = [linkEnumerator nextObject])) {
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   395
		[_linkifiedString replaceCharactersInRange:markedLink.range
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   396
		                                withString:[NSString stringWithFormat:@"<a href=\"%@\">%@</a>",
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   397
		                                                                      markedLink.URL,
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   398
		                                                                      [m_scanString substringWithRange:markedLink.range]]];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   399
	}
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   400
	
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   401
	self.scanLocation = _scanLocationCache;
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 5586
diff changeset
   402
	return [_linkifiedString copy];
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   403
}
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   404
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   405
-(NSString *)linkifiedString
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   406
{
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   407
	if(!m_linkifiedString){
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   408
		NSString *newLinkifiedString = [self _createLinkifiedString];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   409
		// compare the old object to nil, and swap in the new value if they match.
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   410
		// if the old object (m_linkifiedString) already has a value, release the duplicated new object
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   411
		if(OSAtomicCompareAndSwapPtrBarrier(nil, newLinkifiedString, (void *)&m_linkifiedString))
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   412
			[m_linkifiedString retain];
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   413
	}
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   414
	return m_linkifiedString;
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   415
}
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   416
#else
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   417
-(NSAttributedString *)_createLinkifiedString
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   418
{
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   419
	NSMutableAttributedString	*_linkifiedString;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   420
	AHMarkedHyperlink			*markedLink;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   421
	BOOL						_didFindLinks = NO;
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   422
	unsigned long _scanLocationCache = self.scanLocation;
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   423
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   424
	if(m_scanAttrString) {
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 5586
diff changeset
   425
		_linkifiedString = [m_scanAttrString mutableCopy];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   426
	} else {
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 5586
diff changeset
   427
		_linkifiedString = [[NSMutableAttributedString alloc] initWithString:m_scanString];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   428
	}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   429
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   430
	//for each SHMarkedHyperlink, add the proper URL to the proper range in the string.
2588
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   431
	for(markedLink in self) {
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   432
		NSURL *markedLinkURL;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   433
		_didFindLinks = YES;
3110
3d0a53def683 Fix a few memory leaks introduced by AutoHyperlinks changes.
Stephen Holt <sholt@adium.im>
parents: 3109
diff changeset
   434
		if((markedLinkURL = markedLink.URL)) {
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   435
			[_linkifiedString addAttribute:NSLinkAttributeName
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   436
									 value:markedLinkURL
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   437
									 range:markedLink.range];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   438
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   439
	}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   440
	
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   441
	self.scanLocation = _scanLocationCache;
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   442
	return _didFindLinks? _linkifiedString :
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 5586
diff changeset
   443
	m_scanAttrString ? [m_scanAttrString retain] : [[NSMutableAttributedString alloc] initWithString:m_scanString];
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   444
}
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   445
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   446
-(NSAttributedString *)linkifiedString
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   447
{
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   448
	if(!m_linkifiedString){
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   449
		NSAttributedString *newLinkifiedString = [self _createLinkifiedString];
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   450
		// compare the old object to nil, and swap in the new value if they match.
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   451
		// if the old object (m_linkifiedString) already has a value, release the duplicated new object
3110
3d0a53def683 Fix a few memory leaks introduced by AutoHyperlinks changes.
Stephen Holt <sholt@adium.im>
parents: 3109
diff changeset
   452
		if(OSAtomicCompareAndSwapPtrBarrier(nil, newLinkifiedString, (void *)&m_linkifiedString))
3d0a53def683 Fix a few memory leaks introduced by AutoHyperlinks changes.
Stephen Holt <sholt@adium.im>
parents: 3109
diff changeset
   453
			[m_linkifiedString retain];
3108
7754de9d8f18 Create the linkified string once and cache it, also make it a r/o property.
Stephen Holt <sholt@adium.im>
parents: 3107
diff changeset
   454
	}
3110
3d0a53def683 Fix a few memory leaks introduced by AutoHyperlinks changes.
Stephen Holt <sholt@adium.im>
parents: 3109
diff changeset
   455
	return m_linkifiedString;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   456
}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   457
#endif
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   458
2588
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   459
#pragma mark NSFastEnumeration
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   460
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   461
{
2637
1832ae51377b Silence this warning.
Stephen Holt <sholt@adium.im>
parents: 2603
diff changeset
   462
	AHMarkedHyperlink	*currentLink = nil;
2588
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   463
	
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   464
	NSUInteger fastEnumCount = 0;
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   465
	while (fastEnumCount < len && nil != (currentLink = [self nextURI])) {
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   466
		stackbuf[fastEnumCount] = currentLink;
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   467
		++fastEnumCount;
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   468
	}
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   469
	
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   470
	state->state = (nil == currentLink)? (NSUInteger)currentLink : NSNotFound;
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   471
	state->itemsPtr = stackbuf;
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   472
	state->mutationsPtr = (unsigned long *)self;
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   473
	
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   474
	return fastEnumCount;
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   475
}
705099bf70ca Add NSFastEndumeration protocol support to AHHyperlinkScanner. Closes #12789
Stephen Holt <sholt@adium.im>
parents: 2528
diff changeset
   476
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   477
#pragma mark Below Here There Be Private Methods
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   478
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   479
- (NSRange)_longestBalancedEnclosureInRange:(NSRange)inRange
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   480
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   481
	NSMutableArray	*enclosureStack = nil, *enclosureArray = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   482
	NSString  *matchChar = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   483
	NSDictionary *encDict;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   484
	unsigned long encScanLocation = inRange.location;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   485
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   486
	while(encScanLocation < inRange.length + inRange.location) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   487
		[self _scanString:m_scanString upToCharactersFromSet:enclosureSet intoRange:nil fromIndex:&encScanLocation];
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   488
		
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   489
		if(encScanLocation >= (inRange.location + inRange.length)) break;
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   490
		
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   491
		matchChar = [m_scanString substringWithRange:NSMakeRange(encScanLocation, 1)];
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   492
		
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   493
		if([enclosureStartArray containsObject:matchChar]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   494
			encDict = [NSDictionary	dictionaryWithObjects:[NSArray arrayWithObjects:[NSNumber numberWithUnsignedLong:encScanLocation], matchChar, nil]
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   495
												  forKeys:encKeys];
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   496
			if(!enclosureStack) enclosureStack = [NSMutableArray array];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   497
			[enclosureStack addObject:encDict];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   498
		}else if([enclosureStopArray containsObject:matchChar]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   499
			NSEnumerator *encEnumerator = [enclosureStack objectEnumerator];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   500
			while ((encDict = [encEnumerator nextObject])) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   501
				unsigned long encTagIndex = [(NSNumber *)[encDict objectForKey:ENC_INDEX_KEY] unsignedLongValue];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   502
				unsigned long encStartIndex = [enclosureStartArray indexOfObjectIdenticalTo:[encDict objectForKey:ENC_CHAR_KEY]];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   503
				if([enclosureStopArray indexOfObjectIdenticalTo:matchChar] == encStartIndex) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   504
					NSRange encRange = NSMakeRange(encTagIndex, encScanLocation - encTagIndex + 1);
3106
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   505
					if(!enclosureStack) enclosureStack = [NSMutableArray array];
f75c7bfd396b Restructure AHHyperlinkScanner for better synchronization to nextURI.
Stephen Holt <sholt@adium.im>
parents: 3104
diff changeset
   506
					if(!enclosureArray) enclosureArray = [NSMutableArray array];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   507
					[enclosureStack removeObject:encDict];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   508
					[enclosureArray addObject:NSStringFromRange(encRange)];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   509
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   510
				}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   511
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   512
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   513
		if(encScanLocation < inRange.length + inRange.location)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   514
			encScanLocation++;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   515
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   516
	return (enclosureArray && [enclosureArray count])? NSRangeFromString([enclosureArray lastObject]) : NSMakeRange(0, 0);
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   517
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   518
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   519
// functional replacement for -[NSScanner scanUpToCharactersFromSet:intoString:]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   520
- (BOOL)_scanString:(NSString *)inString upToCharactersFromSet:(NSCharacterSet *)inCharSet intoRange:(NSRange *)outRangeRef fromIndex:(unsigned long *)idx
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   521
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   522
	unichar			_curChar;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   523
	NSRange			_outRange;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   524
	unsigned long	_scanLength = [inString length];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   525
	unsigned long	_idx;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   526
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   527
	if(_scanLength <= *idx) return NO;
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   528
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   529
	// Asorb skipSet
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   530
	for(_idx = *idx; _scanLength > _idx; _idx++) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   531
		_curChar = [inString characterAtIndex:_idx];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   532
		if(![skipSet characterIsMember:_curChar]) break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   533
	}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   534
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   535
	// scanUpTo:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   536
	for(*idx = _idx; _scanLength > _idx; _idx++) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   537
		_curChar = [inString characterAtIndex:_idx];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   538
		if([inCharSet characterIsMember:_curChar] || [skipSet characterIsMember:_curChar]) break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   539
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   540
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   541
	_outRange = NSMakeRange(*idx, _idx - *idx);
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   542
	*idx = _idx;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   543
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   544
	if(_outRange.length) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   545
		if(outRangeRef) *outRangeRef = _outRange;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   546
		return YES;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   547
	} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   548
		return NO;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   549
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   550
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   551
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   552
// functional replacement for -[NSScanner scanCharactersFromSet:intoString:]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   553
- (BOOL)_scanString:(NSString *)inString charactersFromSet:(NSCharacterSet *)inCharSet intoRange:(NSRange *)outRangeRef fromIndex:(unsigned long *)idx
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   554
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   555
	unichar			_curChar;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   556
	NSRange			_outRange;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   557
	unsigned long	_scanLength = [inString length];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   558
	unsigned long	_idx = *idx;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   559
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   560
	if(_scanLength <= _idx) return NO;
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   561
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   562
	// Asorb skipSet
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   563
	for(_idx = *idx; _scanLength > _idx; _idx++) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   564
		_curChar = [inString characterAtIndex:_idx];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   565
		if(![skipSet characterIsMember:_curChar]) break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   566
	}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   567
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   568
	// scanCharacters:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   569
	for(*idx = _idx; _scanLength > _idx; _idx++) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   570
		_curChar = [inString characterAtIndex:_idx];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   571
		if(![inCharSet characterIsMember:_curChar]) break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   572
	}
3177
7aafecd5cd6e Replace AH with AH2 from http://bitbucket.org/sholt/autohyperlinks2/
Stephen Holt <sholt@adium.im>
parents: 3160
diff changeset
   573
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   574
	_outRange = NSMakeRange(*idx, _idx - *idx);
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   575
	*idx = _idx;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   576
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   577
	if(_outRange.length) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   578
		if(outRangeRef) *outRangeRef = _outRange;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   579
		return YES;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   580
	} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   581
		return NO;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   582
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   583
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   584
@end