blob: b08093960ded6e107bd2f67e558a58c87d071d2c [file] [log] [blame]
Jooyung Han205e2822023-12-19 16:59:39 +09001/*
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#pragma once
18
19#include <string>
20#include <string_view>
21
22#include <android-base/strings.h>
23
24namespace android {
25
26#ifndef VENDORSERVICEMANAGER
27
28struct NativeName {
29 std::string package;
30 std::string instance;
31
32 // Parse {package}/{instance}
33 static bool fill(std::string_view name, NativeName* nname) {
34 size_t slash = name.find('/');
35 if (slash == std::string_view::npos) {
36 return false;
37 }
38 // no extra slashes
39 if (name.find('/', slash + 1) != std::string_view::npos) {
40 return false;
41 }
42 // every part should be non-empty
43 if (slash == 0 || slash + 1 == name.size()) {
44 return false;
45 }
46 // no dots in package
47 if (name.rfind('.', slash) != std::string_view::npos) {
48 return false;
49 }
50 nname->package = name.substr(0, slash);
51 nname->instance = name.substr(slash + 1);
52 return true;
53 }
54};
55
56#endif
57
58} // namespace android