Path: blob/main/libshaderc_util/src/version_profile.cc
1560 views
// Copyright 2015 The Shaderc Authors. All rights reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314#include "libshaderc_util/version_profile.h"1516#include <cctype>17#include <sstream>1819namespace {2021const int kVersionNumberLength = 3;22const int kMaxProfileLength = 13; // strlen(compatibility)23const int kMaxVersionProfileLength = kVersionNumberLength + kMaxProfileLength;24const int kMinVersionProfileLength = kVersionNumberLength;2526} // anonymous namespace2728namespace shaderc_util {2930bool ParseVersionProfile(const std::string& version_profile, int* version,31EProfile* profile) {32if (version_profile.size() < kMinVersionProfileLength ||33version_profile.size() > kMaxVersionProfileLength ||34!::isdigit(version_profile.front()))35return false;3637std::string profile_string;38std::istringstream(version_profile) >> *version >> profile_string;3940if (!IsKnownVersion(*version)) {41return false;42}43if (profile_string.empty()) {44*profile = ENoProfile;45} else if (profile_string == "core") {46*profile = ECoreProfile;47} else if (profile_string == "es") {48*profile = EEsProfile;49} else if (profile_string == "compatibility") {50*profile = ECompatibilityProfile;51} else {52return false;53}5455return true;56}5758} // namespace shaderc_util596061