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 #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 StringifyTimeval(const timeval value);
34 CVMFS_EXPORT std::string RfcTimestamp();
35 CVMFS_EXPORT std::string IsoTimestamp();
36 CVMFS_EXPORT std::string WhitelistTimestamp(time_t when);
37 CVMFS_EXPORT time_t IsoTimestamp2UtcTime(const std::string &iso8601);
38 CVMFS_EXPORT int64_t String2Int64(const std::string &value);
39 CVMFS_EXPORT uint64_t String2Uint64(const std::string &value);
40 CVMFS_EXPORT bool String2Uint64Parse(const std::string &value,
41  uint64_t *result);
42 
43 CVMFS_EXPORT void String2Uint64Pair(const std::string &value,
44  uint64_t *a, uint64_t *b);
45 CVMFS_EXPORT bool HasPrefix(const std::string &str, const std::string &prefix,
46  const bool ignore_case);
47 CVMFS_EXPORT bool HasSuffix(const std::string &str, const std::string &suffix,
48  const bool ignore_case);
49 
50 CVMFS_EXPORT std::vector<std::string> SplitStringBounded(
51  unsigned max_chunks, const std::string &str, char delim);
52 CVMFS_EXPORT std::vector<std::string> SplitString(const std::string &str,
53  char delim);
54 
55 CVMFS_EXPORT std::string JoinStrings(const std::vector<std::string> &strings,
56  const std::string &joint);
57 CVMFS_EXPORT void ParseKeyvalMem(const unsigned char *buffer,
58  const unsigned buffer_size,
59  std::map<char, std::string> *content);
60 CVMFS_EXPORT bool ParseKeyvalPath(const std::string &filename,
61  std::map<char, std::string> *content);
62 
63 CVMFS_EXPORT std::string GetLineMem(const char *text, const int text_size);
64 CVMFS_EXPORT bool GetLineFile(FILE *f, std::string *line);
65 CVMFS_EXPORT bool GetLineFd(const int fd, std::string *line);
66 CVMFS_EXPORT std::string Trim(const std::string &raw,
67  bool trim_newline = false);
68 CVMFS_EXPORT std::string TrimString(const std::string& path,
69  const std::string& toTrim,
70  const int trimMode = kTrimAll);
71 
72 CVMFS_EXPORT std::string ToUpper(const std::string &mixed_case);
73 CVMFS_EXPORT std::string ReplaceAll(const std::string &haystack,
74  const std::string &needle,
75  const std::string &replace_by);
76 CVMFS_EXPORT std::string Tail(const std::string &source, unsigned num_lines);
77 
78 CVMFS_EXPORT std::string Base64(const std::string &data);
79 CVMFS_EXPORT std::string Base64Url(const std::string &data);
80 CVMFS_EXPORT bool Debase64(const std::string &data, std::string *decoded);
81 CVMFS_EXPORT std::string GetGMTimestamp(
82  const std::string &format = "%Y-%m-%d %H:%M:%S");
83 
84 #ifdef CVMFS_NAMESPACE_GUARD
85 } // namespace CVMFS_NAMESPACE_GUARD
86 #endif
87 
88 #endif // CVMFS_UTIL_STRING_H_
string GetLineMem(const char *text, const int text_size)
Definition: string.cc:378
std::string GetGMTimestamp(const std::string &format)
Definition: string.cc:613
std::string IsoTimestamp()
Definition: string.cc:149
string Trim(const string &raw, bool trim_newline)
Definition: string.cc:426
string ReplaceAll(const string &haystack, const string &needle, const string &replace_by)
Definition: string.cc:482
string JoinStrings(const vector< string > &strings, const string &joint)
Definition: string.cc:323
const int kTrimLeading
Definition: string.h:19
string Tail(const string &source, unsigned num_lines)
Definition: string.cc:590
#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:562
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:533
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:384
string ToUpper(const string &mixed_case)
Definition: string.cc:474
vector< string > SplitString(const string &str, char delim)
Definition: string.cc:288
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:21
vector< string > SplitStringBounded(unsigned max_chunks, const string &str, char delim)
Definition: string.cc:292
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:402
string Base64(const string &data)
Definition: string.cc:502
uint64_t String2Uint64(const string &value)
Definition: string.cc:228
bool ParseKeyvalPath(const string &filename, map< char, string > *content)
Definition: string.cc:364
std::string TrimString(const std::string &path, const std::string &toTrim, const int trimMode)
Definition: string.cc:448
const int kTrimNone
Definition: string.h:18
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:335
void String2Uint64Pair(const string &value, uint64_t *a, uint64_t *b)
Definition: string.cc:261