github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/model/strings.go (about) 1 // Unless explicitly stated otherwise all files in this repository are licensed 2 // under the Apache License Version 2.0. 3 // This product includes software developed at Datadog (https://www.datadoghq.com/). 4 // Copyright 2016-present Datadog, Inc. 5 6 // Package model holds model related files 7 package model 8 9 import "unicode" 10 11 var ( 12 alphaNumericRange = []*unicode.RangeTable{unicode.L, unicode.Digit} 13 ) 14 15 // IsAlphaNumeric returns whether a character is either a digit or a letter 16 func IsAlphaNumeric(r rune) bool { 17 return unicode.IsOneOf(alphaNumericRange, r) 18 } 19 20 // IsPrintable returns whether the string does contain only unicode printable 21 func IsPrintable(s string) bool { 22 for _, c := range s { 23 if !unicode.IsOneOf(unicode.PrintRanges, c) { 24 return false 25 } 26 } 27 return true 28 } 29 30 // IsPrintableASCII returns whether the string does contain only ASCII char 31 func IsPrintableASCII(s string) bool { 32 for _, c := range s { 33 if (c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && c != '/' && c != ':' && c != '-' && (c < '0' || c > '9') { 34 return false 35 } 36 } 37 return true 38 }