CALLOUTS.API 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. Callouts API Version 6.8.2 2018/06/08
  2. #include <oniguruma.h>
  3. (1) Callout functions
  4. (2) Set/Get functions for Callouts of contents
  5. (3) Set functions for Callouts of name
  6. (4) User data
  7. (5) Get values from OnigCalloutArgs
  8. (6) Tag
  9. (7) Callout data (used in callout functions)
  10. (8) Callout data (used in applications)
  11. (9) Miscellaneous functions
  12. (1) Callout functions
  13. type: OnigCalloutFunc
  14. typedef int (*OnigCalloutFunc)(OnigCalloutArgs* args, void* user_data);
  15. If 0 (NULL) is set as a callout function value, never called.
  16. * Callout function return value (int)
  17. ONIG_CALLOUT_FAIL (== 1): fail
  18. ONIG_CALLOUT_SUCCESS (== 0): success
  19. less than -1: error code (terminate search/match)
  20. ONIG_CALLOUT_FAIL/SUCCESS values are ignored in retractions,
  21. because retraction is a part of recovery process after failure.
  22. * Example of callout function
  23. extern int always_success(OnigCalloutArgs* args, void* user_data)
  24. {
  25. return ONIG_CALLOUT_SUCCESS;
  26. }
  27. (2) Set/Get functions for Callouts of contents
  28. # OnigCalloutFunc onig_get_progress_callout(void)
  29. Get a function for callouts of contents in progress.
  30. # int onig_set_progress_callout(OnigCalloutFunc f)
  31. Set a function for callouts of contents in progress.
  32. This value set in onig_initialize_match_param() as a default
  33. callout function.
  34. normal return: ONIG_NORMAL
  35. # OnigCalloutFunc onig_get_retraction_callout(void)
  36. Get a function for callouts of contents in retraction (backtrack).
  37. # int onig_set_retraction_callout(OnigCalloutFunc f)
  38. Set a function for callouts of contents in retraction (backtrack).
  39. This value set in onig_initialize_match_param() as a default
  40. callout function.
  41. normal return: ONIG_NORMAL
  42. # int onig_set_progress_callout_of_match_param(OnigMatchParam* mp, OnigCalloutFunc f)
  43. Set a function for callouts of contents in progress.
  44. arguments
  45. 1 mp: match-param pointer
  46. 2 f: function
  47. normal return: ONIG_NORMAL
  48. # int onig_set_retraction_callout_of_match_param(OnigMatchParam* mp, OnigCalloutFunc f)
  49. Set a function for callouts of contents in retraction (backtrack).
  50. arguments
  51. 1 mp: match-param pointer
  52. 2 f: function
  53. normal return: ONIG_NORMAL
  54. (3) Set functions for Callouts of name
  55. # int onig_set_callout_of_name(OnigEncoding enc, OnigCalloutType type, OnigUChar* name, OnigUChar* name_end, int callout_in, OnigCalloutFunc callout, OnigCalloutFunc end_callout, int arg_num, unsigned int arg_types[], int opt_arg_num, OnigValue opt_defaults[])
  56. Set a function for callouts of name.
  57. Allowed name string characters: _ A-Z a-z 0-9 (* first character: _ A-Z a-z)
  58. (enc, name) pair is used as key value to find callout function.
  59. You have to call this function for every encoding used in your applications.
  60. But if enc is ASCII compatible and (enc, name) entry is not found,
  61. then (ASCII, name) entry is used.
  62. Therefore, if you use ASCII compatible encodings only, it is enough to call
  63. this function one time for (ASCII, name).
  64. arguments
  65. 1 enc: character encoding
  66. 2 type: callout type (currently ONIG_CALLOUT_TYPE_SINGLE only supported)
  67. 3 name: name string address (the string is encoded by enc)
  68. 4 name_end: name string end address
  69. 5 callout_in: direction (ONIG_CALLOUT_IN_PROGRESS/RETRACTION/BOTH)
  70. 6 callout: callout function
  71. 7 end_callout: * not used currently (set 0)
  72. 8 arg_num: number of arguments (*limit by ONIG_CALLOUT_MAX_ARGS_NUM == 4)
  73. 9 arg_types: type array of arguments
  74. 10 opt_arg_num: number of optional arguments
  75. 11 opt_defaults: default values array of optional arguments
  76. normal return: ONIG_NORMAL
  77. error:
  78. ONIGERR_INVALID_CALLOUT_NAME
  79. ONIGERR_INVALID_ARGUMENT
  80. ONIGERR_INVALID_CALLOUT_ARG
  81. (4) User data
  82. # int onig_set_callout_user_data_of_match_param(OnigMatchParam* param, void* user_data)
  83. Set a user_data value which passed as second argument of callout.
  84. normal return: ONIG_NORMAL
  85. (5) Get values from OnigCalloutArgs
  86. # int onig_get_callout_num_by_callout_args(OnigCalloutArgs* args)
  87. Returns callout number of this callout.
  88. "Callout number" is an identifier of callout in a regex pattern.
  89. # OnigCalloutIn onig_get_callout_in_by_callout_args(OnigCalloutArgs* args)
  90. Returns the direction of this callout.
  91. (ONIG_CALLOUT_IN_PROGRESS or ONIG_CALLOUT_IN_RETRACTION)
  92. # int onig_get_name_id_by_callout_args(OnigCalloutArgs* args)
  93. Returns the name identifier of this callout.
  94. If this callout is callout of contents, then returns ONIG_NON_NAME_ID.
  95. # const OnigUChar* onig_get_contents_by_callout_args(OnigCalloutArgs* args)
  96. Returns the contents string of this callout. (NULL terminated string)
  97. If this callout is callout of name, then returns NULL.
  98. # const OnigUChar* onig_get_contents_end_by_callout_args(OnigCalloutArgs* args)
  99. Returns the end of contents string of this callout.
  100. If this callout is callout of name, then returns NULL.
  101. # int onig_get_args_num_by_callout_args(OnigCalloutArgs* args)
  102. Returns the number of args of this callout.
  103. It includes optional arguments that doesn't passed in regex pattern.
  104. If this callout is callout of contents, then returns
  105. ONIGERR_INVALID_ARGUMENT.
  106. # int onig_get_passed_args_num_by_callout_args(OnigCalloutArgs* args)
  107. Returns the number of args that passed really in regex pattern.
  108. If this callout is callout of contents, then returns
  109. ONIGERR_INVALID_ARGUMENT.
  110. # int onig_get_arg_by_callout_args(OnigCalloutArgs* args, int index, OnigType* type, OnigValue* val)
  111. Returns a value and a type of the callout argument.
  112. If this callout is callout of contents, then returns
  113. ONIGERR_INVALID_ARGUMENT.
  114. normal return: ONIG_NORMAL
  115. # const OnigUChar* onig_get_string_by_callout_args(OnigCalloutArgs* args)
  116. Returns the subject string address.
  117. This is the second argument(str) of onig_search().
  118. # const OnigUChar* onig_get_string_end_by_callout_args(OnigCalloutArgs* args)
  119. Returns the end address of subject string.
  120. This is the third argument(end) of onig_search().
  121. # const OnigUChar* onig_get_start_by_callout_args(OnigCalloutArgs* args)
  122. Returns the start address of subject string in current match process.
  123. # const OnigUChar* onig_get_right_range_by_callout_args(OnigCalloutArgs* args)
  124. Returns the right range address of subject string.
  125. # const OnigUChar* onig_get_current_by_callout_args(OnigCalloutArgs* args)
  126. Returns the current address of subject string in current match process.
  127. # OnigRegex onig_get_regex_by_callout_args(OnigCalloutArgs* args)
  128. Returns the regex object address of this callout.
  129. # unsigned long onig_get_retry_counter_by_callout_args(OnigCalloutArgs* args)
  130. Returns the current counter value for retry-limit-in-match.
  131. (6) Tag
  132. "Tag" is a name assigned to a callout in regexp pattern.
  133. Allowed tag string characters: _ A-Z a-z 0-9 (* first character: _ A-Z a-z)
  134. # int onig_callout_tag_is_exist_at_callout_num(OnigRegex reg, int callout_num)
  135. Returns 1 if tag is assigned for the callout, else returns 0.
  136. # int onig_get_callout_num_by_tag(OnigRegex reg, const OnigUChar* tag, const OnigUChar* tag_end)
  137. Returns the callout number for the tag.
  138. # const OnigUChar* onig_get_callout_tag_start(OnigRegex reg, int callout_num)
  139. Returns the start address of tag string for the callout.
  140. (NULL terminated string)
  141. # const OnigUChar* onig_get_callout_tag_end(OnigRegex reg, int callout_num)
  142. Returns the end address of tag string for the callout.
  143. (7) Callout data (used in callout functions)
  144. "Callout data" is ONIG_CALLOUT_DATA_SLOT_NUM(5) values area
  145. for each callout in each search process.
  146. Each value area in a callout is indicated by "slot" number (0 - 4).
  147. Callout data are used for any purpose by callout function implementers.
  148. # int onig_get_callout_data_by_callout_args(OnigCalloutArgs* args, int callout_num, int slot, OnigType* type, OnigValue* val)
  149. Returns the callout data value/type for a callout slot indicated by
  150. callout_num/slot.
  151. normal return: ONIG_NORMAL
  152. 1: not yet set (type is ONIG_TYPE_VOID)
  153. < 0: error code
  154. # int onig_get_callout_data_by_callout_args_self(OnigCalloutArgs* args, int slot, OnigType* type, OnigValue* val)
  155. Returns self callout data value/type.
  156. normal return: ONIG_NORMAL
  157. 1: not yet set (type is ONIG_TYPE_VOID)
  158. < 0: error code
  159. # int onig_set_callout_data_by_callout_args(OnigCalloutArgs* args, int callout_num, int slot, OnigType type, OnigValue* val)
  160. Set the callout data value/type for a callout slot indicated by callout_num/slot.
  161. normal return: ONIG_NORMAL
  162. < 0: error code
  163. # int onig_set_callout_data_by_callout_args_self(OnigCalloutArgs* args, int slot, OnigType type, OnigValue* val)
  164. Set self callout data value/type for a callout slot indicated by slot.
  165. normal return: ONIG_NORMAL
  166. < 0: error code
  167. # int onig_get_callout_data_by_callout_args_self_dont_clear_old(OnigCalloutArgs* args, int slot, OnigType* type, OnigValue* val)
  168. This function is almost same as onig_get_callout_data_by_callout_args_self().
  169. But this function doesn't clear values which set in previous failed match process.
  170. Other onig_get_callout_data_xxxx() functions clear all values which set
  171. in previous failed match process.
  172. For example, Builtin callout (*TOTAL_COUNT) is implemented by using this
  173. function for accumulate count of all of match processes in a search process.
  174. Builtin callout (*COUNT) returns count in last success match process only,
  175. because it doesn't use this function.
  176. (8) Callout data (used in apllications)
  177. # int onig_get_callout_data(OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType* type, OnigValue* val)
  178. Returns the callout data value/type for a callout slot indicated by
  179. callout_num/slot.
  180. normal return: ONIG_NORMAL
  181. 1: not yet set (type is ONIG_TYPE_VOID)
  182. < 0: error code
  183. # int onig_get_callout_data_by_tag(OnigRegex reg, OnigMatchParam* mp, const OnigUChar* tag, const OnigUChar* tag_end, int slot, OnigType* type, OnigValue* val)
  184. Returns the callout data value/type for a callout slot indicated by tag/slot.
  185. normal return: ONIG_NORMAL
  186. 1: not yet set (type is ONIG_TYPE_VOID)
  187. < 0: error code
  188. # int onig_set_callout_data(OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType type, OnigValue* val)
  189. Set the callout data value/type for a callout slot indicated by callout_num/slot.
  190. normal return: ONIG_NORMAL
  191. < 0: error code
  192. # int onig_set_callout_data_by_tag(OnigRegex reg, OnigMatchParam* mp, const OnigUChar* tag, const OnigUChar* tag_end, int slot, OnigType type, OnigValue* val)
  193. Set the callout data value/type for a callout slot indicated by tag/slot.
  194. normal return: ONIG_NORMAL
  195. < 0: error code
  196. # int onig_get_callout_data_dont_clear_old(OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType* type, OnigValue* val)
  197. No needs to use this function.
  198. It will be abolished.
  199. (9) Miscellaneous functions
  200. # OnigUChar* onig_get_callout_name_by_name_id(int name_id)
  201. Returns callout name of the name id.
  202. if invalid name id is passed, return 0.
  203. # int onig_get_capture_range_in_callout(OnigCalloutArgs* args, int mem_num, int* begin, int* end)
  204. Returns current capture range position.
  205. Position is byte length offset from subject string.
  206. For uncaptured mem_num, ONIG_REGION_NOTPOS is set.
  207. # int onig_get_used_stack_size_in_callout(OnigCalloutArgs* args, int* used_num, int* used_bytes)
  208. Returns current used match-stack size.
  209. used_num: number of match-stack elements
  210. used_bytes: used byte size of match-stack
  211. //END