Line data Source code
1 0 : /* 2 : 3 : OOStringParsing.h 4 : 5 : Various functions for interpreting values from strings. 6 : 7 : Oolite 8 : Copyright (C) 2004-2013 Giles C Williams and contributors 9 : 10 : This program is free software; you can redistribute it and/or 11 : modify it under the terms of the GNU General Public License 12 : as published by the Free Software Foundation; either version 2 13 : of the License, or (at your option) any later version. 14 : 15 : This program is distributed in the hope that it will be useful, 16 : but WITHOUT ANY WARRANTY; without even the implied warranty of 17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 : GNU General Public License for more details. 19 : 20 : You should have received a copy of the GNU General Public License 21 : along with this program; if not, write to the Free Software 22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 : MA 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 : 35 0 : NSMutableArray *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. 38 0 : BOOL ScanVectorFromString(NSString *xyzString, Vector *outVector); 39 0 : BOOL ScanHPVectorFromString(NSString *xyzString, HPVector *outVector); 40 0 : BOOL ScanQuaternionFromString(NSString *wxyzString, Quaternion *outQuaternion); 41 0 : BOOL ScanVectorAndQuaternionFromString(NSString *xyzwxyzString, Vector *outVector, Quaternion *outQuaternion); 42 : 43 0 : Vector VectorFromString(NSString *xyzString, Vector defaultValue); 44 0 : Quaternion QuaternionFromString(NSString *wxyzString, Quaternion defaultValue); 45 : 46 0 : NSString *StringFromPoint(NSPoint point); 47 0 : NSPoint PointFromString(NSString *xyString); 48 : 49 0 : Random_Seed RandomSeedFromString(NSString *abcdefString); 50 0 : NSString *StringFromRandomSeed(Random_Seed seed); 51 : 52 : 53 0 : NSString *OOStringFromDeciCredits(OOCreditsQuantity tenthsOfCredits, BOOL includeDecimal, BOOL includeSymbol); 54 0 : OOINLINE NSString *OOStringFromIntCredits(OOCreditsQuantity integerCredits, BOOL includeSymbol) 55 : { 56 : return OOStringFromDeciCredits(integerCredits * 10, NO, includeSymbol); 57 : } 58 : 59 0 : OOINLINE NSString *OOCredits(OOCreditsQuantity tenthsOfCredits) 60 : { 61 : return OOStringFromDeciCredits(tenthsOfCredits, YES, YES); 62 : } 63 0 : OOINLINE NSString *OOIntCredits(OOCreditsQuantity integerCredits) 64 : { 65 : return OOStringFromIntCredits(integerCredits, YES); 66 : } 67 : 68 0 : NSString *OOPadStringToEms(NSString * string, float numEms); 69 : 70 : @interface NSString (OOUtilities) 71 : 72 : // Case-insensitive match of [self pathExtension] 73 0 : - (BOOL)pathHasExtension:(NSString *)extension; 74 0 : - (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. 80 0 : NSArray *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 : */ 88 0 : NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2); 89 : 90 : 91 0 : NSString *ClockToString(double clock, BOOL adjusting); 92 : 93 : 94 : #if DEBUG_GRAPHVIZ 95 : NSString *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 : */ 106 : NSString *GraphVizTokenString(NSString *string, NSMutableSet *uniqueSet); 107 : 108 : #endif