| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef STRING_UTILS_H |
| 17 |
#define STRING_UTILS_H |
| 18 |
|
| 19 |
#include <iomanip> |
| 20 |
#include <iostream> |
| 21 |
#include <ostream> |
| 22 |
#include <sstream> |
| 23 |
#include <string> |
| 24 |
#include <unordered_set> |
| 25 |
|
| 26 |
#include <utils/Log.h> |
| 27 |
|
| 28 |
namespace android { |
| 29 |
namespace uirenderer { |
| 30 |
|
| 31 |
class unordered_string_set : public std::unordered_set<std::string> { |
| 32 |
public: |
| 33 |
bool has(const char* str) { return find(std::string(str)) != end(); } |
| 34 |
}; |
| 35 |
|
| 36 |
class StringUtils { |
| 37 |
public: |
| 38 |
static unordered_string_set split(const char* spacedList); |
| 39 |
}; |
| 40 |
|
| 41 |
struct SizePrinter { |
| 42 |
int bytes; |
| 43 |
friend std::ostream& operator<<(std::ostream& stream, const SizePrinter& d) { |
| 44 |
static const char* SUFFIXES[] = {"B", "KiB", "MiB"}; |
| 45 |
size_t suffix = 0; |
| 46 |
double temp = d.bytes; |
| 47 |
while (temp > 1024 && suffix < 2) { |
| 48 |
temp /= 1024.0; |
| 49 |
suffix++; |
| 50 |
} |
| 51 |
stream << std::fixed << std::setprecision(2) << temp << SUFFIXES[suffix]; |
| 52 |
return stream; |
| 53 |
} |
| 54 |
}; |
| 55 |
|
| 56 |
class LogcatStream : public std::ostream { |
| 57 |
class LogcatStreamBuf : public std::stringbuf { |
| 58 |
virtual int sync() { |
| 59 |
ALOGD("%s", str().c_str()); |
| 60 |
str(""); |
| 61 |
return 0; |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
LogcatStreamBuf buffer; |
| 66 |
|
| 67 |
public: |
| 68 |
LogcatStream() : std::ostream(&buffer) {} |
| 69 |
}; |
| 70 |
|
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
#endif |