Go to the source code of this file.
◆ OOParseRolesFromString()
| NSDictionary * OOParseRolesFromString |
( |
NSString * | string | ) |
|
Definition at line 286 of file OORoleSet.m.
287{
288 NSMutableDictionary* result =
nil;
289 NSArray* tokens =
nil;
291 NSString* role =
nil;
292 float probability;
293 NSScanner* scanner =
nil;
294
295
298
303
304 result = [NSMutableDictionary dictionaryWithCapacity:
count];
305
306
307 for (i = 0; i !=
count; ++i) {
308 role = [tokens objectAtIndex:i];
309
310 probability = 1.0f;
311 if ([role rangeOfString:@"("].location != NSNotFound) {
312 scanner = [[NSScanner alloc] initWithString:role];
313 [scanner scanUpToString:@"(" intoString:&role];
314 [scanner scanString:@"(" intoString:NULL];
315 if (![scanner scanFloat:&probability])
316 probability = 1.0f;
317
318
319 [scanner release];
320 }
321
322
323 if (0 <= probability && ![role hasPrefix:@"["]) {
324 [result setObject:[NSNumber numberWithFloat:probability] forKey:role];
325 }
326 }
327
328 if ([result
count] == 0)
330 return result;
331}
NSMutableArray * ScanTokensFromString(NSString *values)
References count, nil, and ScanTokensFromString().
Referenced by OORoleSet::initWithRoleString:, and OOShipRegistry(OODataLoader)::mergeShipRoles:forShipKey:intoProbabilityMap:.