Chris Craik | 6e6646c | 2015-09-14 15:54:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #ifndef STRING_UTILS_H |
| 17 | #define STRING_UTILS_H |
| 18 | |
| 19 | #include <string> |
| 20 | #include <unordered_set> |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame^] | 21 | #include <ostream> |
| 22 | #include <iomanip> |
Chris Craik | 6e6646c | 2015-09-14 15:54:12 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | namespace uirenderer { |
| 26 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 27 | class unordered_string_set : public std::unordered_set<std::string> { |
Chris Craik | 6e6646c | 2015-09-14 15:54:12 -0700 | [diff] [blame] | 28 | public: |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 29 | bool has(const char* str) { |
| 30 | return find(std::string(str)) != end(); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | class StringUtils { |
| 35 | public: |
| 36 | static unordered_string_set split(const char* spacedList); |
Chris Craik | 6e6646c | 2015-09-14 15:54:12 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame^] | 39 | struct SizePrinter { |
| 40 | int bytes; |
| 41 | friend std::ostream& operator<<(std::ostream& stream, const SizePrinter& d) { |
| 42 | static const char* SUFFIXES[] = {"B", "KiB", "MiB"}; |
| 43 | size_t suffix = 0; |
| 44 | double temp = d.bytes; |
| 45 | while (temp > 1000 && suffix < 2) { |
| 46 | temp /= 1024.0; |
| 47 | suffix++; |
| 48 | } |
| 49 | stream << std::fixed << std::setprecision(2) << temp << SUFFIXES[suffix]; |
| 50 | return stream; |
| 51 | } |
| 52 | }; |
| 53 | |
Chris Craik | 6e6646c | 2015-09-14 15:54:12 -0700 | [diff] [blame] | 54 | } /* namespace uirenderer */ |
| 55 | } /* namespace android */ |
| 56 | |
| 57 | #endif /* GLUTILS_H */ |