Go to the source code of this file.
◆ OOParseRolesFromString()
NSDictionary * OOParseRolesFromString |
( |
NSString * | string | ) |
|
Definition at line 315 of file OORoleSet.m.
316{
317 NSMutableDictionary *result =
nil;
318 NSArray *tokens =
nil;
320 NSString *role =
nil;
321 float probability;
322 NSScanner *scanner =
nil;
323
324
325 if (
string ==
nil)
return nil;
326
330
331 result = [NSMutableDictionary dictionaryWithCapacity:
count];
332
333
334 for (i = 0; i !=
count; ++i)
335 {
336 role = [tokens objectAtIndex:i];
337
338 probability = 1.0f;
339 if ([role rangeOfString:@"("].location != NSNotFound)
340 {
341 scanner = [[NSScanner alloc] initWithString:role];
342 [scanner scanUpToString:@"(" intoString:&role];
343 [scanner scanString:@"(" intoString:NULL];
344 if (![scanner scanFloat:&probability]) probability = 1.0f;
345
346
347 [scanner release];
348 }
349
350
351 if (0 <= probability && ![role hasPrefix:@"["])
352 {
353 [result setObject:[NSNumber numberWithFloat:probability] forKey:role];
354 }
355 }
356
357 if ([result
count] == 0) result =
nil;
358 return result;
359}
NSMutableArray * ScanTokensFromString(NSString *values)
References count, nil, and ScanTokensFromString().