CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
string.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_UTIL_STRING_H_
6 #define CVMFS_UTIL_STRING_H_
7 
8 #include <stdint.h>
9 #include <sys/time.h>
10 
11 #include <cstdio>
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 const int kTrimNone = 0;
17 const int kTrimLeading = 1 << 0;
18 const int kTrimTrailing = 1 << 1;
20 
21 #ifdef CVMFS_NAMESPACE_GUARD
22 namespace CVMFS_NAMESPACE_GUARD {
23 #endif
24 
25 std::string StringifyBool(const bool value);
26 std::string StringifyInt(const int64_t value);
27 std::string StringifyUint(const uint64_t value);
28 std::string StringifyByteAsHex(const unsigned char value);
29 std::string StringifyDouble(const double value);
30 std::string StringifyTime(const time_t seconds, const bool utc);
31 std::string StringifyTimeval(const timeval value);
32 std::string RfcTimestamp();
33 std::string IsoTimestamp();
34 std::string WhitelistTimestamp(time_t when);
35 time_t IsoTimestamp2UtcTime(const std::string &iso8601);
36 int64_t String2Int64(const std::string &value);
37 uint64_t String2Uint64(const std::string &value);
38 bool String2Uint64Parse(const std::string &value, uint64_t *result);
39 
40 void String2Uint64Pair(const std::string &value, uint64_t *a, uint64_t *b);
41 bool HasPrefix(const std::string &str, const std::string &prefix,
42  const bool ignore_case);
43 bool HasSuffix(const std::string &str, const std::string &suffix,
44  const bool ignore_case);
45 
46 std::vector<std::string> SplitString(const std::string &str, const char delim,
47  const unsigned max_chunks = 0);
48 std::string JoinStrings(const std::vector<std::string> &strings,
49  const std::string &joint);
50 void ParseKeyvalMem(const unsigned char *buffer, const unsigned buffer_size,
51  std::map<char, std::string> *content);
52 bool ParseKeyvalPath(const std::string &filename,
53  std::map<char, std::string> *content);
54 
55 std::string GetLineMem(const char *text, const int text_size);
56 bool GetLineFile(FILE *f, std::string *line);
57 bool GetLineFd(const int fd, std::string *line);
58 std::string Trim(const std::string &raw, bool trim_newline = false);
59 std::string TrimString(const std::string& path,
60  const std::string& toTrim,
61  const int trimMode = kTrimAll);
62 
63 std::string ToUpper(const std::string &mixed_case);
64 std::string ReplaceAll(const std::string &haystack, const std::string &needle,
65  const std::string &replace_by);
66 std::string Tail(const std::string &source, unsigned num_lines);
67 
68 std::string Base64(const std::string &data);
69 std::string Base64Url(const std::string &data);
70 bool Debase64(const std::string &data, std::string *decoded);
71 std::string GetGMTimestamp(const std::string &format = "%Y-%m-%d %H:%M:%S");
72 
73 
74 #ifdef CVMFS_NAMESPACE_GUARD
75 } // namespace CVMFS_NAMESPACE_GUARD
76 #endif
77 
78 #endif // CVMFS_UTIL_STRING_H_
string GetLineMem(const char *text, const int text_size)
Definition: string.cc:373
std::string GetGMTimestamp(const std::string &format)
Definition: string.cc:608
vector< string > SplitString(const string &str, const char delim, const unsigned max_chunks)
Definition: string.cc:288
std::string IsoTimestamp()
Definition: string.cc:149
string Trim(const string &raw, bool trim_newline)
Definition: string.cc:421
string ReplaceAll(const string &haystack, const string &needle, const string &replace_by)
Definition: string.cc:477
string JoinStrings(const vector< string > &strings, const string &joint)
Definition: string.cc:318
const int kTrimLeading
Definition: string.h:17
string Tail(const string &source, unsigned num_lines)
Definition: string.cc:585
const int kTrimTrailing
Definition: string.h:18
string StringifyTime(const time_t seconds, const bool utc)
Definition: string.cc:105
string StringifyDouble(const double value)
Definition: string.cc:96
std::string StringifyUint(const uint64_t value)
Definition: string.cc:84
bool Debase64(const string &data, string *decoded)
Definition: string.cc:557
string StringifyByteAsHex(const unsigned char value)
Definition: string.cc:90
string StringifyBool(const bool value)
Definition: string.cc:76
bool String2Uint64Parse(const std::string &value, uint64_t *result)
Definition: string.cc:243
string Base64Url(const string &data)
Definition: string.cc:528
std::string RfcTimestamp()
Definition: string.cc:127
int64_t String2Int64(const string &value)
Definition: string.cc:222
bool GetLineFile(FILE *f, std::string *line)
Definition: string.cc:379
string ToUpper(const string &mixed_case)
Definition: string.cc:469
bool HasSuffix(const std::string &str, const std::string &suffix, const bool ignore_case)
Definition: string.cc:279
std::string WhitelistTimestamp(time_t when)
Definition: string.cc:169
const int kTrimAll
Definition: string.h:19
string StringifyInt(const int64_t value)
Definition: string.cc:78
bool HasPrefix(const string &str, const string &prefix, const bool ignore_case)
Definition: string.cc:265
time_t IsoTimestamp2UtcTime(const std::string &iso8601)
Definition: string.cc:198
bool GetLineFd(const int fd, std::string *line)
Definition: string.cc:397
string Base64(const string &data)
Definition: string.cc:497
uint64_t String2Uint64(const string &value)
Definition: string.cc:228
bool ParseKeyvalPath(const string &filename, map< char, string > *content)
Definition: string.cc:359
std::string TrimString(const std::string &path, const std::string &toTrim, const int trimMode)
Definition: string.cc:443
const int kTrimNone
Definition: string.h:16
string StringifyTimeval(const timeval value)
Definition: string.cc:185
void ParseKeyvalMem(const unsigned char *buffer, const unsigned buffer_size, map< char, string > *content)
Definition: string.cc:330
void String2Uint64Pair(const string &value, uint64_t *a, uint64_t *b)
Definition: string.cc:261