48 NSMutableArray *result =
nil;
49 NSScanner *scanner =
nil;
50 NSString *token =
nil;
51 static NSCharacterSet *space_set =
nil;
55 if (
EXPECT_NOT(space_set ==
nil)) space_set = [[NSCharacterSet whitespaceAndNewlineCharacterSet] retain];
57 result = [NSMutableArray array];
58 scanner = [NSScanner scannerWithString:values];
60 while (![scanner isAtEnd])
62 [scanner ooliteScanCharactersFromSet:space_set intoString:NULL];
63 if ([scanner ooliteScanUpToCharactersFromSet:space_set intoString:&token])
65 [result addObject:token];
75 GLfloat xyz[] = {0.0, 0.0, 0.0};
77 NSString *error =
nil;
78 NSScanner *scanner =
nil;
80 assert(outVector != NULL);
81 if (xyzString ==
nil)
return NO;
83 if (!error) scanner = [NSScanner scannerWithString:xyzString];
84 while (![scanner isAtEnd] && i < 3 && !error)
86 if (![scanner scanFloat:&xyz[i++]]) error =
@"could not scan a float value.";
89 if (!error && i < 3) error =
@"found less than three float values.";
93 *outVector = make_vector(xyz[0], xyz[1], xyz[2]);
106 assert(outVector != NULL);
112 *outVector = vectorToHPVector(scanVector);
118 GLfloat wxyz[] = {1.0, 0.0, 0.0, 0.0};
120 NSString *error =
nil;
121 NSScanner *scanner =
nil;
123 assert(outQuaternion != NULL);
124 if (wxyzString ==
nil)
return NO;
126 if (!error) scanner = [NSScanner scannerWithString:wxyzString];
127 while (![scanner isAtEnd] && i < 4 && !error)
129 if (![scanner scanFloat:&wxyz[i++]]) error =
@"could not scan a float value.";
132 if (!error && i < 4) error =
@"found less than four float values.";
136 outQuaternion->w = wxyz[0];
137 outQuaternion->x = wxyz[1];
138 outQuaternion->y = wxyz[2];
139 outQuaternion->z = wxyz[3];
140 quaternion_normalize(outQuaternion);
153 GLfloat xyzwxyz[] = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0};
155 NSString *error =
nil;
156 NSScanner *scanner =
nil;
158 assert(outVector != NULL && outQuaternion != NULL);
159 if (xyzwxyzString ==
nil)
return NO;
161 if (!error) scanner = [NSScanner scannerWithString:xyzwxyzString];
162 while (![scanner isAtEnd] && i < 7 && !error)
164 if (![scanner scanFloat:&xyzwxyz[i++]]) error =
@"Could not scan a float value.";
167 if (!error && i < 7) error =
@"Found less than seven float values.";
175 outVector->x = xyzwxyz[0];
176 outVector->y = xyzwxyz[1];
177 outVector->z = xyzwxyz[2];
178 outQuaternion->w = xyzwxyz[3];
179 outQuaternion->x = xyzwxyz[4];
180 outQuaternion->y = xyzwxyz[5];
181 outQuaternion->z = xyzwxyz[6];
205 return [NSString stringWithFormat:@"%f %f", point.x, point.y];
212 NSPoint result = NSZeroPoint;
214 NSUInteger n_tokens = [tokens count];
217 result.x = [[tokens objectAtIndex:0] doubleValue];
218 result.y = [[tokens objectAtIndex:1] doubleValue];
227 int abcdef[] = { 0, 0, 0, 0, 0, 0};
229 NSString *error =
nil;
230 NSScanner *scanner = [NSScanner scannerWithString:abcdefString];
232 while (![scanner isAtEnd] && i < 6 && !error)
234 if (![scanner scanInt:&abcdef[i++]]) error =
@"could not scan a int value.";
237 if (!error && i < 6) error =
@"found less than six int values.";
241 result.
a = abcdef[0];
242 result.
b = abcdef[1];
243 result.
c = abcdef[2];
244 result.
d = abcdef[3];
245 result.
e = abcdef[4];
246 result.
f = abcdef[5];
260 return [NSString stringWithFormat: @"%d %d %d %d %d %d", seed.a, seed.b, seed.c, seed.d, seed.e, seed.f];
266 NSString *result = string;
271 result=[[@"" stringByPaddingToLength:(NSUInteger)numEms withString: @" " startingAtIndex:0] stringByAppendingString: result];
278 result=[[@"" stringByPaddingToLength:(NSUInteger)numEms withString: @"\037" startingAtIndex:0] stringByAppendingString: result];
291 NSString *result =
nil;
299 static BOOL reentrancyLock;
300 if (reentrancyLock)
return [NSString stringWithFormat:@"%0.1f", tenthsOfCredits * 0.1];
302 reentrancyLock = YES;
304 hadException = JS_GetPendingException(context, &exception);
305 JS_ClearPendingException(context);
307 if (JS_GetMethodById(context, global,
OOJSID(
"formatCredits"), &fakeRoot, &method))
310 if (JS_NewNumberValue(context, tenthsOfCredits * 0.1, &args[0]))
316 JS_CallFunctionValue(context, global, method, 3, args, &rval);
323 if (hadException) JS_SetPendingException(context, exception);
327 if (
EXPECT_NOT(result ==
nil)) result = [NSString stringWithFormat:@"%li", (long)(tenthsOfCredits) / 10];
335@implementation NSString (OOUtilities)
337- (BOOL)pathHasExtension:(NSString *)extension
339 return [[
self pathExtension] caseInsensitiveCompare:extension] == NSOrderedSame;
343- (BOOL)pathHasExtensionInArray:(NSArray *)extensions
345 NSEnumerator *extEnum =
nil;
346 NSString *extension =
nil;
348 for (extEnum = [extensions objectEnumerator]; (extension = [extEnum nextObject]); )
350 if ([[
self pathExtension] caseInsensitiveCompare:extension] == NSOrderedSame)
return YES;
361 NSArray *stringComponents =
nil;
362 NSMutableArray *result =
nil;
367 stringComponents = [string componentsSeparatedByString:@" "];
368 stringComponents = [[stringComponents objectAtIndex:0] componentsSeparatedByString:@"-"];
369 stringComponents = [[stringComponents objectAtIndex:0] componentsSeparatedByString:@"."];
370 count = [stringComponents count];
371 result = [NSMutableArray arrayWithCapacity:count];
373 for (i = 0; i !=
count; ++i)
375 component = [stringComponents objectAtIndex:i];
376 if ([component respondsToSelector:
@selector(intValue)]) value =
MAX([component intValue], 0);
379 [result addObject:[NSNumber numberWithUnsignedInt:value]];
388 NSEnumerator *leftEnum =
nil,
390 NSNumber *leftComponent =
nil,
391 *rightComponent =
nil;
395 leftEnum = [version1 objectEnumerator];
396 rightEnum = [version2 objectEnumerator];
400 leftComponent = [leftEnum nextObject];
401 rightComponent = [rightEnum nextObject];
403 if (leftComponent ==
nil && rightComponent ==
nil)
break;
406 leftValue = [leftComponent unsignedIntValue];
407 rightValue = [rightComponent unsignedIntValue];
409 if (leftValue < rightValue)
return NSOrderedAscending;
410 if (leftValue > rightValue)
return NSOrderedDescending;
414 return NSOrderedSame;
420 int days, hrs, mins, secs;
421 NSString *format =
nil;
423 days = floor(clock / 86400.0);
424 secs = floor(clock - days * 86400.0);
425 hrs = floor(secs / 3600.0);
427 mins = floor(secs / 60.0);
430 if (adjusting) format =
DESC(
@"clock-format-adjusting");
431 else format =
DESC(
@"clock-format");
433 return [NSString stringWithFormat:format, days, hrs, mins, secs];
439NSString *EscapedGraphVizString(NSString *
string)
441 NSString *
const srcStrings[] =
444 @"\\",
@"\"", @"\
'", @"\r", @"\n", @"\t", nil
446 NSString * const subStrings[] =
448 //Note: must be same order.
449 @"\\\\", @"\\\"", @"\\\'", @"\\r", @"\\n", @"\\t", nil
452 NSString * const * src = srcStrings;
453 NSString * const * sub = subStrings;
454 NSMutableString *mutable = nil;
455 NSString *result = nil;
457 mutable = [string mutableCopy];
460 [mutable replaceOccurrencesOfString:*src++
463 range:(NSRange){ 0, [mutable length] }];
466 if ([mutable length] == [string length])
472 result = [[mutable copy] autorelease];
479static BOOL NameIsTaken(NSString *name, NSSet *uniqueSet);
481NSString *GraphVizTokenString(NSString *string, NSMutableSet *uniqueSet)
483 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
485 BOOL lastWasUnderscore = NO;
486 NSUInteger i, length = [string length], ri = 0;
487 unichar result[length];
488 NSString *token = nil;
492 // Special case for first char - can't be digit.
493 unichar c = [string characterAtIndex:0];
497 lastWasUnderscore = YES;
501 for (i = 1; i < length; i++)
503 c = [string characterAtIndex:i];
506 if (lastWasUnderscore)
continue;
508 lastWasUnderscore = YES;
512 lastWasUnderscore = NO;
518 token = [NSString stringWithCharacters:result length:ri];
525 if (NameIsTaken(token, uniqueSet))
527 if (!lastWasUnderscore) token = [token stringByAppendingString:@"_"];
528 NSString *uniqueToken =
nil;
529 unsigned uniqueID = 2;
533 uniqueToken = [NSString stringWithFormat:@"%@%u", token, uniqueID];
534 if (!NameIsTaken(uniqueToken, uniqueSet))
break;
538 [uniqueSet addObject:token];
542 return [token autorelease];
546static BOOL NameIsTaken(NSString *name, NSSet *uniqueSet)
548 if ([uniqueSet containsObject:name])
return YES;
550 static NSSet *keywords =
nil;
551 if (keywords ==
nil) keywords = [[NSSet alloc] initWithObjects:@"node", @"edge", @"graph", @"digraph", @"subgraph", @"strict", nil];
553 return [keywords containsObject:[name lowercaseString]];
CGFloat OOStringWidthInEm(NSString *text)
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiter()
NSString * OOStringFromJSValue(JSContext *context, jsval value)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
OOINLINE void OOJSRelinquishContext(JSContext *context)
#define OOLogERR(class, format,...)
NSArray * ComponentsFromVersionString(NSString *string)
NSString * ClockToString(double clock, BOOL adjusting)
NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2)
NSMutableArray * ScanTokensFromString(NSString *values)
Quaternion QuaternionFromString(NSString *wxyzString, Quaternion defaultValue)
static NSString *const kOOLogStringVectorConversion
static NSString *const kOOLogStringRandomSeedConversion
static NSString *const kOOLogStringQuaternionConversion
BOOL ScanVectorAndQuaternionFromString(NSString *xyzwxyzString, Vector *outVector, Quaternion *outQuaternion)
NSPoint PointFromString(NSString *xyString)
Vector VectorFromString(NSString *xyzString, Vector defaultValue)
NSString * OOPadStringToEms(NSString *string, float padEms)
NSString * StringFromRandomSeed(Random_Seed seed)
Random_Seed RandomSeedFromString(NSString *abcdefString)
BOOL ScanHPVectorFromString(NSString *xyzString, HPVector *outVector)
BOOL ScanQuaternionFromString(NSString *wxyzString, Quaternion *outQuaternion)
NSString * OOStringFromDeciCredits(OOCreditsQuantity tenthsOfCredits, BOOL includeDecimal, BOOL includeSymbol)
BOOL ScanVectorFromString(NSString *xyzString, Vector *outVector)
NSString * StringFromPoint(NSPoint point)
uint64_t OOCreditsQuantity
JSObject * globalObject()
OOJavaScriptEngine * sharedEngine()
const Random_Seed kNilRandomSeed