PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/alibaba/fastjson/parser/CharTypes.java

https://bitbucket.org/xiejuntao/xdesktop
Java | 132 lines | 105 code | 9 blank | 18 comment | 22 complexity | b76cbbe8c7cf21527f779007dcd7687d MD5 | raw file
  1. /*
  2. * Copyright 1999-2101 Alibaba Group.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.alibaba.fastjson.parser;
  17. /**
  18. * @author wenshao<szujobs@hotmail.com>
  19. */
  20. public final class CharTypes {
  21. public final static char[] digits = {
  22. '0' , '1' , '2' , '3' , '4' , '5' ,
  23. '6' , '7' , '8' , '9' , 'A' , 'B' ,
  24. 'C' , 'D' , 'E' , 'F'
  25. };
  26. public final static boolean[] firstIdentifierFlags = new boolean[256];
  27. static {
  28. for (char c = 0; c < firstIdentifierFlags.length; ++c) {
  29. if (c >= 'A' && c <= 'Z') {
  30. firstIdentifierFlags[c] = true;
  31. } else if (c >= 'a' && c <= 'z') {
  32. firstIdentifierFlags[c] = true;
  33. } else if (c == '_') {
  34. firstIdentifierFlags[c] = true;
  35. }
  36. }
  37. }
  38. public final static boolean[] identifierFlags = new boolean[256];
  39. static {
  40. for (char c = 0; c < identifierFlags.length; ++c) {
  41. if (c >= 'A' && c <= 'Z') {
  42. identifierFlags[c] = true;
  43. } else if (c >= 'a' && c <= 'z') {
  44. identifierFlags[c] = true;
  45. } else if (c == '_') {
  46. identifierFlags[c] = true;
  47. } else if (c >= '0' && c <= '9') {
  48. identifierFlags[c] = true;
  49. }
  50. }
  51. }
  52. public final static boolean[] specicalFlags_doubleQuotes = new boolean[128];
  53. public final static boolean[] specicalFlags_singleQuotes = new boolean[128];
  54. public static boolean isSpecial_doubleQuotes(char ch) {
  55. return ch < specicalFlags_doubleQuotes.length && specicalFlags_doubleQuotes[ch];
  56. }
  57. public final static char[] replaceChars = new char[128];
  58. static {
  59. specicalFlags_doubleQuotes['\b'] = true;
  60. specicalFlags_doubleQuotes['\n'] = true;
  61. specicalFlags_doubleQuotes['\f'] = true;
  62. specicalFlags_doubleQuotes['\r'] = true;
  63. specicalFlags_doubleQuotes['\"'] = true;
  64. specicalFlags_doubleQuotes['\\'] = true;
  65. specicalFlags_doubleQuotes['\u000B'] = true;
  66. specicalFlags_singleQuotes['\b'] = true;
  67. specicalFlags_singleQuotes['\n'] = true;
  68. specicalFlags_singleQuotes['\f'] = true;
  69. specicalFlags_singleQuotes['\r'] = true;
  70. specicalFlags_singleQuotes['\''] = true;
  71. specicalFlags_singleQuotes['\\'] = true;
  72. specicalFlags_singleQuotes['\u000B'] = true;
  73. replaceChars['\b'] = 'b';
  74. replaceChars['\n'] = 'n';
  75. replaceChars['\f'] = 'f';
  76. replaceChars['\r'] = 'r';
  77. replaceChars['\"'] = '"';
  78. replaceChars['\''] = '\'';
  79. replaceChars['\\'] = '\\';
  80. replaceChars['\t'] = 't';
  81. replaceChars['/'] = '/';
  82. replaceChars['\u000B'] = 'v';
  83. }
  84. public final static char [] ASCII_CHARS = {
  85. '0', '0', '0', '1', '0', '2', '0', '3',
  86. '0', '4', '0', '5', '0', '6', '0', '7',
  87. '0', '8', '0', '9', '0', 'A', '0', 'B',
  88. '0', 'C', '0', 'D', '0', 'E', '0', 'F',
  89. '1', '0', '1', '1', '1', '2', '1', '3',
  90. '1', '4', '1', '5', '1', '6', '1', '7',
  91. '1', '8', '1', '9', '1', 'A', '1', 'B',
  92. '1', 'C', '1', 'D', '1', 'E', '1', 'F',
  93. '2', '0', '2', '1', '2', '2', '2', '3',
  94. '2', '4', '2', '5', '2', '6', '2', '7',
  95. '2', '8', '2', '9', '2', 'A', '2', 'B',
  96. '2', 'C', '2', 'D', '2', 'E', '2', 'F',
  97. } ;
  98. public final static boolean isEmoji(char ch) {
  99. if (ch >= '\uE001' && ch <= '\uE05A') {
  100. return true;
  101. }
  102. if (ch >= '\uE101' && ch <= '\uE15A') {
  103. return true;
  104. }
  105. if (ch >= '\uE201' && ch <= '\uE253') {
  106. return true;
  107. }
  108. if (ch >= '\uE401' && ch <= '\uE44C') {
  109. return true;
  110. }
  111. if (ch >= '\uE501' && ch <= '\uE537') {
  112. return true;
  113. }
  114. return false;
  115. }
  116. }