ATLAS Offline Software
Macros | Functions
SbStringHelpers.h File Reference
#include <Inventor/SbBasic.h>
#include <stdarg.h>
Include dependency graph for SbStringHelpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SbStringNotFound   (-1)
 

Functions

char * SbSTRDUP (const char *)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
void SbSTRDEL (char *&)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbPList SbStringGetWords (const SbString &, const char *)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbStringConvertToBool (const SbString &, SbBool &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbStringConvertToInt (const SbString &, int &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbStringConvertToFloat (const SbString &, float &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbStringConvertToUnsignedLong (const SbString &, unsigned long &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbStringPrintF (SbString &, int, const char *,...)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbString SbStringPrintF (int, const char *,...)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
int SbStringFind (const SbString &, const SbString &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
int SbStringReverseFind (const SbString &, const SbString &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
void SbStringDelete (SbPList &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbString * SbStringCreateEmpty (int)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbStringIsTTF (const SbString &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbString_isenv (const SbString &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbString_getenv (const SbString &, SbString &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbStringGetenv (SbString &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbBool SbStringReplace (SbString &, const SbString &, const SbString &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 
SbString SbStringSuffix (const SbString &)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// More...
 

Macro Definition Documentation

◆ SbStringNotFound

#define SbStringNotFound   (-1)

Definition at line 38 of file SbStringHelpers.h.

Function Documentation

◆ SbSTRDEL()

void SbSTRDEL ( char *&  )

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 36 of file SbStringHelpers.cxx.

41 {
42  ::free(aString);
43  aString = NULL;
44 }

◆ SbSTRDUP()

char* SbSTRDUP ( const char *  )

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 24 of file SbStringHelpers.cxx.

29 {
30  char* p = (char*)::malloc((unsigned)::strlen(aString)+1);
31  if(p==NULL) return 0;
32  //cppcheck-suppress returnDanglingLifetime
33  return ::strcpy(p,aString);
34 }

◆ SbString_getenv()

SbBool SbString_getenv ( const SbString &  ,
SbString &   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 419 of file SbStringHelpers.cxx.

426 {
427  const char* env = ::getenv(aString.getString());
428  if(env) {
429  aValue = SbString(env);
430  return TRUE;
431  } else {
432  aValue = "";
433  return FALSE;
434  }
435 }

◆ SbString_isenv()

SbBool SbString_isenv ( const SbString &  )

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 409 of file SbStringHelpers.cxx.

414 {
415  const char* env = ::getenv(aString.getString());
416  return (env?TRUE:FALSE);
417 }

◆ SbStringConvertToBool()

SbBool SbStringConvertToBool ( const SbString &  ,
SbBool &   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 133 of file SbStringHelpers.cxx.

139 {
140  if( (aString=="true") || (aString=="TRUE") ||
141  (aString=="yes") || (aString=="YES") ) {
142  aValue = TRUE;
143  return TRUE;
144  } else if( (aString=="false") || (aString=="FALSE") ||
145  (aString=="no") || (aString=="NO") ) {
146  aValue = FALSE;
147  return TRUE;
148  } else {
149  aValue = FALSE;
150  return FALSE;
151  }
152 }

◆ SbStringConvertToFloat()

SbBool SbStringConvertToFloat ( const SbString &  ,
float &   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 172 of file SbStringHelpers.cxx.

178 {
179  const char* string = aString.getString();
180  char* s;
181  double value = ::strtod(string,&s);
182  if(s==string) {
183  aValue = 0;
184  return FALSE;
185  }
186  aValue = (float)value;
187  return TRUE;
188 }

◆ SbStringConvertToInt()

SbBool SbStringConvertToInt ( const SbString &  ,
int &   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 154 of file SbStringHelpers.cxx.

160 {
161  const char* string = aString.getString();
162  char* s;
163  long value = ::strtol(string,&s,10);
164  if(s==string) {
165  aValue = 0L;
166  return FALSE;
167  }
168  aValue = (int)value;
169  return TRUE;
170 }

◆ SbStringConvertToUnsignedLong()

SbBool SbStringConvertToUnsignedLong ( const SbString &  ,
unsigned long &   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 190 of file SbStringHelpers.cxx.

196 {
197  aValue = 0L;
198  if(::sscanf(aString.getString(),"%lx",&aValue)!=1) {
199  if(::sscanf(aString.getString(),"%lu",&aValue)!=1) {
200  aValue = 0L;
201  return FALSE;
202  }
203  }
204  return TRUE;
205 }

◆ SbStringCreateEmpty()

SbString* SbStringCreateEmpty ( int  )

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 292 of file SbStringHelpers.cxx.

297 {
298  if(aLength<=0) aLength = 0;
299  char* string = (char*)::malloc((aLength+1)*sizeof(char));
300  if(string==NULL) return NULL;
301  string[aLength] = '\0';
302  for(int count=0;count<aLength;count++) string[count] = ' ';
303  SbString* sbString = new SbString(string);
304  free(string);
305  return sbString;
306 }

◆ SbStringDelete()

void SbStringDelete ( SbPList &  )

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 122 of file SbStringHelpers.cxx.

127 {
128  int linen = aList.getLength();
129  for(int count=0;count<linen;count++) delete ((SbString*)aList[count]);
130  //aList.Clear();
131 }

◆ SbStringFind()

int SbStringFind ( const SbString &  ,
const SbString &   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 247 of file SbStringHelpers.cxx.

253 {
254  int lsearch = aSearch.getLength();
255  if(lsearch<=0) return SbStringNotFound;
256  int number = aString.getLength();
257  for(int index=0;index<=(number-lsearch);index++) {
258  if(aString.getSubString(index,index+lsearch-1)==aSearch) return index;
259  }
260  return SbStringNotFound;
261 }

◆ SbStringGetenv()

SbBool SbStringGetenv ( SbString &  )

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 358 of file SbStringHelpers.cxx.

364 {
365  std::string a_String(aString.getString());
366  std::string::size_type dollar;
367  while((dollar=a_String.find('$'))!=std::string::npos){
368  std::string::size_type slash = a_String.find('/',dollar+1);
369  std::string::size_type back_slash = a_String.find('\\',dollar+1);
370  std::string::size_type pos = std::string::npos;
371  if(slash!=std::string::npos) {
372  if(back_slash!=std::string::npos) {
373  pos = SbMinimum(slash,back_slash);
374  } else {
375  pos = slash;
376  }
377  } else {
378  if(back_slash!=std::string::npos) {
379  pos = back_slash;
380  } else {
381  pos = std::string::npos;
382  }
383  }
384  std::string env;
385  if(pos==std::string::npos) {
386  env = a_String.substr(dollar+1,a_String.length()-(dollar+1));
387  } else {
388  // abc$xxx/ef
389  // 0 3 7 9
390  env = a_String.substr(dollar+1,pos-(dollar+1));
391  }
392  char* val = ::getenv(env.c_str());
393  if(val) {
394  std::string value = a_String.substr(0,dollar);
395  value += val;
396  if(pos!=std::string::npos)
397  value += a_String.substr(pos,a_String.length()-pos);
398  a_String = value;
399  }
400  if(!val) {
401  aString = SbString(a_String.c_str());
402  return FALSE; // Stop looping if env variable not found.
403  }
404  }
405  aString = SbString(a_String.c_str());
406  return TRUE;
407 }

◆ SbStringGetWords()

SbPList SbStringGetWords ( const SbString &  ,
const char *   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 46 of file SbStringHelpers.cxx.

52 {
53  SbPList list(16);
54 
55  if(aString.getLength()<=0) return list;
56 
57  SbString string = aString;
58 
59  char* token = (char*)string.getString();
60 
61  while(1) {
62  char* pos = ::strstr (token,aLimiter);
63  if(pos!=NULL) {
64  *pos = '\0';
65  if(*token!='\0') {
66  list.append(token);
67  }
68  token = pos + ::strlen(aLimiter);
69  } else {
70  //last word
71  if(*token!='\0') {
72  list.append(token);
73  }
74  break;
75  }
76  }
77 
78  int wordn = list.getLength();
79  char* word;
80  for(int count=0;count<wordn;count++) {
81  word = (char*)list[count];
82  list[count] = new SbString(word);
83  }
84 
85  return list;
86 }

◆ SbStringIsTTF()

SbBool SbStringIsTTF ( const SbString &  )

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 346 of file SbStringHelpers.cxx.

351 {
352  if(aString.getLength()<4) return FALSE;
353  if(aString.getSubString(0,3)!="TTF/") return FALSE;
354  return TRUE;
355 }

◆ SbStringPrintF() [1/2]

SbString SbStringPrintF ( int  ,
const char *  ,
  ... 
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 229 of file SbStringHelpers.cxx.

236 {
237  va_list args;
238  va_start(args,aFormat);
239  SbString* sbString = SbStringCreateV(aNumber,aFormat,args);
240  va_end(args);
241  if(sbString==NULL) return "";
242  SbString s(*sbString);
243  delete sbString;
244  return s;
245 }

◆ SbStringPrintF() [2/2]

SbBool SbStringPrintF ( SbString &  ,
int  ,
const char *  ,
  ... 
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 207 of file SbStringHelpers.cxx.

215 {
216  va_list args;
217  va_start(args,aFormat);
218  SbString* sbString = SbStringCreateV(aNumber,aFormat,args);
219  va_end(args);
220  if(sbString==NULL) {
221  aString = "";
222  return FALSE;
223  }
224  aString = *sbString;
225  delete sbString;
226  return TRUE;
227 }

◆ SbStringReplace()

SbBool SbStringReplace ( SbString &  ,
const SbString &  ,
const SbString &   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 437 of file SbStringHelpers.cxx.

447 {
448  std::string a_Old(aOld.getString());
449  std::string a_New(aNew.getString());
450  if(a_Old=="") return FALSE;
451  std::string snew;
452  std::string::size_type lold = a_Old.length();
453  bool status = FALSE;
454  std::string stmp(aString.getString());
455  while(true) {
456  std::string::size_type pos = stmp.find(a_Old);
457  if(pos==std::string::npos){
458  snew += stmp;
459  break;
460  } else {
461  snew += stmp.substr(0,pos);
462  snew += a_New;
463  stmp = stmp.substr(pos+lold,stmp.length()-(pos+lold));
464  status = TRUE;
465  }
466  }
467  aString = SbString(snew.c_str());
468  return status;
469 }

◆ SbStringReverseFind()

int SbStringReverseFind ( const SbString &  ,
const SbString &   
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 263 of file SbStringHelpers.cxx.

269 {
270  int lsearch = aSearch.getLength();
271  if(lsearch<=0) return SbStringNotFound;
272  int number = aString.getLength();
273  for(int index=number-lsearch;index>=0;index--) {
274  if(aString.getSubString(index,index+lsearch-1)==aSearch) return index;
275  }
276  return SbStringNotFound;
277 }

◆ SbStringSuffix()

SbString SbStringSuffix ( const SbString &  )

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 279 of file SbStringHelpers.cxx.

284 {
285  int index = SbStringReverseFind(aString,".");
286  if(index==SbStringNotFound) return SbString("");
287  return aString.getSubString(index+1);
288 }
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
SbStringNotFound
#define SbStringNotFound
Definition: SbStringHelpers.h:37
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
index
Definition: index.py:1
xAOD::char
char
Definition: TrigDecision_v1.cxx:38
athena.value
value
Definition: athena.py:124
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
python.Constants.TRUE
bool TRUE
for job options legacy (TODO: get rid of these!) ----------------------—
Definition: Control/AthenaCommon/python/Constants.py:22
TrigInDetValidation_Base.malloc
malloc
Definition: TrigInDetValidation_Base.py:132
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.selection.number
number
Definition: selection.py:20
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.Constants.FALSE
bool FALSE
Definition: Control/AthenaCommon/python/Constants.py:23
DeMoScan.index
string index
Definition: DeMoScan.py:364
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
merge.status
status
Definition: merge.py:17
SbStringReverseFind
int SbStringReverseFind(const SbString &aString, const SbString &aSearch)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbStringHelpers.cxx:263
SbMinimum
#define SbMinimum(a, b)
Definition: SbStringHelpers.cxx:16
python.DataFormatRates.env
env
Definition: DataFormatRates.py:32
readCCLHist.float
float
Definition: readCCLHist.py:83
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80