OpendTect-6_4  6.4
string2.h
Go to the documentation of this file.
1 #ifndef string2_h
2 #define string2_h
3 
4 /*@+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril
9  Date: 11-4-1994
10  Contents: Extra string functions
11  RCS: $Id$
12 ________________________________________________________________________
13 -*/
14 
15 /* Functions making sure you don't need <string.h>
16 
17  (1) Usually OD::String or its subclass BufferString can already do the job
18  (2) toString(XX) for all simple types
19  (3) toXX from const char* for most used simple types
20  (4) Replacement for strchr and strstr: firstOcc()
21  (5) Various construction-, manipulation- and matching functions
22 
23  */
24 
25 #include "basicmod.h"
26 #include "plftypes.h"
27 #include "commondefs.h"
28 #include <ctype.h>
29 #include <wctype.h>
30 namespace OD { class String; }
31 class CompoundKey;
32 class BufferStringSet;
33 
34 mGlobal(Basic) const char* toString(od_int32);
35 mGlobal(Basic) const char* toString(od_uint32);
36 mGlobal(Basic) const char* toString(od_int64);
37 mGlobal(Basic) const char* toString(od_uint64);
38 mGlobal(Basic) const char* toString(float);
39 mGlobal(Basic) const char* toString(float,int nrdec);
40 mGlobal(Basic) const char* toString(float,char format,int precision);
41 mGlobal(Basic) const char* toStringLim(float,int maxtxtwdth);
42 mGlobal(Basic) const char* toStringPrecise(float);
43 mGlobal(Basic) const char* toString(double);
44 mGlobal(Basic) const char* toString(double,int nrdec);
45 mGlobal(Basic) const char* toString(double,char format,int precision);
46 mGlobal(Basic) const char* toStringLim(double,int maxtxtwdth);
47 mGlobal(Basic) const char* toStringPrecise(double);
48 mGlobal(Basic) const char* toString(short);
49 mGlobal(Basic) const char* toString(unsigned short);
50 mGlobal(Basic) const char* toString(const char*);
51 mGlobal(Basic) const char* toString(unsigned char);
52 mGlobal(Basic) const char* toString(signed char);
53 mGlobal(Basic) const char* toString(bool);
54 mGlobal(Basic) const char* toString(const OD::String&);
55 mGlobal(Basic) const char* toString(const CompoundKey&);
56 
57 mGlobal(Basic) bool getFromString(int&,const char*,int udfval);
58 mGlobal(Basic) bool getFromString(od_int64&,const char*,od_int64 udfval);
59 mGlobal(Basic) bool getFromString(float&,const char*,float udfval);
60 mGlobal(Basic) bool getFromString(double&,const char*,double udfval);
61 mGlobal(Basic) bool getFromString(bool&,const char*);
62 mGlobal(Basic) bool yesNoFromString(const char*);
63 
64 inline bool toBool( const char* s, bool defval=true )
65 { return s && *s ? yesNoFromString(s) : defval; }
66 
67 inline float toFloat( const char* s, float defval=0 )
68 { float ret = defval; getFromString( ret, s, ret ); return ret; }
69 
70 inline double toDouble( const char* s, double defval=0 )
71 { double ret = defval; getFromString( ret, s, ret ); return ret; }
72 
73 inline int toInt( const char* s, int defval=0 )
74 { int ret = defval; getFromString( ret, s, ret ); return ret; }
75 
76 inline od_int64 toInt64( const char* s, od_int64 defval=0 )
77 { od_int64 ret = defval; getFromString( ret, s, ret ); return ret; }
78 
79 
81 #define mSkipBlanks(ptr) \
82  { if ( ptr ) { while ( *(ptr) && iswspace(*(ptr)) ) (ptr)++; } }
83 
85 #define mSkipNonBlanks(ptr) \
86  { if ( ptr ) { while ( *(ptr) && !iswspace(*(ptr)) ) (ptr)++; } }
87 
89 #define mTrimBlanks(ptr) \
90  { mSkipBlanks(ptr); removeTrailingBlanks(ptr); }
91 
92 
93 mGlobal(Basic) bool caseInsensitiveEqual(const char*,const char*,
94  int match_nrchars=-1);
96 mGlobal(Basic) bool stringStartsWith(const char* startstring,
97  const char* maybebigger);
99 mGlobal(Basic) bool stringStartsWithCI(const char*,const char*);
101 mGlobal(Basic) bool stringEndsWith(const char* endstring,
102  const char* maybebigger);
104 mGlobal(Basic) bool stringEndsWithCI(const char*,const char*);
107 mGlobal(Basic) void removeTrailingBlanks(char*);
109 mGlobal(Basic) void cleanupString(char*,bool,bool,bool);
111 mGlobal(Basic) bool isNumberString(const char*,bool int_only=false);
113 mGlobal(Basic) bool isAlphaNumString(const char*,bool allowspace = false);
116 mGlobal(Basic) const char* getNextWord(const char*,char*);
121 mGlobal(Basic) const char* firstOcc(const char*,char);
123 mGlobal(Basic) char* firstOcc(char*,char);
125 mGlobal(Basic) const char* lastOcc(const char*,char);
127 mGlobal(Basic) char* lastOcc(char*,char);
129 mGlobal(Basic) const char* firstOcc(const char*,const char*);
131 mGlobal(Basic) char* firstOcc(char*,const char*);
133 mGlobal(Basic) const char* lastOcc(const char*,const char*);
135 mGlobal(Basic) char* lastOcc(char*,const char*);
136 
137 mGlobal(Basic) const char* getYesNoString(bool);
139 mGlobal(Basic) const char* getDistUnitString(bool isfeet,bool withparentheses);
141 mGlobal(Basic) const char* getVelUnitString(bool isfeet,bool withparentheses);
144 mGlobal(Basic) const char* getRankPostFix(int);
146 mGlobal(Basic) const char* getBytesString(od_uint64);
148 mGlobal(Basic) const char* getLimitedDisplayString(const char*,int nrchars,
149  bool trimright);
152 mGlobal(Basic) int getIndexInStringArrCI(const char*,const char* const* arr,
153  int startnr=0,int nr_chars_to_match=0,
154  int notfoundidx=-1);
157 mGlobal(Basic) int getIndexInStringArrCI(const char*,const BufferStringSet set,
158  int startnr=0,int nr_chars_to_match=0,
159  int notfoundidx=-1);
162 mGlobal(Basic) const char* getAreaString(float m2,bool parensonunit,
163  char* str=0);
164 mGlobal(Basic) const char* getAreaString(float m2,bool xyinfeet,int precision,
165  bool parensonunit,char* str=0);
169 mGlobal(Basic) char* truncateString(char* str, int maxlen );
174 #endif
int toInt(const char *s, int defval=0)
Definition: string2.h:73
bool getFromString(int &, const char *, int udfval)
float toFloat(const char *s, float defval=0)
Definition: string2.h:67
bool isNumberString(const char *, bool int_only=false)
#define mGlobal(module)
Definition: commondefs.h:163
#define od_int64
Definition: plftypes.h:36
int64_t toInt64(const char *s, int64_t defval=0)
Definition: string2.h:76
const char * getNextWord(const char *, char *)
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:29
const char * getRankPostFix(int)
double toDouble(const char *s, double defval=0)
Definition: string2.h:70
Set of BufferString objects.
Definition: bufstringset.h:28
bool isAlphaNumString(const char *, bool allowspace=false)
bool stringEndsWithCI(const char *, const char *)
bool stringStartsWithCI(const char *, const char *)
bool yesNoFromString(const char *)
bool caseInsensitiveEqual(const char *, const char *, int match_nrchars=-1)
#define od_uint32
Definition: plftypes.h:32
void cleanupString(char *, bool, bool, bool)
const char * getBytesString(uint64_t)
const char * getLimitedDisplayString(const char *, int nrchars, bool trimright)
void removeTrailingBlanks(char *)
char * truncateString(char *str, int maxlen)
const char * getVelUnitString(bool isfeet, bool withparentheses)
#define od_uint64
Definition: plftypes.h:37
const char * getDistUnitString(bool isfeet, bool withparentheses)
const char * getYesNoString(bool)
#define od_int32
Definition: plftypes.h:31
const char * toStringLim(float, int maxtxtwdth)
const char * getAreaString(float m2, bool parensonunit, char *str=0)
Concatenated short keys separated by dots. Used for Object identifiers in the Object Manager...
Definition: compoundkey.h:23
OpendTect.
Definition: commontypes.h:29
const char * lastOcc(const char *, char)
const char * firstOcc(const char *, char)
bool stringEndsWith(const char *endstring, const char *maybebigger)
const char * toStringPrecise(float)
Export_Basic const char * toString(PythonSource)
bool stringStartsWith(const char *startstring, const char *maybebigger)
int getIndexInStringArrCI(const char *, const char *const *arr, int startnr=0, int nr_chars_to_match=0, int notfoundidx=-1)
bool toBool(const char *s, bool defval=true)
Definition: string2.h:64

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019