1/* 2Copyright 2015 The Kubernetes Authors. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16// See k8s.io/apimachinery/pkg/util/rand/rand.go 17package chartify 18 19const ( 20 // We omit vowels from the set of available characters to reduce the chances 21 // of "bad words" being formed. 22 alphanums = "bcdfghjklmnpqrstvwxz2456789" 23) 24 25// SafeEncodeString encodes s using the same characters as rand.String. This reduces the chances of bad words and 26// ensures that strings generated from hash functions appear consistent throughout the API. 27func SafeEncodeString(s string) string { 28 r := make([]byte, len(s)) 29 for i, b := range []rune(s) { 30 r[i] = alphanums[(int(b) % len(alphanums))] 31 } 32 return string(r) 33} 34