-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathmisc.h
56 lines (47 loc) · 1.31 KB
/
misc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef __BASE_MISC_H__
#define __BASE_MISC_H__
#include "inc/basictypes.h"
#include "base/log.h"
#include "base/format.h"
#if defined(LOGGING) && !defined(LABELS)
#define LABELS
#endif
namespace base {
struct Label {
int index;
const char *label;
};
class Labels {
public:
Labels(const Label *alabel) {
alabel_ = alabel;
}
const char *Find(int index) const {
for (const Label *label = alabel_; label->label != NULL; label++) {
if (label->index == index) {
return label->label;
}
}
return Format::ToString("UNKNOWN: %d", index);
}
private:
const Label *alabel_;
};
#ifdef LABELS
#define STARTLABEL(name) const base::Label name ## _labels[] = {
#define LABEL(x) { x, #x },
#define ENDLABEL(name) { 0, 0 } }; const base::Labels name(name ## _labels);
#else // !LABELS
#define STARTLABEL(name) const base::Label name ## _labels[] = {
#define LABEL(x)
#define ENDLABEL(name) { 0, 0 } }; const base::Labels name(name ## _labels);
#endif
class StringEncoder {
public:
static const char *Escape(const char *s, bool quote = false);
static const char *Replace(const char *s, const char *findstr,
const char *replacewith);
static const char *QueryEncode(const char *s);
};
} // namespace base
#endif // __BASE_MISC_H__