Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/libshaderc_util/src/args.cc
1560 views
1
// Copyright 2019 The Shaderc Authors. All rights reserved.
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 "libshaderc_util/args.h"
16
17
#include <iomanip>
18
#include <sstream>
19
20
namespace shaderc_util {
21
22
bool GetOptionArgument(int argc, char** argv, int* index,
23
const std::string& option,
24
string_piece* option_argument) {
25
const string_piece arg = argv[*index];
26
assert(arg.starts_with(option));
27
if (arg.size() != option.size()) {
28
*option_argument = arg.substr(option.size());
29
return true;
30
}
31
32
if (option.back() == '=') {
33
*option_argument = "";
34
return true;
35
}
36
37
if (++(*index) >= argc) return false;
38
*option_argument = argv[*index];
39
return true;
40
}
41
42
bool ParseUint32(const std::string& str, uint32_t* value) {
43
std::istringstream iss(str);
44
45
iss >> std::setbase(0);
46
iss >> *value;
47
48
// We should have read something.
49
bool ok = !str.empty() && !iss.bad();
50
// It should have been all the text.
51
ok = ok && iss.eof();
52
// It should have been in range.
53
ok = ok && !iss.fail();
54
55
// Work around a bugs in various C++ standard libraries.
56
// Count any negative number as an error, including "-0".
57
ok = ok && (str[0] != '-');
58
59
return ok;
60
}
61
62
} // namespace shaderc_util
63
64