main.go 546 B

12345678910111213141516171819202122
  1. package yu_http
  2. const toLower = 'a' - 'A'
  3. // Normalize
  4. //
  5. // @Description: 标准化协议头
  6. func Normalize(key string) string {
  7. j_buf := make([]byte, 0, len(key))
  8. j_upper := true
  9. for j_i := 0; j_i < len(key); j_i++ {
  10. if j_upper && 'a' <= key[j_i] && key[j_i] <= 'z' {
  11. j_buf = append(j_buf, key[j_i]-toLower)
  12. } else if !j_upper && 'A' <= key[j_i] && key[j_i] <= 'Z' {
  13. j_buf = append(j_buf, key[j_i]+toLower)
  14. } else {
  15. j_buf = append(j_buf, key[j_i])
  16. }
  17. j_upper = key[j_i] == '-' // for next time
  18. }
  19. return string(j_buf)
  20. }