Oolite
Loading...
Searching...
No Matches
OOStringParsing.h File Reference
import "OOMaths.h"
import "OOTypes.h"
import "legacy_random.h"
import <Foundation/Foundation.h>
Include dependency graph for OOStringParsing.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

category  NSString(OOUtilities)

Functions

NSMutableArray * ScanTokensFromString (NSString *values)
BOOL ScanVectorFromString (NSString *xyzString, Vector *outVector)
BOOL ScanHPVectorFromString (NSString *xyzString, HPVector *outVector)
BOOL ScanQuaternionFromString (NSString *wxyzString, Quaternion *outQuaternion)
BOOL ScanVectorAndQuaternionFromString (NSString *xyzwxyzString, Vector *outVector, Quaternion *outQuaternion)
Vector VectorFromString (NSString *xyzString, Vector defaultValue)
Quaternion QuaternionFromString (NSString *wxyzString, Quaternion defaultValue)
NSString * StringFromPoint (NSPoint point)
NSPoint PointFromString (NSString *xyString)
Random_Seed RandomSeedFromString (NSString *abcdefString)
NSString * StringFromRandomSeed (Random_Seed seed)
NSString * OOStringFromDeciCredits (OOCreditsQuantity tenthsOfCredits, BOOL includeDecimal, BOOL includeSymbol)
OOINLINE NSString * OOStringFromIntCredits (OOCreditsQuantity integerCredits, BOOL includeSymbol)
OOINLINE NSString * OOCredits (OOCreditsQuantity tenthsOfCredits)
OOINLINE NSString * OOIntCredits (OOCreditsQuantity integerCredits)
NSString * OOPadStringToEms (NSString *string, float numEms)
NSArray * ComponentsFromVersionString (NSString *string)
NSComparisonResult CompareVersions (NSArray *version1, NSArray *version2)
NSString * ClockToString (double clock, BOOL adjusting)

Function Documentation

◆ ClockToString()

NSString * ClockToString ( double clock,
BOOL adjusting )

Definition at line 434 of file OOStringParsing.m.

435{
436 int days, hrs, mins, secs;
437 NSString* format = nil;
438
439 days = floor(clock / 86400.0);
440 secs = floor(clock - days * 86400.0);
441 hrs = floor(secs / 3600.0);
442 secs %= 3600;
443 mins = floor(secs / 60.0);
444 secs %= 60;
445
446 if (adjusting)
447 format = DESC(@"clock-format-adjusting");
448 else
449 format = DESC(@"clock-format");
450
451 return [NSString stringWithFormat:format, days, hrs, mins, secs];
452}
return nil
#define DESC(key)
Definition Universe.h:832

References DESC, and nil.

Referenced by ClockClockStringForTime(), ClockClockStringForTime(), PlayerEntity::dial_clock, PlayerEntity::dial_clock_adjusted, WormholeEntity::dumpSelfState, and PlayerEntity(OOLoadSavePrivate)::showCommanderShip:.

Here is the caller graph for this function:

◆ CompareVersions()

NSComparisonResult CompareVersions ( NSArray * version1,
NSArray * version2 )

Definition at line 401 of file OOStringParsing.m.

402{
403 NSEnumerator *leftEnum = nil,
404 *rightEnum = nil;
405 NSNumber *leftComponent = nil,
406 *rightComponent = nil;
407 unsigned leftValue,
408 rightValue;
409
410 leftEnum = [version1 objectEnumerator];
411 rightEnum = [version2 objectEnumerator];
412
413 for (;;) {
414 leftComponent = [leftEnum nextObject];
415 rightComponent = [rightEnum nextObject];
416
417 if (leftComponent == nil && rightComponent == nil)
418 break; // End of both versions
419
420 // We'll get 0 if the component is nil, which is what we want.
421 leftValue = [leftComponent unsignedIntValue];
422 rightValue = [rightComponent unsignedIntValue];
423
424 if (leftValue < rightValue)
425 return NSOrderedAscending;
426 if (leftValue > rightValue)
427 return NSOrderedDescending;
428 }
429
430 // If there was a difference, we'd have returned already.
431 return NSOrderedSame;
432}

References nil.

Referenced by ResourceManager::areRequirementsFulfilled:forOXP:andFile:, OOOXZManager(NSURLConnectionDataDelegate)::installableState:, ResourceManager::matchVersions:withVersion:, OoliteCompareVersion(), OoliteCompareVersion(), and OOCheckRequiresPListVerifierStage::run.

Here is the caller graph for this function:

◆ ComponentsFromVersionString()

NSArray * ComponentsFromVersionString ( NSString * string)

Definition at line 374 of file OOStringParsing.m.

375{
376 NSArray* stringComponents = nil;
377 NSMutableArray* result = nil;
378 NSUInteger i, count;
379 int value;
380 id component;
381
382 stringComponents = [string componentsSeparatedByString:@" "];
383 stringComponents = [[stringComponents objectAtIndex:0] componentsSeparatedByString:@"-"];
384 stringComponents = [[stringComponents objectAtIndex:0] componentsSeparatedByString:@"."];
385 count = [stringComponents count];
386 result = [NSMutableArray arrayWithCapacity:count];
387
388 for (i = 0; i != count; ++i) {
389 component = [stringComponents objectAtIndex:i];
390 if ([component respondsToSelector:@selector(intValue)])
391 value = MAX([component intValue], 0);
392 else
393 value = 0;
394
395 [result addObject:[NSNumber numberWithUnsignedInt:value]];
396 }
397
398 return result;
399}
#define MAX(A, B)
Definition OOMaths.h:94
unsigned count

References count, MAX, and nil.

Referenced by ResourceManager::areRequirementsFulfilled:forOXP:andFile:, OOOXZManager(NSURLConnectionDataDelegate)::installableState:, ResourceManager::matchVersions:withVersion:, OoliteCompareVersion(), OoliteCompareVersion(), OOCheckRequiresPListVerifierStage::run, and VersionComponents().

Here is the caller graph for this function:

◆ OOCredits()

OOINLINE NSString * OOCredits ( OOCreditsQuantity tenthsOfCredits)

Definition at line 57 of file OOStringParsing.h.

58{
59 return OOStringFromDeciCredits(tenthsOfCredits, YES, YES);
60}
NSString * OOStringFromDeciCredits(OOCreditsQuantity tenthsOfCredits, BOOL includeDecimal, BOOL includeSymbol)

References OOINLINE, and OOStringFromDeciCredits().

Referenced by Operator_cr(), Operator_dcr(), and PlayerEntity::setGuiToStatusScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOIntCredits()

OOINLINE NSString * OOIntCredits ( OOCreditsQuantity integerCredits)

Definition at line 61 of file OOStringParsing.h.

62{
63 return OOStringFromIntCredits(integerCredits, YES);
64}
OOINLINE NSString * OOStringFromIntCredits(OOCreditsQuantity integerCredits, BOOL includeSymbol)

References OOINLINE, and OOStringFromIntCredits().

Referenced by PlayerEntity(ContractsPrivate)::contractsListFromArray:forCargo:forParcels:, Operator_icr(), and Operator_idcr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOPadStringToEms()

NSString * OOPadStringToEms ( NSString * string,
float numEms )

Definition at line 253 of file OOStringParsing.m.

254{
255 NSString* result = string;
256 float numEms = padEms - OOStringWidthInEm(result);
257 if (numEms > 0) {
258 numEms /= OOStringWidthInEm(@" "); // start with wide space
259 result = [[@"" stringByPaddingToLength:(NSUInteger)numEms withString:@" " startingAtIndex:0] stringByAppendingString:result];
260 }
261 // most of the way there, so switch to narrow space
262 numEms = padEms - OOStringWidthInEm(result);
263 if (numEms > 0) {
264 numEms /= OOStringWidthInEm(@"\037"); // 037 is narrow space
265 result = [[@"" stringByPaddingToLength:(NSUInteger)numEms withString:@"\037" startingAtIndex:0] stringByAppendingString:result];
266 }
267 return result;
268}
CGFloat OOStringWidthInEm(NSString *text)

References OOStringWidthInEm().

Referenced by PlayerEntity(OOPrivate)::showMarketScreenDataLine:forGood:inMarket:holdQuantity:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOStringFromDeciCredits()

NSString * OOStringFromDeciCredits ( OOCreditsQuantity tenthsOfCredits,
BOOL includeDecimal,
BOOL includeSymbol )

Definition at line 270 of file OOStringParsing.m.

271{
272 JSContext* context = OOJSAcquireContext();
273#if OOJS_QUICKJS
274 JSValueConst global = [[OOJavaScriptEngine sharedEngine] globalObject];
275 JSValue exception = JS_UNDEFINED;
276#else
277 JSObject* global = [[OOJavaScriptEngine sharedEngine] globalObject];
278 JSObject* fakeRoot;
279 jsval method;
280 jsval rval;
281 jsval exception;
282#endif
283 NSString* result = nil;
284 BOOL hadException;
285
286 /* Because the |cr etc. formatting operators call this, and the
287 implementation may use string expansion, we need to ensure recursion
288 can't happen.
289 */
290 static BOOL reentrancyLock;
291 if (reentrancyLock)
292 return [NSString stringWithFormat:@"%0.1f", tenthsOfCredits * 0.1];
293
294 reentrancyLock = YES;
295
296#if OOJS_QUICKJS
297 hadException = JS_HasException(context);
298 if (hadException)
299 exception = JS_GetException(context); // Clears it.
300
301 JSValue method = JS_GetProperty(context, global, OOJSID("formatCredits"));
302 if (!JS_IsException(method)) {
303 JSValue args[3] = { JS_NewNumber(context, tenthsOfCredits * 0.1), OOJSValueFromBOOL(includeDecimal), OOJSValueFromBOOL(includeSymbol) };
304
306 JSValue rval = JS_Call(context, method, global, 3, args);
308
309 if (JS_IsException(rval))
311 else
312 result = OOStringFromJSValue(context, rval);
313 JS_FreeValue(context, rval);
314 } else {
316 }
317 JS_FreeValue(context, method);
318
319 if (hadException)
320 JS_Throw(context, exception); // Takes ownership.
321#else
322 hadException = JS_GetPendingException(context, &exception);
323 JS_ClearPendingException(context);
324
325 if (JS_GetMethodById(context, global, OOJSID("formatCredits"), &fakeRoot, &method)) {
326 jsval args[3];
327 if (JS_NewNumberValue(context, tenthsOfCredits * 0.1, &args[0])) {
328 args[1] = OOJSValueFromBOOL(includeDecimal);
329 args[2] = OOJSValueFromBOOL(includeSymbol);
330
332 JS_CallFunctionValue(context, global, method, 3, args, &rval);
334
335 result = OOStringFromJSValue(context, rval);
336 }
337 }
338
339 if (hadException)
340 JS_SetPendingException(context, exception);
341#endif
342
343 OOJSRelinquishContext(context);
344
345 if (EXPECT_NOT(result == nil))
346 result = [NSString stringWithFormat:@"%li", (long)(tenthsOfCredits) / 10];
347
348 reentrancyLock = NO;
349
350 return result;
351}
#define EXPECT_NOT(x)
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiter()
#define OOJSID(str)
Definition OOJSPropID.h:42
NSString * OOStringFromJSValue(JSContext *context, jsval value)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSReportPendingException(JSContext *context)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
OOINLINE void OOJSRelinquishContext(JSContext *context)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque

References EXPECT_NOT, OOJavaScriptEngine::globalObject, nil, OOJSAcquireContext(), OOJSID, OOJSRelinquishContext(), OOJSReportPendingException(), OOJSStartTimeLimiter, OOJSStopTimeLimiter, OOJSValueFromBOOL(), OOStringFromJSValue(), and OOJavaScriptEngine::sharedEngine.

Referenced by PlayerEntity(ScriptMethods)::creditsFormattedForSubstitution, OOCredits(), and OOStringFromIntCredits().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOStringFromIntCredits()

OOINLINE NSString * OOStringFromIntCredits ( OOCreditsQuantity integerCredits,
BOOL includeSymbol )

Definition at line 52 of file OOStringParsing.h.

53{
54 return OOStringFromDeciCredits(integerCredits * 10, NO, includeSymbol);
55}

References OOINLINE, and OOStringFromDeciCredits().

Referenced by OOIntCredits().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PointFromString()

NSPoint PointFromString ( NSString * xyString)

Definition at line 204 of file OOStringParsing.m.

205{
206 NSArray* tokens = ScanTokensFromString(xyString);
207 NSPoint result = NSZeroPoint;
208
209 NSUInteger n_tokens = [tokens count];
210 if (n_tokens == 2) {
211 result.x = [[tokens objectAtIndex:0] doubleValue];
212 result.y = [[tokens objectAtIndex:1] doubleValue];
213 }
214 return result;
215}
NSMutableArray * ScanTokensFromString(NSString *values)

References ScanTokensFromString().

Referenced by OOSystemDescriptionManager::buildRouteCache, PlayerEntity::doBookkeeping:, PlayerEntity::enterGalacticWitchspace, PlayerEntity(OOPrivate)::hyperspaceJumpDistance, OOTrumble::setFromDictionary:, PlayerEntity::setSystemID:, PlayerEntity::setTargetSystemID:, and PlayerEntity(OOPrivate)::witchJumpTo:misjump:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ QuaternionFromString()

Quaternion QuaternionFromString ( NSString * wxyzString,
Quaternion defaultValue )

Definition at line 191 of file OOStringParsing.m.

192{
193 Quaternion result;
194 if (!ScanQuaternionFromString(wxyzString, &result))
195 result = defaultValue;
196 return result;
197}
BOOL ScanQuaternionFromString(NSString *wxyzString, Quaternion *outQuaternion)

References ScanQuaternionFromString().

Here is the call graph for this function:

◆ RandomSeedFromString()

Random_Seed RandomSeedFromString ( NSString * abcdefString)

Definition at line 217 of file OOStringParsing.m.

218{
219 Random_Seed result;
220 int abcdef[] = { 0, 0, 0, 0, 0, 0 };
221 int i = 0;
222 NSString* error = nil;
223 NSScanner* scanner = [NSScanner scannerWithString:abcdefString];
224
225 while (![scanner isAtEnd] && i < 6 && !error) {
226 if (![scanner scanInt:&abcdef[i++]])
227 error = @"could not scan a int value.";
228 }
229
230 if (!error && i < 6)
231 error = @"found less than six int values.";
232
233 if (!error) {
234 result.a = abcdef[0];
235 result.b = abcdef[1];
236 result.c = abcdef[2];
237 result.d = abcdef[3];
238 result.e = abcdef[4];
239 result.f = abcdef[5];
240 } else {
241 OOLogERR(kOOLogStringRandomSeedConversion, @"cannot make Random_Seed from '%@': %@", abcdefString, error);
242 result = kNilRandomSeed;
243 }
244
245 return result;
246}
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
static NSString *const kOOLogStringRandomSeedConversion
const Random_Seed kNilRandomSeed

References Random_Seed::a, Random_Seed::b, Random_Seed::c, Random_Seed::d, Random_Seed::e, Random_Seed::f, kNilRandomSeed, kOOLogStringRandomSeedConversion, nil, and OOLogERR.

Referenced by OOSystemDescriptionManager::getRandomSeedForCurrentSystem, OOSystemDescriptionManager::getRandomSeedForSystem:inGalaxy:, PlanetEntity::initFromDictionary:withAtmosphere:andSeed:, and OOCharacter(Private)::setCharacterFromDictionary:.

Here is the caller graph for this function:

◆ ScanHPVectorFromString()

BOOL ScanHPVectorFromString ( NSString * xyzString,
HPVector * outVector )

Definition at line 100 of file OOStringParsing.m.

101{
102 Vector scanVector;
103 assert(outVector != NULL);
104 BOOL result = ScanVectorFromString(xyzString, &scanVector);
105 if (!result) {
106 return NO;
107 }
108 *outVector = vectorToHPVector(scanVector);
109 return YES;
110}
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
BOOL ScanVectorFromString(NSString *xyzString, Vector *outVector)

References ScanVectorFromString(), and vectorToHPVector().

Referenced by PlayerEntity(Scripting)::addMoon:, PlayerEntity(Scripting)::addPlanet:, and OOHPVectorFromObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScanQuaternionFromString()

BOOL ScanQuaternionFromString ( NSString * wxyzString,
Quaternion * outQuaternion )

Definition at line 112 of file OOStringParsing.m.

113{
114 GLfloat wxyz[] = { 1.0, 0.0, 0.0, 0.0 };
115 int i = 0;
116 NSString* error = nil;
117 NSScanner* scanner = nil;
118
119 assert(outQuaternion != NULL);
120 if (wxyzString == nil)
121 return NO;
122
123 if (!error)
124 scanner = [NSScanner scannerWithString:wxyzString];
125 while (![scanner isAtEnd] && i < 4 && !error) {
126 if (![scanner scanFloat:&wxyz[i++]])
127 error = @"could not scan a float value.";
128 }
129
130 if (!error && i < 4)
131 error = @"found less than four float values.";
132
133 if (!error) {
134 outQuaternion->w = wxyz[0];
135 outQuaternion->x = wxyz[1];
136 outQuaternion->y = wxyz[2];
137 outQuaternion->z = wxyz[3];
138 quaternion_normalize(outQuaternion);
139 return YES;
140 } else {
141 OOLogERR(kOOLogStringQuaternionConversion, @"cannot make quaternion from '%@': %@", wxyzString, error);
142 return NO;
143 }
144}
OOINLINE void quaternion_normalize(Quaternion *quat) NONNULL_FUNC ALWAYS_INLINE_FUNC
static NSString *const kOOLogStringQuaternionConversion
OOScalar w
OOScalar x
OOScalar y
OOScalar z

References kOOLogStringQuaternionConversion, nil, OOLogERR, quaternion_normalize(), Quaternion::w, Quaternion::x, Quaternion::y, and Quaternion::z.

Referenced by PlayerEntity(Scripting)::addMoon:, PlayerEntity(Scripting)::addPlanet:, OOQuaternionFromObject(), and QuaternionFromString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScanTokensFromString()

NSMutableArray * ScanTokensFromString ( NSString * values)

Definition at line 44 of file OOStringParsing.m.

45{
46 NSMutableArray* result = nil;
47 NSScanner* scanner = nil;
48 NSString* token = nil;
49 static NSCharacterSet* space_set = nil;
50
51 // Note: Shark suggests we're getting a lot of early exits, but testing showed a pretty steady 2% early exit rate.
52 if (EXPECT_NOT(values == nil))
53 return [NSMutableArray array];
54 if (EXPECT_NOT(space_set == nil))
55 space_set = [[NSCharacterSet whitespaceAndNewlineCharacterSet] retain];
56
57 result = [NSMutableArray array];
58 scanner = [NSScanner scannerWithString:values];
59
60 while (![scanner isAtEnd]) {
61 [scanner ooliteScanCharactersFromSet:space_set intoString:NULL];
62 if ([scanner ooliteScanUpToCharactersFromSet:space_set intoString:&token]) {
63 [result addObject:token];
64 }
65 }
66
67 return result;
68}

References EXPECT_NOT, and nil.

Referenced by PlayerEntity(Scripting)::add:, GuiDisplayGen::addLongText:startingAtRow:align:, PlayerEntity(Scripting)::addMissionDestination:, PlayerEntity(Scripting)::addShips:, PlayerEntity(Scripting)::addShipsAt:, PlayerEntity(Scripting)::addShipsAtPrecisely:, PlayerEntity(Scripting)::addShipsWithinRadius:, PlayerEntity(Scripting)::addSystemShips:, PlayerEntity(Scripting)::awardCargo:, Universe::coordinatesFromCoordinateSystemString:, OOSystemDescriptionManager::getPropertiesForSystemKey:, ShipEntity::interpretAIMessage:, PlayerEntity(Scripting)::messageShipAIs:, OOParseRolesFromString(), PointFromString(), GuiDisplayGen::printLongText:align:color:fadeTime:key:addToArray:, PlayerEntity(Scripting)::processSceneString:atOffset:, ShipEntity(PureAI)::randomPauseAI:, SkyEntity(OOPrivate)::readColor1:andColor2:andColor3:andColor4:fromDictionary:, GuiDisplayGen::reflowTextForMFD:, PlayerEntity(Scripting)::removeMissionDestination:, PlayerEntity(Scripting)::replaceVariablesInString:, OOCheckShipDataPListVerifierStage(OOPrivate)::rolesFromString:, SanitizeActionStatement(), SanitizeCondition(), ShipEntity(PureAI)::sendScriptMessage:, PlayerEntity(Scripting)::set:, PlayerEntity::setCommanderDataFromDictionary:, ShipEntity(PureAI)::setCoordinates:, PlayerEntity(Scripting)::setGalacticHyperspaceFixedCoordsTo:, OOSystemDescriptionManager::setProperties:forSystemKey:, OOSystemDescriptionManager::setProperty:forSystemKey:andLayer:toValue:fromManifest:, ShipEntity::setUpSubEntities, OOShipRegistry(OODataLoader)::shipIsBallTurretForKey:inShipData:, ShipEntity::spawn:, PlayerEntity(Scripting)::subtract:, AI::takeAction:, OOShipRegistry(OODataLoader)::translateOldStyleSubentityDeclaration:forShip:shipData:fatalError:, and OOSystemDescriptionEntry(OOPrivate)::validateProperty:withValue:.

Here is the caller graph for this function:

◆ ScanVectorAndQuaternionFromString()

BOOL ScanVectorAndQuaternionFromString ( NSString * xyzwxyzString,
Vector * outVector,
Quaternion * outQuaternion )

Definition at line 146 of file OOStringParsing.m.

147{
148 GLfloat xyzwxyz[] = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 };
149 int i = 0;
150 NSString* error = nil;
151 NSScanner* scanner = nil;
152
153 assert(outVector != NULL && outQuaternion != NULL);
154 if (xyzwxyzString == nil)
155 return NO;
156
157 if (!error)
158 scanner = [NSScanner scannerWithString:xyzwxyzString];
159 while (![scanner isAtEnd] && i < 7 && !error) {
160 if (![scanner scanFloat:&xyzwxyz[i++]])
161 error = @"Could not scan a float value.";
162 }
163
164 if (!error && i < 7)
165 error = @"Found less than seven float values.";
166
167 if (error) {
168 OOLogERR(kOOLogStringQuaternionConversion, @"cannot make vector and quaternion from '%@': %@", xyzwxyzString, error);
169 return NO;
170 }
171
172 outVector->x = xyzwxyz[0];
173 outVector->y = xyzwxyz[1];
174 outVector->z = xyzwxyz[2];
175 outQuaternion->w = xyzwxyz[3];
176 outQuaternion->x = xyzwxyz[4];
177 outQuaternion->y = xyzwxyz[5];
178 outQuaternion->z = xyzwxyz[6];
179
180 return YES;
181}
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References kOOLogStringQuaternionConversion, nil, OOLogERR, Quaternion::w, Quaternion::x, Vector::x, Quaternion::y, Vector::y, Quaternion::z, and Vector::z.

Referenced by PlayerEntity(Scripting)::processSceneString:atOffset:.

Here is the caller graph for this function:

◆ ScanVectorFromString()

BOOL ScanVectorFromString ( NSString * xyzString,
Vector * outVector )

Definition at line 70 of file OOStringParsing.m.

71{
72 GLfloat xyz[] = { 0.0, 0.0, 0.0 };
73 int i = 0;
74 NSString* error = nil;
75 NSScanner* scanner = nil;
76
77 assert(outVector != NULL);
78 if (xyzString == nil)
79 return NO;
80
81 if (!error)
82 scanner = [NSScanner scannerWithString:xyzString];
83 while (![scanner isAtEnd] && i < 3 && !error) {
84 if (![scanner scanFloat:&xyz[i++]])
85 error = @"could not scan a float value.";
86 }
87
88 if (!error && i < 3)
89 error = @"found less than three float values.";
90
91 if (!error) {
92 *outVector = make_vector(xyz[0], xyz[1], xyz[2]);
93 return YES;
94 } else {
95 OOLogERR(kOOLogStringVectorConversion, @"cannot make vector from '%@': %@", xyzString, error);
96 return NO;
97 }
98}
static NSString *const kOOLogStringVectorConversion
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149

References kOOLogStringVectorConversion, make_vector(), nil, and OOLogERR.

Referenced by PlanetEntity::initFromDictionary:withAtmosphere:andSeed:, OOVectorFromObject(), PlayerEntity(Scripting)::processSceneString:atOffset:, ScanHPVectorFromString(), PlanetEntity(OOPrivate)::setTextureColorForPlanet:inSystem:, ShipEntity::update:, and VectorFromString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StringFromPoint()

NSString * StringFromPoint ( NSPoint point)

Definition at line 199 of file OOStringParsing.m.

200{
201 return [NSString stringWithFormat:@"%f %f", point.x, point.y];
202}

◆ StringFromRandomSeed()

NSString * StringFromRandomSeed ( Random_Seed seed)

Definition at line 248 of file OOStringParsing.m.

249{
250 return [NSString stringWithFormat:@"%d %d %d %d %d %d", seed.a, seed.b, seed.c, seed.d, seed.e, seed.f];
251}

◆ VectorFromString()

Vector VectorFromString ( NSString * xyzString,
Vector defaultValue )

Definition at line 183 of file OOStringParsing.m.

184{
185 Vector result;
186 if (!ScanVectorFromString(xyzString, &result))
187 result = defaultValue;
188 return result;
189}

References ScanVectorFromString().

Here is the call graph for this function: