Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
Classes | Functions
OORoleSet.m File Reference
import "OORoleSet.h"
import "OOStringParsing.h"
import "OOCollectionExtractors.h"
import "OOLogging.h"
+ Include dependency graph for OORoleSet.m:

Go to the source code of this file.

Classes

category  OORoleSet(OOPrivate)
 

Functions

NSDictionary * OOParseRolesFromString (NSString *string)
 

Function Documentation

◆ OOParseRolesFromString()

NSDictionary * OOParseRolesFromString ( NSString * string)

Definition at line 315 of file OORoleSet.m.

316{
317 NSMutableDictionary *result = nil;
318 NSArray *tokens = nil;
319 NSUInteger i, count;
320 NSString *role = nil;
321 float probability;
322 NSScanner *scanner = nil;
323
324 // Split string at spaces, sanity checks, set-up.
325 if (string == nil) return nil;
326
327 tokens = ScanTokensFromString(string);
328 count = [tokens count];
329 if (count == 0) return nil;
330
331 result = [NSMutableDictionary dictionaryWithCapacity:count];
332
333 // Scan tokens, looking for probabilities.
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 // Ignore rest of string
346
347 [scanner release];
348 }
349
350 // shipKey roles start with [ so other roles can't
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}
unsigned count
return nil
NSMutableArray * ScanTokensFromString(NSString *values)

References count, nil, and ScanTokensFromString().

+ Here is the call graph for this function: