source: tags/0.55/wutils.h @ 9

Last change on this file since 9 was 9, checked in by willem, 11 years ago

willem

File size: 1.8 KB
Line 
1#ifndef WUTILS_H
2#define WUTILS_H
3#include <vector>
4#include <string>
5#include <sstream>
6#include <iomanip>
7#include <sys/types.h>
8std::vector <std::string> split(std::vector <std::string> &v, const std::string s, const char sep);
9char* str_to_charp(const std::string s);
10
11template <typename T>
12  std::string NumberToString ( T Number )
13  {
14    std::ostringstream ss;
15    ss << Number;
16    return ss.str();
17  }
18template <typename T>
19  std::string NumberToString ( T Number,int w)
20  {
21    std::ostringstream ss;
22    ss <<std::setfill('0') << std::setw(w) << Number;
23    return ss.str();
24  }
25template <typename T>
26  T StringToNumber ( const std::string &Text )
27  {
28    std::istringstream ss(Text);
29    T result;
30    return ss >> result ? result : 0;
31  }
32
33std::string strtohex(const std::string s);
34std::string hextostr(const std::string s);
35const static std::string ZBEGIN_ = "ZZZ";
36const static std::string ZEND_   = "YY";
37
38std::string zstrtohex(const std::string s);
39std::string zhextostr(const std::string s);
40
41std::string gen_random(const int len);
42
43int get_file_contents(std::string &contents,const std::string &filename);
44
45inline std::string trim_right(
46  const std::string& s,
47  const std::string& delimiters = " \f\n\r\t\v" )
48{
49  size_t p = s.find_last_not_of(delimiters);
50  if (p == s.npos)
51    return "";
52  return s.substr( 0, p + 1 );
53}
54
55inline std::string trim_left(
56  const std::string& s,
57  const std::string& delimiters = " \f\n\r\t\v" )
58{
59  size_t p = s.find_first_not_of(delimiters);
60  if (p == s.npos)
61    return "";
62  return s.substr(p);
63}
64
65inline std::string trim(
66  const std::string& s,
67  const std::string& delimiters = " \f\n\r\t\v" )
68{
69  return trim_left( trim_right( s, delimiters ), delimiters );
70}
71
72int mkdir_p(const std::string &s,mode_t m);
73
74std::string envtostr(const std::string &s);
75#endif
Note: See TracBrowser for help on using the repository browser.