1 /*
2  * Copyright (C) 2023 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 
17 #ifndef SHELL_AS_STRING_UTILS_H_
18 #define SHELL_AS_STRING_UTILS_H_
19 
20 #include <unistd.h>
21 
22 #include <vector>
23 
24 namespace shell_as {
25 
26 // Parses a string into an unsigned 32bit int value. Returns true on success and
27 // false otherwise.
28 bool StringToUInt32(const char* s, uint32_t* i);
29 
30 // Parses a string into a unsigned 64bit int value. Returns true on success and
31 // false otherwise.
32 bool StringToUInt64(const char* s, uint64_t* i);
33 
34 // Splits a line of uid_t/guid_t values by a given separator and returns the
35 // integer values in a vector.
36 //
37 // The separators string may contain multiple characters and is treated as a set
38 // of possible separating characters.
39 //
40 // If num_to_skip is non-zero, then that many entries will be skipped after
41 // splitting the line and before parsing the values as integers. This is useful
42 // if the line has a prefix such as "Gid: 1 2 3 4".
43 //
44 // Returns true on success and false otherwise.
45 bool SplitIdsAndSkip(char* line, const char* separators, int num_to_skip,
46                      std::vector<uid_t>* ids);
47 
48 }  // namespace shell_as
49 
50 #endif  // SHELL_AS_STRING_UTILS_H_
51