lwjson_opt.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * \file lwjson_opt.h
  3. * \brief LwJSON options
  4. */
  5. /*
  6. * Copyright (c) 2024 Tilen MAJERLE
  7. *
  8. * Permission is hereby granted, free of charge, to any person
  9. * obtaining a copy of this software and associated documentation
  10. * files (the "Software"), to deal in the Software without restriction,
  11. * including without limitation the rights to use, copy, modify, merge,
  12. * publish, distribute, sublicense, and/or sell copies of the Software,
  13. * and to permit persons to whom the Software is furnished to do so,
  14. * subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  21. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  22. * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  23. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  24. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. *
  28. * This file is part of LwJSON - Lightweight JSON format parser.
  29. *
  30. * Author: Tilen MAJERLE <tilen@majerle.eu>
  31. * Version: v1.8.1
  32. */
  33. #ifndef LWJSON_OPT_HDR_H
  34. #define LWJSON_OPT_HDR_H
  35. /* Uncomment to ignore user options (or set macro in compiler flags) */
  36. /* #define LWJSON_IGNORE_USER_OPTS */
  37. /* Include application options */
  38. #ifndef LWJSON_IGNORE_USER_OPTS
  39. #include "lwjson_opts.h"
  40. #endif /* LWJSON_IGNORE_USER_OPTS */
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif /* __cplusplus */
  44. /**
  45. * \defgroup LWJSON_OPT Configuration
  46. * \brief LwJSON options
  47. * \{
  48. */
  49. /**
  50. * \brief Real data type used to parse numbers with floating point number
  51. * \note Data type must be signed, normally `float` or `double`
  52. *
  53. * This is used for numbers in \ref LWJSON_TYPE_NUM_REAL token data type.
  54. */
  55. #ifndef LWJSON_CFG_REAL_TYPE
  56. #define LWJSON_CFG_REAL_TYPE float
  57. #endif
  58. /**
  59. * \brief Integer type used to parse numbers
  60. * \note Data type must be signed integer
  61. *
  62. * This is used for numbers in \ref LWJSON_TYPE_NUM_INT token data type.
  63. */
  64. #ifndef LWJSON_CFG_INT_TYPE
  65. #define LWJSON_CFG_INT_TYPE long long
  66. #endif
  67. /**
  68. * \brief Enables `1` or disables `0` support for inline comments
  69. *
  70. * Default set to `0` to be JSON compliant
  71. */
  72. #ifndef LWJSON_CFG_COMMENTS
  73. #define LWJSON_CFG_COMMENTS 0
  74. #endif
  75. /**
  76. * \brief Memory set function
  77. *
  78. * \note Function footprint is the same as \ref memset
  79. */
  80. #ifndef LWJSON_MEMSET
  81. #define LWJSON_MEMSET(dst, val, len) memset((dst), (val), (len))
  82. #endif
  83. /**
  84. * \brief Memory copy function
  85. *
  86. * \note Function footprint is the same as \ref memcpy
  87. */
  88. #ifndef LWJSON_MEMCPY
  89. #define LWJSON_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
  90. #endif
  91. /**
  92. * \defgroup LWJSON_OPT_STREAM JSON stream
  93. * \brief JSON streaming confiuration
  94. * \{
  95. */
  96. /**
  97. * \brief Max length of token key (object key name) to be available for stack storage
  98. *
  99. */
  100. #ifndef LWJSON_CFG_STREAM_KEY_MAX_LEN
  101. #define LWJSON_CFG_STREAM_KEY_MAX_LEN 32
  102. #endif
  103. /**
  104. * \brief Max stack size (depth) in units of \ref lwjson_stream_stack_t structure
  105. *
  106. */
  107. #ifndef LWJSON_CFG_STREAM_STACK_SIZE
  108. #define LWJSON_CFG_STREAM_STACK_SIZE 16
  109. #endif
  110. /**
  111. * \brief Max size of string for single parsing in units of bytes
  112. *
  113. */
  114. #ifndef LWJSON_CFG_STREAM_STRING_MAX_LEN
  115. #define LWJSON_CFG_STREAM_STRING_MAX_LEN 256
  116. #endif
  117. /**
  118. * \brief Max number of bytes used to parse primitive.
  119. *
  120. * Primitives are all numbers and logical values (null, true, false)
  121. */
  122. #ifndef LWJSON_CFG_STREAM_PRIMITIVE_MAX_LEN
  123. #define LWJSON_CFG_STREAM_PRIMITIVE_MAX_LEN 32
  124. #endif
  125. /**
  126. * \}
  127. */
  128. /**
  129. * \}
  130. */
  131. #ifdef __cplusplus
  132. }
  133. #endif /* __cplusplus */
  134. #endif /* LWJSON_OPT_HDR_H */