Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OORoleSet.h File Reference
import "OOCocoa.h"
+ Include dependency graph for OORoleSet.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  OORoleSet
 

Functions

NSDictionary * OOParseRolesFromString (NSString *string)
 

Function Documentation

◆ OOParseRolesFromString()

static NSDictionary * OOParseRolesFromString ( NSString * string)

Definition at line 290 of file GetMetadataForFile.m.

291{
292 NSMutableDictionary *result = nil;
293 NSArray *tokens = nil;
294 NSUInteger i, count;
295 NSString *role = nil;
296 float probability;
297 NSScanner *scanner = nil;
298
299 // Split string at spaces, sanity checks, set-up.
300 if (string == nil) return nil;
301
302 tokens = ScanTokensFromString(string);
303 count = [tokens count];
304 if (count == 0) return nil;
305
306 result = [NSMutableDictionary dictionaryWithCapacity:count];
307
308 // Scan tokens, looking for probabilities.
309 for (i = 0; i != count; ++i)
310 {
311 role = [tokens objectAtIndex:i];
312
313 probability = 1.0f;
314 if ([role rangeOfString:@"("].location != NSNotFound)
315 {
316 scanner = [[NSScanner alloc] initWithString:role];
317 [scanner scanUpToString:@"(" intoString:&role];
318 [scanner scanString:@"(" intoString:NULL];
319 if (![scanner scanFloat:&probability]) probability = 1.0f;
320 // Ignore rest of string
321 }
322
323 // shipKey roles start with [ so other roles can't
324 if (0 <= probability && ![role hasPrefix:@"["])
325 {
326 [result setObject:[NSNumber numberWithFloat:probability] forKey:role];
327 }
328 }
329
330 if ([result count] == 0) result = nil;
331 return result;
332}
static NSMutableArray * ScanTokensFromString(NSString *values)
unsigned count
return nil

References count, nil, and ScanTokensFromString().

+ Here is the call graph for this function: