35 return [[
self alloc] initWithString:aString];
40 if (
self = [super
init])
42 _string = [aString
copy];
73 - (void)setCaseSensitive:(BOOL)flag
75 _caseSensitive = flag;
80 return _caseSensitive;
90 return _charactersToBeSkipped;
95 _charactersToBeSkipped = c;
100 return _scanLocation == _string.length;
105 return _scanLocation;
108 - (void)setScanLocation:(
int)aLocation
110 if (aLocation > _string.length)
111 aLocation = _string.length;
112 else if (aLocation < 0)
115 _scanLocation = aLocation;
119 - (BOOL)_performScanWithSelector:(
SEL)s withObject:(
id)arg into:(
id)ref
121 var ret = [
self performSelector:s withObject:arg];
138 return [
self _performScanWithSelector:@selector(scanCharactersFromSet:) withObject:scanSet into:ref];
143 return [
self _scanWithSet:scanSet breakFlag:NO];
148 return [
self _performScanWithSelector:@selector(scanUpToCharactersFromSet:) withObject:scanSet into:ref];
153 return [
self _scanWithSet:scanSet breakFlag:YES];
165 var current = [
self scanLocation],
168 while (current < _string.length)
170 var c = (_string.charAt(current));
172 if ([scanSet characterIsMember:c] ==
stop)
175 if (![_charactersToBeSkipped characterIsMember:c])
186 [
self setScanLocation:current];
195 - (void)_movePastCharactersToBeSkipped
197 var current = [
self scanLocation],
198 string = [
self string],
199 toSkip = [
self charactersToBeSkipped];
201 while (current <
string.length)
203 if (![toSkip characterIsMember:
string.charAt(current)])
209 [
self setScanLocation:current];
213 - (BOOL)scanString:(
CPString)aString intoString:(
id)ref
215 return [
self _performScanWithSelector:@selector(scanString:) withObject:aString into:ref];
220 [
self _movePastCharactersToBeSkipped];
224 var currentStr = [
self string].substr([
self scanLocation], s.
length);
225 if ((_caseSensitive && currentStr != s) || (!_caseSensitive && (currentStr.toLowerCase() != s.toLowerCase())))
236 - (BOOL)scanUpToString:(
CPString)aString intoString:(
id)ref
238 return [
self _performScanWithSelector:@selector(scanUpToString:) withObject:aString into:ref];
247 while (current < str.length)
249 var currentStr = str.substr(current, s.
length);
250 if (currentStr == s || (!_caseSensitive && currentStr.toLowerCase() == s.toLowerCase()))
255 captured += str.charAt(current);
265 if ([
self charactersToBeSkipped])
266 captured = [captured _stringByTrimmingCharactersInSet:[
self charactersToBeSkipped] options:_CPCharacterSetTrimAtBeginning];
275 - (float)scanWithParseFunction:(Function)parseFunction
277 [
self _movePastCharactersToBeSkipped];
284 var s = str.substring(loc, str.length),
285 f = parseFunction(s);
290 loc += (
""+f).length;
292 while (!isNaN(parseFloat(str.substring(loc + i, str.length))))
310 - (BOOL)scanInt:(
int)intoInt
312 return [
self _performScanWithSelector:@selector(scanInt) withObject:nil into:intoInt];
315 - (BOOL)scanFloat:(
float)intoFloat
317 return [
self _performScanWithSelector:@selector(scanFloat) withObject:nil into:intoFloat];
320 - (BOOL)scanDouble:(
float)intoDouble
331 return [
super description] +
" {" +
CPStringFromClass([
self class]) +
", state = '" + ([
self string].substr(0, _scanLocation) +
"{{ SCAN LOCATION ->}}" + [
self string].substr(_scanLocation)) +
"'; }";
void setScanLocation:(int aLocation)
function CPStringFromClass(aClass)
A mutable key-value pair collection.
id whitespaceCharacterSet()
FrameUpdater prototype stop
An immutable string (collection of characters).
BOOL scanFloat:(float intoFloat)
CPCharacterSet charactersToBeSkipped()
float scanWithParseFunction:(Function parseFunction)
FrameUpdater prototype description