Ryan Harrison | acdc35d | 2021-04-14 14:55:07 +0000 | [diff] [blame] | 1 | // Copyright 2021 The Dawn Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "tests/ToggleParser.h" |
| 16 | |
| 17 | #include <cstring> |
| 18 | #include <sstream> |
| 19 | |
| 20 | ToggleParser::ToggleParser() = default; |
| 21 | ToggleParser::~ToggleParser() = default; |
| 22 | |
| 23 | bool ToggleParser::ParseEnabledToggles(char* arg) { |
| 24 | constexpr const char kEnableTogglesSwitch[] = "--enable-toggles="; |
| 25 | size_t argLen = sizeof(kEnableTogglesSwitch) - 1; |
| 26 | if (strncmp(arg, kEnableTogglesSwitch, argLen) == 0) { |
| 27 | std::string toggle; |
| 28 | std::stringstream toggles(arg + argLen); |
| 29 | while (getline(toggles, toggle, ',')) { |
| 30 | mEnabledToggles.push_back(toggle); |
| 31 | } |
| 32 | return true; |
| 33 | } |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | bool ToggleParser::ParseDisabledToggles(char* arg) { |
| 38 | constexpr const char kDisableTogglesSwitch[] = "--disable-toggles="; |
| 39 | size_t argLDis = sizeof(kDisableTogglesSwitch) - 1; |
| 40 | if (strncmp(arg, kDisableTogglesSwitch, argLDis) == 0) { |
| 41 | std::string toggle; |
| 42 | std::stringstream toggles(arg + argLDis); |
| 43 | while (getline(toggles, toggle, ',')) { |
| 44 | mDisabledToggles.push_back(toggle); |
| 45 | } |
| 46 | return true; |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | const std::vector<std::string>& ToggleParser::GetEnabledToggles() const { |
| 52 | return mEnabledToggles; |
| 53 | } |
| 54 | |
| 55 | const std::vector<std::string>& ToggleParser::GetDisabledToggles() const { |
| 56 | return mDisabledToggles; |
| 57 | } |