ascii.go 683 B

12345678910111213141516171819202122232425262728293031323334
  1. package codec
  2. var printableASCII [256]bool
  3. func init() {
  4. for b := 0; b < len(printableASCII); b++ {
  5. if '\x08' < b && b < '\x7f' {
  6. printableASCII[b] = true
  7. }
  8. }
  9. }
  10. // isPrintableASCII returns true if all bytes are printable ASCII
  11. func isPrintableASCII(b []byte) bool {
  12. for _, c := range b {
  13. if !printableASCII[c] {
  14. return false
  15. }
  16. }
  17. return true
  18. }
  19. // hasByte can be used to check if a string has at least one of the provided
  20. // bytes. Note: make sure byteset is long enough to handle the largest byte in
  21. // the string.
  22. func hasByte(data string, byteset []bool) bool {
  23. for i := 0; i < len(data); i++ {
  24. if byteset[data[i]] {
  25. return true
  26. }
  27. }
  28. return false
  29. }