source: tags/0.58/wutils.h @ 9

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

willem

File size: 2.1 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>
8#include <list>
9#include <dirent.h>
10std::vector <std::string> split(std::vector <std::string> &v, const std::string s, const char sep);
11char* str_to_charp(const std::string s);
12
13template <typename T>
14  std::string NumberToString ( T Number )
15  {
16    std::ostringstream ss;
17    ss << Number;
18    return ss.str();
19  }
20template <typename T>
21  std::string NumberToString ( T Number,int w)
22  {
23    std::ostringstream ss;
24    ss <<std::setfill('0') << std::setw(w) << Number;
25    return ss.str();
26  }
27template <typename T>
28  T StringToNumber ( const std::string &Text )
29  {
30    std::istringstream ss(Text);
31    T result;
32    return ss >> result ? result : 0;
33  }
34
35std::string strtohex(const std::string s);
36std::string hextostr(const std::string s);
37const static std::string ZBEGIN_ = "ZZZ";
38const static std::string ZEND_   = "YY";
39
40std::string zstrtohex(const std::string s);
41std::string zhextostr(const std::string s);
42
43std::string gen_random(const int len);
44
45int get_file_contents(std::string &contents,const std::string &filename);
46
47inline std::string trim_right(
48  const std::string& s,
49  const std::string& delimiters = " \f\n\r\t\v" )
50{
51  size_t p = s.find_last_not_of(delimiters);
52  if (p == s.npos)
53    return "";
54  return s.substr( 0, p + 1 );
55}
56
57inline std::string trim_left(
58  const std::string& s,
59  const std::string& delimiters = " \f\n\r\t\v" )
60{
61  size_t p = s.find_first_not_of(delimiters);
62  if (p == s.npos)
63    return "";
64  return s.substr(p);
65}
66
67inline std::string trim(
68  const std::string& s,
69  const std::string& delimiters = " \f\n\r\t\v" )
70{
71  return trim_left( trim_right( s, delimiters ), delimiters );
72}
73
74int mkdir_p(const std::string &s,mode_t m);
75
76std::string envtostr(const std::string &s);
77
78#include <zlib.h>
79
80int get_dir_list(std::list <std::string> &v,
81                 const std::string       &d);
82std::string compress_string(const std::string& str,
83                            int compressionlevel = Z_BEST_COMPRESSION);
84
85std::string decompress_string(const std::string& str);
86#endif
Note: See TracBrowser for help on using the repository browser.