File: StringUtils.h

package info (click to toggle)
thepeg 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 9,312 kB
  • ctags: 11,509
  • sloc: cpp: 57,129; sh: 11,315; java: 3,212; lisp: 1,402; makefile: 830; ansic: 58; perl: 3
file content (111 lines) | stat: -rw-r--r-- 2,801 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// -*- C++ -*-
//
// StringUtils.h is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef ThePEG_StringUtils_H
#define ThePEG_StringUtils_H
// This is the declaration of the StringUtils class.

#include "ThePEG/Config/ThePEG.h"

namespace ThePEG {

/**
 * The StringUtils class contains a few static utility functions for
 * basic strings.
 */
class StringUtils {

public:

  /**
   * A vector of strings.
   */
  typedef vector<string> StringVector;

  /**
   * Return a vector of string containing the substrings of s, defined
   * by the separating characters in ws (the ws characters are not
   * included in the substrings.
   */
  static StringVector split(string s, string ws = " \t\r\n");

  /**
   * Return the first substring of s, defined by the separating
   * characters in ws (the ws characters are not included in the
   * substrings.
   */
  static string car(string s, string ws = " \t\r\n");

  /**
   * Return s after removing the first substring, defined by the
   * separating characters in ws (the ws characters are not included
   * in the substrings.
   */
  static string cdr(string s, string ws = " \t\r\n");

  /**
   * Return the string \a str stripped from leading and trailing white
   * space.
   */
  static string stripws(string str);

  /**
   * Return the directory path part (excluding the trailing slash) of
   * the given filename, or an empty string if no directory path is
   * included
   */
  static string dirname(string file);

  /**
   * Return the base name of the given filename, removing the
   * directory path if present.
   */
  static string basename(string file);

  /**
   * Remove the trailing suffix from the given filename.
   */
  static string remsuf(string file);

  /**
   * Return the trailing suffix (without the dot) of the given
   * filename.
   */
  static string suffix(string file);

  /**
   * Assuming the \a line contains a valid XML \a tag, scan the \a
   * line for attributes belonging to this \a tag and return a map of
   * name-value pairs. Oprionally only look from position \a curr in
   * the \a line.
   */
  static map<string,string> xmlAttributes(string tag, string line,
				       string::size_type curr = 0);

  /**
   * Try to return a human-readable class name given a type_info
   * object. Currently only works for simple classes compiled by g++.
   */
  static string typeName(const type_info & t);

  /**
   * Convenient typdef.
   */
  typedef string::size_type pos_t;

  /**
   * Convenient alias for npos.
   */
  static const pos_t end = string::npos;
  

};

}

#endif /* ThePEG_StringUtils_H */