16e6646c03788f198a9878763680c05342d7622f3Chris Craik/* 26e6646c03788f198a9878763680c05342d7622f3Chris Craik * Copyright (C) 2015 The Android Open Source Project 36e6646c03788f198a9878763680c05342d7622f3Chris Craik * 46e6646c03788f198a9878763680c05342d7622f3Chris Craik * Licensed under the Apache License, Version 2.0 (the "License"); 56e6646c03788f198a9878763680c05342d7622f3Chris Craik * you may not use this file except in compliance with the License. 66e6646c03788f198a9878763680c05342d7622f3Chris Craik * You may obtain a copy of the License at 76e6646c03788f198a9878763680c05342d7622f3Chris Craik * 86e6646c03788f198a9878763680c05342d7622f3Chris Craik * http://www.apache.org/licenses/LICENSE-2.0 96e6646c03788f198a9878763680c05342d7622f3Chris Craik * 106e6646c03788f198a9878763680c05342d7622f3Chris Craik * Unless required by applicable law or agreed to in writing, software 116e6646c03788f198a9878763680c05342d7622f3Chris Craik * distributed under the License is distributed on an "AS IS" BASIS, 126e6646c03788f198a9878763680c05342d7622f3Chris Craik * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136e6646c03788f198a9878763680c05342d7622f3Chris Craik * See the License for the specific language governing permissions and 146e6646c03788f198a9878763680c05342d7622f3Chris Craik * limitations under the License. 156e6646c03788f198a9878763680c05342d7622f3Chris Craik */ 166e6646c03788f198a9878763680c05342d7622f3Chris Craik#ifndef STRING_UTILS_H 176e6646c03788f198a9878763680c05342d7622f3Chris Craik#define STRING_UTILS_H 186e6646c03788f198a9878763680c05342d7622f3Chris Craik 196e6646c03788f198a9878763680c05342d7622f3Chris Craik#include <string> 206e6646c03788f198a9878763680c05342d7622f3Chris Craik#include <unordered_set> 2138e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck#include <ostream> 2238e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck#include <iomanip> 236e6646c03788f198a9878763680c05342d7622f3Chris Craik 246e6646c03788f198a9878763680c05342d7622f3Chris Craiknamespace android { 256e6646c03788f198a9878763680c05342d7622f3Chris Craiknamespace uirenderer { 266e6646c03788f198a9878763680c05342d7622f3Chris Craik 27704bed0da7cc75d0c517d425445de70ceb58060bJohn Reckclass unordered_string_set : public std::unordered_set<std::string> { 286e6646c03788f198a9878763680c05342d7622f3Chris Craikpublic: 29704bed0da7cc75d0c517d425445de70ceb58060bJohn Reck bool has(const char* str) { 30704bed0da7cc75d0c517d425445de70ceb58060bJohn Reck return find(std::string(str)) != end(); 31704bed0da7cc75d0c517d425445de70ceb58060bJohn Reck } 32704bed0da7cc75d0c517d425445de70ceb58060bJohn Reck}; 33704bed0da7cc75d0c517d425445de70ceb58060bJohn Reck 34704bed0da7cc75d0c517d425445de70ceb58060bJohn Reckclass StringUtils { 35704bed0da7cc75d0c517d425445de70ceb58060bJohn Reckpublic: 36704bed0da7cc75d0c517d425445de70ceb58060bJohn Reck static unordered_string_set split(const char* spacedList); 376e6646c03788f198a9878763680c05342d7622f3Chris Craik}; 386e6646c03788f198a9878763680c05342d7622f3Chris Craik 3938e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reckstruct SizePrinter { 4038e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck int bytes; 4138e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck friend std::ostream& operator<<(std::ostream& stream, const SizePrinter& d) { 4238e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck static const char* SUFFIXES[] = {"B", "KiB", "MiB"}; 4338e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck size_t suffix = 0; 4438e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck double temp = d.bytes; 4591eff22b5d7f8fe551bae01331948858ce932a96Chris Craik while (temp > 1024 && suffix < 2) { 4638e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck temp /= 1024.0; 4738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck suffix++; 4838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck } 4938e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck stream << std::fixed << std::setprecision(2) << temp << SUFFIXES[suffix]; 5038e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck return stream; 5138e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck } 5238e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck}; 5338e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck 546e6646c03788f198a9878763680c05342d7622f3Chris Craik} /* namespace uirenderer */ 556e6646c03788f198a9878763680c05342d7622f3Chris Craik} /* namespace android */ 566e6646c03788f198a9878763680c05342d7622f3Chris Craik 576e6646c03788f198a9878763680c05342d7622f3Chris Craik#endif /* GLUTILS_H */ 58