Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

75 řádky
1.8 KiB

  1. // Copyright 2018 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this 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. // +build !go1.7
  15. package spanner
  16. import (
  17. "reflect"
  18. "strconv"
  19. )
  20. func structTagLookup(tag reflect.StructTag, key string) (string, bool) {
  21. // from go1.10.2 implementation of StructTag.Lookup.
  22. for tag != "" {
  23. // Skip leading space.
  24. i := 0
  25. for i < len(tag) && tag[i] == ' ' {
  26. i++
  27. }
  28. tag = tag[i:]
  29. if tag == "" {
  30. break
  31. }
  32. // Scan to colon. A space, a quote or a control character is a syntax error.
  33. // Strictly speaking, control chars include the range [0x7f, 0x9f], not just
  34. // [0x00, 0x1f], but in practice, we ignore the multi-byte control characters
  35. // as it is simpler to inspect the tag's bytes than the tag's runes.
  36. i = 0
  37. for i < len(tag) && tag[i] > ' ' && tag[i] != ':' && tag[i] != '"' && tag[i] != 0x7f {
  38. i++
  39. }
  40. if i == 0 || i+1 >= len(tag) || tag[i] != ':' || tag[i+1] != '"' {
  41. break
  42. }
  43. name := string(tag[:i])
  44. tag = tag[i+1:]
  45. // Scan quoted string to find value.
  46. i = 1
  47. for i < len(tag) && tag[i] != '"' {
  48. if tag[i] == '\\' {
  49. i++
  50. }
  51. i++
  52. }
  53. if i >= len(tag) {
  54. break
  55. }
  56. qvalue := string(tag[:i+1])
  57. tag = tag[i+1:]
  58. if key == name {
  59. value, err := strconv.Unquote(qvalue)
  60. if err != nil {
  61. break
  62. }
  63. return value, true
  64. }
  65. }
  66. return "", false
  67. }