CernVM-FS  2.12.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 #include "util/export.h"
17 
18 const int kTrimNone = 0;
19 const int kTrimLeading = 1 << 0;
20 const int kTrimTrailing = 1 << 1;
22 
23 #ifdef CVMFS_NAMESPACE_GUARD
24 namespace CVMFS_NAMESPACE_GUARD {
25 #endif
26 
27 CVMFS_EXPORT std::string StringifyBool(const bool value);
28 CVMFS_EXPORT std::string StringifyInt(const int64_t value);
29 CVMFS_EXPORT std::string StringifyUint(const uint64_t value);
30 CVMFS_EXPORT std::string StringifyByteAsHex(const unsigned char value);
31 CVMFS_EXPORT std::string StringifyDouble(const double value);
32 CVMFS_EXPORT std::string StringifyTime(const time_t seconds, const bool utc);
33 CVMFS_EXPORT std::string StringifyLocalTime(const time_t seconds);
34 CVMFS_EXPORT std::string StringifyTimeval(const timeval value);
35 CVMFS_EXPORT std::string RfcTimestamp();
36 CVMFS_EXPORT std::string IsoTimestamp();
37 CVMFS_EXPORT std::string WhitelistTimestamp(time_t when);
38 CVMFS_EXPORT time_t IsoTimestamp2UtcTime(const std::string &iso8601);
39 CVMFS_EXPORT int64_t String2Int64(const std::string &value);
40 CVMFS_EXPORT uint64_t String2Uint64(const std::string &value);
41 CVMFS_EXPORT bool String2Uint64Parse(const std::string &value,
42  uint64_t *result);
43 
44 CVMFS_EXPORT void String2Uint64Pair(const std::string &value,
45  uint64_t *a, uint64_t *b);
46 CVMFS_EXPORT bool HasPrefix(const std::string &str, const std::string &prefix,
47  const bool ignore_case);
48 CVMFS_EXPORT bool HasSuffix(const std::string &str, const std::string &suffix,
49  const bool ignore_case);
50 
51 CVMFS_EXPORT std::vector<std::string> SplitStringBounded(
52  unsigned max_chunks, const std::string &str, char delim);
53 CVMFS_EXPORT std::vector<std::string> SplitString(const std::string &str,
54  char delim);
55 
56 CVMFS_EXPORT std::string JoinStrings(const std::vector<std::string> &strings,
57  const std::string &joint);
58 CVMFS_EXPORT void ParseKeyvalMem(const unsigned char *buffer,
59  const unsigned buffer_size,
60  std::map<char, std::string> *content);
61 CVMFS_EXPORT bool ParseKeyvalPath(const std::string &filename,
62  std::map<char, std::string> *content);
63 
64 CVMFS_EXPORT std::string GetLineMem(const char *text, const int text_size);
65 CVMFS_EXPORT bool GetLineFile(FILE *f, std::string *line);
66 CVMFS_EXPORT bool GetLineFd(const int fd, std::string *line);
67 CVMFS_EXPORT std::string Trim(const std::string &raw,
68  bool trim_newline = false);
69 CVMFS_EXPORT std::string TrimString(const std::string& path,
70  const std::string& toTrim,
71  const int trimMode = kTrimAll);
72 
73 CVMFS_EXPORT std::string ToUpper(const std::string &mixed_case);
74 CVMFS_EXPORT std::string ReplaceAll(const std::string &haystack,
75  const std::string &needle,
76  const std::string &replace_by);
77 CVMFS_EXPORT std::string Tail(const std::string &source, unsigned num_lines);
78 
79 CVMFS_EXPORT std::string Base64(const std::string &data);
80 CVMFS_EXPORT std::string Base64Url(const std::string &data);
81 CVMFS_EXPORT bool Debase64(const std::string &data, std::string *decoded);
82 CVMFS_EXPORT std::string GetGMTimestamp(
83  const std::string &format = "%Y-%m-%d %H:%M:%S");
84 
85 #ifdef CVMFS_NAMESPACE_GUARD
86 } // namespace CVMFS_NAMESPACE_GUARD
87 #endif
88 
89 #endif // CVMFS_UTIL_STRING_H_
string GetLineMem(const char *text, const int text_size)
Definition: string.cc:398
std::string GetGMTimestamp(const std::string &format)
Definition: string.cc:633
string StringifyLocalTime(const time_t seconds)
Definition: string.cc:126
std::string IsoTimestamp()
Definition: string.cc:167
string Trim(const string &raw, bool trim_newline)
Definition: string.cc:446
string ReplaceAll(const string &haystack, const string &needle, const string &replace_by)
Definition: string.cc:502
string JoinStrings(const vector< string > &strings, const string &joint)
Definition: string.cc:343
const int kTrimLeading
Definition: string.h:19
string Tail(const string &source, unsigned num_lines)
Definition: string.cc:610
#define CVMFS_EXPORT
Definition: export.h:11
const int kTrimTrailing
Definition: string.h:20
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:582
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:263
string Base64Url(const string &data)
Definition: string.cc:553
std::string RfcTimestamp()
Definition: string.cc:145
int64_t String2Int64(const string &value)
Definition: string.cc:240
bool GetLineFile(FILE *f, std::string *line)
Definition: string.cc:404
string ToUpper(const string &mixed_case)
Definition: string.cc:494
vector< string > SplitString(const string &str, char delim)
Definition: string.cc:308
bool HasSuffix(const std::string &str, const std::string &suffix, const bool ignore_case)
Definition: string.cc:299
std::string WhitelistTimestamp(time_t when)
Definition: string.cc:187
const int kTrimAll
Definition: string.h:21
vector< string > SplitStringBounded(unsigned max_chunks, const string &str, char delim)
Definition: string.cc:312
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:285
const int const char * format
Definition: logging.h:23
time_t IsoTimestamp2UtcTime(const std::string &iso8601)
Definition: string.cc:216
bool GetLineFd(const int fd, std::string *line)
Definition: string.cc:422
string Base64(const string &data)
Definition: string.cc:522
uint64_t String2Uint64(const string &value)
Definition: string.cc:246
bool ParseKeyvalPath(const string &filename, map< char, string > *content)
Definition: string.cc:384
std::string TrimString(const std::string &path, const std::string &toTrim, const int trimMode)
Definition: string.cc:468
const int kTrimNone
Definition: string.h:18
string StringifyTimeval(const timeval value)
Definition: string.cc:203
void ParseKeyvalMem(const unsigned char *buffer, const unsigned buffer_size, map< char, string > *content)
Definition: string.cc:355
void String2Uint64Pair(const string &value, uint64_t *a, uint64_t *b)
Definition: string.cc:281