• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2021 The Android Open Source Project
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
15package aidl
16
17import (
18	"strings"
19)
20
21// wrap(p, a, s) = [p + v + s for v in a]
22func wrap(prefix string, strs []string, suffix string) []string {
23	ret := make([]string, len(strs))
24	for i, v := range strs {
25		ret[i] = prefix + v + suffix
26	}
27	return ret
28}
29
30// wrapFunc(p, a, s, f) = [p + f(v) + s for v in a]
31func wrapFunc(prefix string, strs []string, suffix string, f func(string) string) []string {
32	ret := make([]string, len(strs))
33	for i, v := range strs {
34		ret[i] = prefix + f(v) + suffix
35	}
36	return ret
37}
38
39// concat(a...) = sum((i for i in a), [])
40func concat(sstrs ...[]string) []string {
41	var ret []string
42	for _, v := range sstrs {
43		ret = append(ret, v...)
44	}
45	return ret
46}
47
48func fixRustName(name string) string {
49	return strings.Map(func(r rune) rune {
50		switch r {
51		case '-', '.':
52			return '_'
53		default:
54			return r
55		}
56	}, name)
57}
58