Oolite
Loading...
Searching...
No Matches
OOStringParsing.h
Go to the documentation of this file.
1/*
2
3OOStringParsing.h
4
5Various functions for interpreting values from strings.
6
7Oolite
8Copyright (C) 2004-2013 Giles C Williams and contributors
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23MA 02110-1301, USA.
24
25*/
26
27#import "OOMaths.h"
28#import "OOTypes.h"
29#import "legacy_random.h"
30#import <Foundation/Foundation.h>
31
32@class Entity;
33
34NSMutableArray* ScanTokensFromString(NSString* values);
35
36// Note: these functions will leave their out values untouched if they fail (and return NO). They will not log an error if passed a NULL string (but will return NO). This means they can be used to, say, read dictionary entries which might not exist. They also ignore any extra components in the string.
37BOOL ScanVectorFromString(NSString* xyzString, Vector* outVector);
38BOOL ScanHPVectorFromString(NSString* xyzString, HPVector* outVector);
39BOOL ScanQuaternionFromString(NSString* wxyzString, Quaternion* outQuaternion);
40BOOL ScanVectorAndQuaternionFromString(NSString* xyzwxyzString, Vector* outVector, Quaternion* outQuaternion);
41
42Vector VectorFromString(NSString* xyzString, Vector defaultValue);
43Quaternion QuaternionFromString(NSString* wxyzString, Quaternion defaultValue);
44
45NSString* StringFromPoint(NSPoint point);
46NSPoint PointFromString(NSString* xyString);
47
48Random_Seed RandomSeedFromString(NSString* abcdefString);
49NSString* StringFromRandomSeed(Random_Seed seed);
50
51NSString* OOStringFromDeciCredits(OOCreditsQuantity tenthsOfCredits, BOOL includeDecimal, BOOL includeSymbol);
52OOINLINE NSString* OOStringFromIntCredits(OOCreditsQuantity integerCredits, BOOL includeSymbol)
53{
54 return OOStringFromDeciCredits(integerCredits * 10, NO, includeSymbol);
55}
56
57OOINLINE NSString* OOCredits(OOCreditsQuantity tenthsOfCredits)
58{
59 return OOStringFromDeciCredits(tenthsOfCredits, YES, YES);
60}
61OOINLINE NSString* OOIntCredits(OOCreditsQuantity integerCredits)
62{
63 return OOStringFromIntCredits(integerCredits, YES);
64}
65
66NSString* OOPadStringToEms(NSString* string, float numEms);
67
68@interface NSString (OOUtilities)
69
70// Case-insensitive match of [self pathExtension]
71- (BOOL)pathHasExtension:(NSString*)extension;
72- (BOOL)pathHasExtensionInArray:(NSArray*)extensions;
73
74@end
75
76// Given a string of the form 1.2.3.4 (with arbitrarily many components), return an array of unsigned ints.
77NSArray* ComponentsFromVersionString(NSString* string);
78
79/* Compare two arrays of unsigned int NSNumbers, as returned by
80 ComponentsFromVersionString().
81
82 Components are ordered from most to least significant, and a missing
83 component is treated as 0. Thus "1.7" < "1.60", and "1.2.3.0" == "1.2.3".
84*/
85NSComparisonResult CompareVersions(NSArray* version1, NSArray* version2);
86
87NSString* ClockToString(double clock, BOOL adjusting);
88
89#if DEBUG_GRAPHVIZ
90NSString* EscapedGraphVizString(NSString* string);
91
92/* GraphVizTokenString()
93 Generate a C-style identifier. Sequences of invalid characters and
94 underscores are replaced with single underscores. If uniqueSet is not nil,
95 uniqueness is achieved by appending numbers if necessary.
96
97 This can be used for any C-based langauge, but note that it excludes the
98 case-insensitive GraphViz keywords node, edge, graph, digraph, subgraph
99 and strict.
100*/
101NSString* GraphVizTokenString(NSString* string, NSMutableSet* uniqueSet);
102
103#endif
#define OOINLINE
NSMutableArray * ScanTokensFromString(NSString *values)
OOINLINE NSString * OOStringFromIntCredits(OOCreditsQuantity integerCredits, BOOL includeSymbol)
NSArray * ComponentsFromVersionString(NSString *string)
NSString * ClockToString(double clock, BOOL adjusting)
Quaternion QuaternionFromString(NSString *wxyzString, Quaternion defaultValue)
OOINLINE NSString * OOCredits(OOCreditsQuantity tenthsOfCredits)
BOOL ScanVectorAndQuaternionFromString(NSString *xyzwxyzString, Vector *outVector, Quaternion *outQuaternion)
OOINLINE NSString * OOIntCredits(OOCreditsQuantity integerCredits)
NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2)
NSPoint PointFromString(NSString *xyString)
Vector VectorFromString(NSString *xyzString, Vector defaultValue)
NSString * StringFromRandomSeed(Random_Seed seed)
Random_Seed RandomSeedFromString(NSString *abcdefString)
BOOL ScanHPVectorFromString(NSString *xyzString, HPVector *outVector)
NSString * OOPadStringToEms(NSString *string, float numEms)
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
Definition OOTypes.h:160