Oolite 1.91.0.7604-240417-a536cbe
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 <Foundation/Foundation.h>
28#import "OOMaths.h"
29#import "OOTypes.h"
30#import "legacy_random.h"
31
32@class Entity;
33
34
35NSMutableArray *ScanTokensFromString(NSString *values);
36
37// 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.
38BOOL ScanVectorFromString(NSString *xyzString, Vector *outVector);
39BOOL ScanHPVectorFromString(NSString *xyzString, HPVector *outVector);
40BOOL ScanQuaternionFromString(NSString *wxyzString, Quaternion *outQuaternion);
41BOOL ScanVectorAndQuaternionFromString(NSString *xyzwxyzString, Vector *outVector, Quaternion *outQuaternion);
42
43Vector VectorFromString(NSString *xyzString, Vector defaultValue);
44Quaternion QuaternionFromString(NSString *wxyzString, Quaternion defaultValue);
45
46NSString *StringFromPoint(NSPoint point);
47NSPoint PointFromString(NSString *xyString);
48
49Random_Seed RandomSeedFromString(NSString *abcdefString);
50NSString *StringFromRandomSeed(Random_Seed seed);
51
52
53NSString *OOStringFromDeciCredits(OOCreditsQuantity tenthsOfCredits, BOOL includeDecimal, BOOL includeSymbol);
54OOINLINE NSString *OOStringFromIntCredits(OOCreditsQuantity integerCredits, BOOL includeSymbol)
55{
56 return OOStringFromDeciCredits(integerCredits * 10, NO, includeSymbol);
57}
58
59OOINLINE NSString *OOCredits(OOCreditsQuantity tenthsOfCredits)
60{
61 return OOStringFromDeciCredits(tenthsOfCredits, YES, YES);
62}
63OOINLINE NSString *OOIntCredits(OOCreditsQuantity integerCredits)
64{
65 return OOStringFromIntCredits(integerCredits, YES);
66}
67
68NSString *OOPadStringToEms(NSString * string, float numEms);
69
70@interface NSString (OOUtilities)
71
72// Case-insensitive match of [self pathExtension]
73- (BOOL)pathHasExtension:(NSString *)extension;
74- (BOOL)pathHasExtensionInArray:(NSArray *)extensions;
75
76@end
77
78
79// Given a string of the form 1.2.3.4 (with arbitrarily many components), return an array of unsigned ints.
80NSArray *ComponentsFromVersionString(NSString *string);
81
82/* Compare two arrays of unsigned int NSNumbers, as returned by
83 ComponentsFromVersionString().
84
85 Components are ordered from most to least significant, and a missing
86 component is treated as 0. Thus "1.7" < "1.60", and "1.2.3.0" == "1.2.3".
87*/
88NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2);
89
90
91NSString *ClockToString(double clock, BOOL adjusting);
92
93
94#if DEBUG_GRAPHVIZ
95NSString *EscapedGraphVizString(NSString *string);
96
97/* GraphVizTokenString()
98 Generate a C-style identifier. Sequences of invalid characters and
99 underscores are replaced with single underscores. If uniqueSet is not nil,
100 uniqueness is achieved by appending numbers if necessary.
101
102 This can be used for any C-based langauge, but note that it excludes the
103 case-insensitive GraphViz keywords node, edge, graph, digraph, subgraph
104 and strict.
105*/
106NSString *GraphVizTokenString(NSString *string, NSMutableSet *uniqueSet);
107
108#endif
#define OOINLINE
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)
NSMutableArray * ScanTokensFromString(NSString *values)
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:182