Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:32

0001 // -*- C++ -*-
0002 //
0003 // StringUtils.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef ThePEG_StringUtils_H
0010 #define ThePEG_StringUtils_H
0011 // This is the declaration of the StringUtils class.
0012 
0013 #include "ThePEG/Config/ThePEG.h"
0014 
0015 namespace ThePEG {
0016 
0017 /**
0018  * The StringUtils class contains a few static utility functions for
0019  * basic strings.
0020  */
0021 class StringUtils {
0022 
0023 public:
0024 
0025   /**
0026    * A vector of strings.
0027    */
0028   typedef vector<string> StringVector;
0029 
0030   /**
0031    * Return a vector of string containing the substrings of s, defined
0032    * by the separating characters in ws (the ws characters are not
0033    * included in the substrings.
0034    */
0035   static StringVector split(string s, string ws = " \t\r\n");
0036 
0037   /**
0038    * Return the first substring of s, defined by the separating
0039    * characters in ws (the ws characters are not included in the
0040    * substrings.
0041    */
0042   static string car(string s, string ws = " \t\r\n");
0043 
0044   /**
0045    * Return s after removing the first substring, defined by the
0046    * separating characters in ws (the ws characters are not included
0047    * in the substrings.
0048    */
0049   static string cdr(string s, string ws = " \t\r\n");
0050 
0051   /**
0052    * Return the string \a str stripped from leading and trailing white
0053    * space.
0054    */
0055   static string stripws(string str);
0056 
0057   /**
0058    * Return the directory path part (excluding the trailing slash) of
0059    * the given filename, or an empty string if no directory path is
0060    * included
0061    */
0062   static string dirname(string file);
0063 
0064   /**
0065    * Return the base name of the given filename, removing the
0066    * directory path if present.
0067    */
0068   static string basename(string file);
0069 
0070   /**
0071    * Remove the trailing suffix from the given filename.
0072    */
0073   static string remsuf(string file);
0074 
0075   /**
0076    * Return the trailing suffix (without the dot) of the given
0077    * filename.
0078    */
0079   static string suffix(string file);
0080 
0081   /**
0082    * Assuming the \a line contains a valid XML \a tag, scan the \a
0083    * line for attributes belonging to this \a tag and return a map of
0084    * name-value pairs. Oprionally only look from position \a curr in
0085    * the \a line.
0086    */
0087   static map<string,string> xmlAttributes(string tag, string line,
0088                        string::size_type curr = 0);
0089 
0090   /**
0091    * Try to return a human-readable class name given a type_info
0092    * object. Currently only works for simple classes compiled by g++.
0093    */
0094   static string typeName(const type_info & t);
0095 
0096   /**
0097    * Replace all occurences of the substring 'from' with the substring
0098    * 'to' in the string 'original' and return the new string
0099    */
0100   static string replace(string original, string from, string to);
0101 
0102   /**
0103    * Convenient typdef.
0104    */
0105   typedef string::size_type pos_t;
0106 
0107   /**
0108    * Convenient alias for npos.
0109    */
0110   static const pos_t end = string::npos;
0111   
0112 
0113 };
0114 
0115 }
0116 
0117 #endif /* ThePEG_StringUtils_H */