本站源代码
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

174 行
4.8KB

  1. package yaml
  2. const (
  3. // The size of the input raw buffer.
  4. input_raw_buffer_size = 512
  5. // The size of the input buffer.
  6. // It should be possible to decode the whole raw buffer.
  7. input_buffer_size = input_raw_buffer_size * 3
  8. // The size of the output buffer.
  9. output_buffer_size = 128
  10. // The size of the output raw buffer.
  11. // It should be possible to encode the whole output buffer.
  12. output_raw_buffer_size = (output_buffer_size*2 + 2)
  13. // The size of other stacks and queues.
  14. initial_stack_size = 16
  15. initial_queue_size = 16
  16. initial_string_size = 16
  17. )
  18. // Check if the character at the specified position is an alphabetical
  19. // character, a digit, '_', or '-'.
  20. func is_alpha(b []byte, i int) bool {
  21. return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'Z' || b[i] >= 'a' && b[i] <= 'z' || b[i] == '_' || b[i] == '-'
  22. }
  23. // Check if the character at the specified position is a digit.
  24. func is_digit(b []byte, i int) bool {
  25. return b[i] >= '0' && b[i] <= '9'
  26. }
  27. // Get the value of a digit.
  28. func as_digit(b []byte, i int) int {
  29. return int(b[i]) - '0'
  30. }
  31. // Check if the character at the specified position is a hex-digit.
  32. func is_hex(b []byte, i int) bool {
  33. return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'F' || b[i] >= 'a' && b[i] <= 'f'
  34. }
  35. // Get the value of a hex-digit.
  36. func as_hex(b []byte, i int) int {
  37. bi := b[i]
  38. if bi >= 'A' && bi <= 'F' {
  39. return int(bi) - 'A' + 10
  40. }
  41. if bi >= 'a' && bi <= 'f' {
  42. return int(bi) - 'a' + 10
  43. }
  44. return int(bi) - '0'
  45. }
  46. // Check if the character is ASCII.
  47. func is_ascii(b []byte, i int) bool {
  48. return b[i] <= 0x7F
  49. }
  50. // Check if the character at the start of the buffer can be printed unescaped.
  51. func is_printable(b []byte, i int) bool {
  52. return ((b[i] == 0x0A) || // . == #x0A
  53. (b[i] >= 0x20 && b[i] <= 0x7E) || // #x20 <= . <= #x7E
  54. (b[i] == 0xC2 && b[i+1] >= 0xA0) || // #0xA0 <= . <= #xD7FF
  55. (b[i] > 0xC2 && b[i] < 0xED) ||
  56. (b[i] == 0xED && b[i+1] < 0xA0) ||
  57. (b[i] == 0xEE) ||
  58. (b[i] == 0xEF && // #xE000 <= . <= #xFFFD
  59. !(b[i+1] == 0xBB && b[i+2] == 0xBF) && // && . != #xFEFF
  60. !(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF))))
  61. }
  62. // Check if the character at the specified position is NUL.
  63. func is_z(b []byte, i int) bool {
  64. return b[i] == 0x00
  65. }
  66. // Check if the beginning of the buffer is a BOM.
  67. func is_bom(b []byte, i int) bool {
  68. return b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF
  69. }
  70. // Check if the character at the specified position is space.
  71. func is_space(b []byte, i int) bool {
  72. return b[i] == ' '
  73. }
  74. // Check if the character at the specified position is tab.
  75. func is_tab(b []byte, i int) bool {
  76. return b[i] == '\t'
  77. }
  78. // Check if the character at the specified position is blank (space or tab).
  79. func is_blank(b []byte, i int) bool {
  80. //return is_space(b, i) || is_tab(b, i)
  81. return b[i] == ' ' || b[i] == '\t'
  82. }
  83. // Check if the character at the specified position is a line break.
  84. func is_break(b []byte, i int) bool {
  85. return (b[i] == '\r' || // CR (#xD)
  86. b[i] == '\n' || // LF (#xA)
  87. b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
  88. b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
  89. b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9) // PS (#x2029)
  90. }
  91. func is_crlf(b []byte, i int) bool {
  92. return b[i] == '\r' && b[i+1] == '\n'
  93. }
  94. // Check if the character is a line break or NUL.
  95. func is_breakz(b []byte, i int) bool {
  96. //return is_break(b, i) || is_z(b, i)
  97. return ( // is_break:
  98. b[i] == '\r' || // CR (#xD)
  99. b[i] == '\n' || // LF (#xA)
  100. b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
  101. b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
  102. b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029)
  103. // is_z:
  104. b[i] == 0)
  105. }
  106. // Check if the character is a line break, space, or NUL.
  107. func is_spacez(b []byte, i int) bool {
  108. //return is_space(b, i) || is_breakz(b, i)
  109. return ( // is_space:
  110. b[i] == ' ' ||
  111. // is_breakz:
  112. b[i] == '\r' || // CR (#xD)
  113. b[i] == '\n' || // LF (#xA)
  114. b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
  115. b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
  116. b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029)
  117. b[i] == 0)
  118. }
  119. // Check if the character is a line break, space, tab, or NUL.
  120. func is_blankz(b []byte, i int) bool {
  121. //return is_blank(b, i) || is_breakz(b, i)
  122. return ( // is_blank:
  123. b[i] == ' ' || b[i] == '\t' ||
  124. // is_breakz:
  125. b[i] == '\r' || // CR (#xD)
  126. b[i] == '\n' || // LF (#xA)
  127. b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
  128. b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
  129. b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029)
  130. b[i] == 0)
  131. }
  132. // Determine the width of the character.
  133. func width(b byte) int {
  134. // Don't replace these by a switch without first
  135. // confirming that it is being inlined.
  136. if b&0x80 == 0x00 {
  137. return 1
  138. }
  139. if b&0xE0 == 0xC0 {
  140. return 2
  141. }
  142. if b&0xF0 == 0xE0 {
  143. return 3
  144. }
  145. if b&0xF8 == 0xF0 {
  146. return 4
  147. }
  148. return 0
  149. }
上海开阖软件有限公司 沪ICP备12045867号-1