ascii.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2015 Garrett D'Amore
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use 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. package encoding
  15. import (
  16. "golang.org/x/text/encoding"
  17. )
  18. // ASCII represents the 7-bit US-ASCII scheme. It decodes directly to
  19. // UTF-8 without change, as all ASCII values are legal UTF-8.
  20. // Unicode values less than 128 (i.e. 7 bits) map 1:1 with ASCII.
  21. // It encodes runes outside of that to 0x1A, the ASCII substitution character.
  22. var ASCII encoding.Encoding
  23. func init() {
  24. amap := make(map[byte]rune)
  25. for i := 128; i <= 255; i++ {
  26. amap[byte(i)] = RuneError
  27. }
  28. cm := &Charmap{Map: amap}
  29. cm.Init()
  30. ASCII = cm
  31. }