en.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Tencent is pleased to support the open source community by making RapidJSON
  2. // available.
  3. //
  4. // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
  5. // rights reserved.
  6. //
  7. // Licensed under the MIT License (the "License"); you may not use this file
  8. // except in compliance with the License. You may obtain a copy of the License
  9. // at
  10. //
  11. // http://opensource.org/licenses/MIT
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. // License for the specific language governing permissions and limitations under
  17. // the License.
  18. #ifndef RAPIDJSON_ERROR_EN_H_
  19. #define RAPIDJSON_ERROR_EN_H_
  20. #include "error.h"
  21. #ifdef __clang__
  22. RAPIDJSON_DIAG_PUSH
  23. RAPIDJSON_DIAG_OFF(switch - enum)
  24. RAPIDJSON_DIAG_OFF(covered - switch - default)
  25. #endif
  26. RAPIDJSON_NAMESPACE_BEGIN
  27. //! Maps error code of parsing into error message.
  28. /*!
  29. \ingroup RAPIDJSON_ERRORS
  30. \param parseErrorCode Error code obtained in parsing.
  31. \return the error message.
  32. \note User can make a copy of this function for localization.
  33. Using switch-case is safer for future modification of error codes.
  34. */
  35. inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(
  36. ParseErrorCode parseErrorCode) {
  37. switch (parseErrorCode) {
  38. case kParseErrorNone:
  39. return RAPIDJSON_ERROR_STRING("No error.");
  40. case kParseErrorDocumentEmpty:
  41. return RAPIDJSON_ERROR_STRING("The document is empty.");
  42. case kParseErrorDocumentRootNotSingular:
  43. return RAPIDJSON_ERROR_STRING(
  44. "The document root must not be followed by other values.");
  45. case kParseErrorValueInvalid:
  46. return RAPIDJSON_ERROR_STRING("Invalid value.");
  47. case kParseErrorObjectMissName:
  48. return RAPIDJSON_ERROR_STRING("Missing a name for object member.");
  49. case kParseErrorObjectMissColon:
  50. return RAPIDJSON_ERROR_STRING(
  51. "Missing a colon after a name of object member.");
  52. case kParseErrorObjectMissCommaOrCurlyBracket:
  53. return RAPIDJSON_ERROR_STRING(
  54. "Missing a comma or '}' after an object member.");
  55. case kParseErrorArrayMissCommaOrSquareBracket:
  56. return RAPIDJSON_ERROR_STRING(
  57. "Missing a comma or ']' after an array element.");
  58. case kParseErrorStringUnicodeEscapeInvalidHex:
  59. return RAPIDJSON_ERROR_STRING(
  60. "Incorrect hex digit after \\u escape in string.");
  61. case kParseErrorStringUnicodeSurrogateInvalid:
  62. return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid.");
  63. case kParseErrorStringEscapeInvalid:
  64. return RAPIDJSON_ERROR_STRING("Invalid escape character in string.");
  65. case kParseErrorStringMissQuotationMark:
  66. return RAPIDJSON_ERROR_STRING(
  67. "Missing a closing quotation mark in string.");
  68. case kParseErrorStringInvalidEncoding:
  69. return RAPIDJSON_ERROR_STRING("Invalid encoding in string.");
  70. case kParseErrorNumberTooBig:
  71. return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
  72. case kParseErrorNumberMissFraction:
  73. return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
  74. case kParseErrorNumberMissExponent:
  75. return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
  76. case kParseErrorTermination:
  77. return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
  78. case kParseErrorUnspecificSyntaxError:
  79. return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
  80. default:
  81. return RAPIDJSON_ERROR_STRING("Unknown error.");
  82. }
  83. }
  84. RAPIDJSON_NAMESPACE_END
  85. #ifdef __clang__
  86. RAPIDJSON_DIAG_POP
  87. #endif
  88. #endif // RAPIDJSON_ERROR_EN_H_