-
Notifications
You must be signed in to change notification settings - Fork 395
/
_MiscMergeOptionCommand.m
executable file
·167 lines (139 loc) · 6.18 KB
/
_MiscMergeOptionCommand.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// _MiscMergeOptionCommand.m
//
// Written by Doug McClure
//
// Copyright 2002-2004 by Don Yacktman and Doug McClure.
// 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 "_MiscMergeOptionCommand.h"
#import "NSString+MiscAdditions.h"
#import "MiscMergeTemplate.h"
#import "MiscMergeFunctions.h"
typedef enum _OptionType {
RecursiveLookups = 1,
FailedLookupResultKey,
FailedLookupResultKeyWithDelims,
FailedLookupResultNil,
FailedLookupResultKeyIfNumeric,
NilLookupResultNil,
NilLookupResultKeyIfQuoted,
NilLookupResultKey,
NilLookupResultKeyWithDelims
} OptionType;
@implementation _MiscMergeOptionCommand
- (void)dealloc
{
[value1 release];
[super dealloc];
}
/*" This method will parse a option command in a template. Options can affect the template
processing or the runtime.
option betweenWhitespace keepAll* | keepOne | trim
option recursive no* | yes | <number>
option failedLookupResult Key* | KeyWithDelims | Nil | KeyIfNumeric
option nilLookupResult Nil* | KeyIfQuoted | Key | KeyWithDelims
* the default option
"*/
- (BOOL)parseFromScanner:(NSScanner *)aScanner template:(MiscMergeTemplate *)template;
{
NSString *option;
if ( ![self eatKeyWord:@"option" fromScanner:aScanner isOptional:NO] )
return NO;
option = [self getArgumentStringFromScanner:aScanner toEnd:NO];
if ( NSOrderedSame == [option caseInsensitiveCompare:@"recursiveLookups"] ) {
optionType = RecursiveLookups;
value1 = [[self getArgumentStringFromScanner:aScanner toEnd:NO] retain];
}
else if ( NSOrderedSame == [option caseInsensitiveCompare:@"delimiters"] ) {
NSString *argument1 = [self getArgumentStringFromScanner:aScanner toEnd:NO];
NSString *argument2 = [self getArgumentStringFromScanner:aScanner toEnd:NO];
if ( ([argument1 length] == 0) && ([argument2 length] == 0) )
[template reportParseError:@"%@: option delimiters command needs two arguments", [self class]];
else
[template setStartDelimiter:argument1 endDelimiter:argument2];
}
else if ( NSOrderedSame == [option caseInsensitiveCompare:@"betweenWhitespace"] ) {
NSString *argument = [self getArgumentStringFromScanner:aScanner toEnd:NO];
if ( NSOrderedSame == [argument caseInsensitiveCompare:@"keep"] )
[template setTrimWhitespaceBehavior:MiscMergeKeepWhitespace];
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"trim"] )
[template setTrimWhitespaceBehavior:MiscMergeTrimWhitespace];
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"keepNonBlank"] )
[template setTrimWhitespaceBehavior:MiscMergeKeepNonBlankWhitespace];
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"ignoreCommandSpaces"] )
[template setTrimWhitespaceBehavior:MiscMergeIgnoreCommandSpaces];
}
else if ( NSOrderedSame == [option caseInsensitiveCompare:@"failedLookupResult"] ) {
NSString *argument = [self getArgumentStringFromScanner:aScanner toEnd:NO];
if ( NSOrderedSame == [argument caseInsensitiveCompare:@"key"] )
optionType = FailedLookupResultKey;
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"keyWithDelims"] )
optionType = FailedLookupResultKeyWithDelims;
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"nil"] )
optionType = FailedLookupResultNil;
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"keyIfNumeric"] )
optionType = FailedLookupResultKeyIfNumeric;
}
else if ( NSOrderedSame == [option caseInsensitiveCompare:@"nilLookupResult"] ) {
NSString *argument = [self getArgumentStringFromScanner:aScanner toEnd:NO];
if ( NSOrderedSame == [argument caseInsensitiveCompare:@"nil"] )
optionType = NilLookupResultNil;
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"keyIfQuoted"] )
optionType = NilLookupResultKeyIfQuoted;
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"key"] )
optionType = NilLookupResultKey;
else if ( NSOrderedSame == [argument caseInsensitiveCompare:@"keyWithDelims"] )
optionType = NilLookupResultKeyWithDelims;
}
else {
[self error_argument:option];
}
return YES;
}
- (MiscMergeCommandExitType)executeForMerge:(MiscMergeEngine *)aMerger
{
switch (optionType) {
case RecursiveLookups:
if ( [value1 intValue] > 0 )
[aMerger setUseRecursiveLookups:YES limit:[value1 intValue]];
else if ( MMIsBooleanTrueString(value1) )
[aMerger setUseRecursiveLookups:YES];
else
[aMerger setUseRecursiveLookups:NO];
break;
case FailedLookupResultKey:
[aMerger setFailedLookupResult:MiscMergeFailedLookupResultKey];
break;
case FailedLookupResultKeyWithDelims:
[aMerger setFailedLookupResult:MiscMergeFailedLookupResultKeyWithDelims];
break;
case FailedLookupResultNil:
[aMerger setFailedLookupResult:MiscMergeFailedLookupResultNil];
break;
case FailedLookupResultKeyIfNumeric:
[aMerger setFailedLookupResult:MiscMergeFailedLookupResultKeyIfNumeric];
break;
case NilLookupResultNil:
[aMerger setNilLookupResult:MiscMergeNilLookupResultNil];
break;
case NilLookupResultKeyIfQuoted:
[aMerger setNilLookupResult:MiscMergeNilLookupResultKeyIfQuoted];
break;
case NilLookupResultKey:
[aMerger setNilLookupResult:MiscMergeNilLookupResultKey];
break;
case NilLookupResultKeyWithDelims:
[aMerger setNilLookupResult:MiscMergeNilLookupResultKeyWithDelims];
break;
}
return MiscMergeCommandExitNormal;
}
@end