-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path_MiscMergeIndexCommand.m
executable file
·57 lines (47 loc) · 1.62 KB
/
_MiscMergeIndexCommand.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// _MiscMergeIndexCommand.m
//
// Written by Don Yacktman and Carl Lindberg
//
// Copyright 2001-2004 by Don Yacktman and Carl Lindberg.
// All rights reserved.
//
// This notice may not be removed from this source code.
//
// This header is included in the MiscKit by permission from the author
// and its use is governed by the MiscKit license, found in the file
// "License.rtf" in the MiscKit distribution. Please refer to that file
// for a list of all applicable permissions and restrictions.
//
#import "_MiscMergeIndexCommand.h"
#import "MiscMergeExpression.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>
@implementation _MiscMergeIndexCommand
- (void)dealloc
{
[arrayField release];
[super dealloc];
}
- (BOOL)parseFromScanner:(NSScanner *)aScanner template:(MiscMergeTemplate *)template
{
[self eatKeyWord:@"index" fromScanner:aScanner isOptional:NO];
arrayField = [[self getArgumentStringFromScanner:aScanner toEnd:NO quotes:&arrayQuote] retain];
theIndex = [[self getPrimaryExpressionFromScanner:aScanner] retain];
return YES;
}
- (MiscMergeCommandExitType)executeForMerge:(MiscMergeEngine *)aMerger
{
id theArray = [aMerger valueForField:arrayField quoted:arrayQuote];
if ( [theArray respondsToSelector:@selector(objectAtIndex:)] ) {
int lookupIndex = [theIndex evaluateAsIntWithEngine:aMerger];
if ( (lookupIndex >= 0) && (lookupIndex < [theArray count]) ) {
[aMerger appendToOutput:[theArray objectAtIndex:lookupIndex]];
}
}
else {
[aMerger appendToOutput:theArray];
}
return MiscMergeCommandExitNormal;
}
@end