]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_string.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rgw / rgw_string.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_RGW_STRING_H
5 #define CEPH_RGW_STRING_H
6
7 #include <stdlib.h>
8 #include <limits.h>
9
10 struct ltstr_nocase
11 {
12 bool operator()(const string& s1, const string& s2) const
13 {
14 return strcasecmp(s1.c_str(), s2.c_str()) < 0;
15 }
16 };
17
18 static inline int stringcasecmp(const string& s1, const string& s2)
19 {
20 return strcasecmp(s1.c_str(), s2.c_str());
21 }
22
23 static inline int stringcasecmp(const string& s1, const char *s2)
24 {
25 return strcasecmp(s1.c_str(), s2);
26 }
27
28 static inline int stringcasecmp(const string& s1, int ofs, int size, const string& s2)
29 {
30 return strncasecmp(s1.c_str() + ofs, s2.c_str(), size);
31 }
32
33 static inline int stringtoll(const string& s, int64_t *val)
34 {
35 char *end;
36
37 long long result = strtoll(s.c_str(), &end, 10);
38 if (result == LLONG_MAX)
39 return -EINVAL;
40
41 if (*end)
42 return -EINVAL;
43
44 *val = (int64_t)result;
45
46 return 0;
47 }
48
49 static inline int stringtoull(const string& s, uint64_t *val)
50 {
51 char *end;
52
53 unsigned long long result = strtoull(s.c_str(), &end, 10);
54 if (result == ULLONG_MAX)
55 return -EINVAL;
56
57 if (*end)
58 return -EINVAL;
59
60 *val = (uint64_t)result;
61
62 return 0;
63 }
64
65 static inline int stringtol(const string& s, int32_t *val)
66 {
67 char *end;
68
69 long result = strtol(s.c_str(), &end, 10);
70 if (result == LONG_MAX)
71 return -EINVAL;
72
73 if (*end)
74 return -EINVAL;
75
76 *val = (int32_t)result;
77
78 return 0;
79 }
80
81 static inline int stringtoul(const string& s, uint32_t *val)
82 {
83 char *end;
84
85 unsigned long result = strtoul(s.c_str(), &end, 10);
86 if (result == ULONG_MAX)
87 return -EINVAL;
88
89 if (*end)
90 return -EINVAL;
91
92 *val = (uint32_t)result;
93
94 return 0;
95 }
96
97 #endif