PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext/pcre/ext_pcre.php

http://github.com/facebook/hiphop-php
PHP | 427 lines | 89 code | 18 blank | 320 comment | 0 complexity | 76bbc1592de16dc742867da3c76bcf7c MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh // partial
  2. /**
  3. * Perform a regular expression search and replace.
  4. *
  5. * preg_filter() is identical to preg_replace() except it only returns the
  6. * (possibly transformed) subjects where there was a match. For details
  7. * about how this function works, read the preg_replace() documentation.
  8. *
  9. * @return mixed - preg_filter() returns an array if the subject parameter
  10. * is an array, or a string otherwise. If no matches are found or an error
  11. * occurred, an empty array is returned when subject is an array or NULL
  12. * otherwise.
  13. */
  14. <<__Native, __Rx>>
  15. function preg_filter(mixed $pattern,
  16. mixed $replacement,
  17. mixed $subject,
  18. int $limit,
  19. <<__OutOnly("KindOfInt64")>>
  20. inout ?int $count): mixed;
  21. /**
  22. * Return array entries that match the pattern
  23. *
  24. * @param string $pattern - The pattern to search for, as a string.
  25. * @param array $input - The input array.
  26. * @param int $flags - If set to PREG_GREP_INVERT, this function returns
  27. * the elements of the input array that do not match the given pattern.
  28. *
  29. * @return array - Returns an array indexed using the keys from the input
  30. * array.
  31. */
  32. <<__Native, __Rx>>
  33. function preg_grep(string $pattern,
  34. varray_or_darray $input,
  35. int $flags = 0): mixed;
  36. /**
  37. * Returns the error code of the last PCRE regex execution
  38. *
  39. * @return int - Returns one of the following constants (explained on
  40. * their own page): PREG_NO_ERROR PREG_INTERNAL_ERROR
  41. * PREG_BACKTRACK_LIMIT_ERROR (see also pcre.backtrack_limit)
  42. * PREG_RECURSION_LIMIT_ERROR (see also pcre.recursion_limit)
  43. * PREG_BAD_UTF8_ERROR PREG_BAD_UTF8_OFFSET_ERROR (since PHP 5.3.0)
  44. */
  45. <<__Native, __NonRx('Reads from global')>>
  46. function preg_last_error(): int;
  47. /**
  48. * Perform a global regular expression match
  49. *
  50. * @param string $pattern - The pattern to search for, as a string.
  51. * @param string $subject - The input string.
  52. * @param array $matches - Array of all matches in multi-dimensional
  53. * array ordered according to flags.
  54. * @param int $flags - Can be a combination of the following flags (note
  55. * that it doesn't make sense to use PREG_PATTERN_ORDER together with
  56. * PREG_SET_ORDER): PREG_PATTERN_ORDER Orders results so that
  57. * $matches[0] is an array of full pattern matches, $matches[1] is an
  58. * array of strings matched by the first parenthesized subpattern, and so
  59. * on. So, $out[0] contains array of strings that matched full
  60. * pattern, and $out[1] contains array of strings enclosed by tags.
  61. * PREG_SET_ORDER Orders results so that $matches[0] is an array of
  62. * first set of matches, $matches[1] is an array of second set of
  63. * matches, and so on. PREG_OFFSET_CAPTURE If this flag is
  64. * passed, for every occurring match the appendant string offset will
  65. * also be returned. Note that this changes the value of matches into an
  66. * array where every element is an array consisting of the matched string
  67. * at offset 0 and its string offset into subject at offset 1. If
  68. * no order flag is given, PREG_PATTERN_ORDER is assumed.
  69. * @param int $offset - Normally, the search starts from the beginning of
  70. * the subject string. The optional parameter offset can be used to
  71. * specify the alternate place from which to start the search (in bytes).
  72. * Using offset is not equivalent to passing substr($subject, $offset)
  73. * to preg_match_all() in place of the subject string, because pattern
  74. * can contain assertions such as ^, $ or (?=x). See preg_match() for
  75. * examples.
  76. *
  77. * @return int - Returns the number of full pattern matches (which might
  78. * be zero), or FALSE if an error occurred.
  79. */
  80. <<__Native, __Rx>>
  81. function preg_match_all(string $pattern,
  82. string $subject,
  83. int $flags = 0,
  84. int $offset = 0): mixed;
  85. <<__Native, __Rx>>
  86. function preg_match_all_with_matches(string $pattern,
  87. string $subject,
  88. <<__OutOnly>>
  89. inout mixed $matches,
  90. int $flags = 0,
  91. int $offset = 0): mixed;
  92. /**
  93. * Perform a regular expression match
  94. *
  95. * @param string $pattern - The pattern to search for, as a string.
  96. * @param string $subject - The input string.
  97. * @param array $matches - If matches is provided, then it is filled with
  98. * the results of search. $matches[0] will contain the text that matched
  99. * the full pattern, $matches[1] will have the text that matched the
  100. * first captured parenthesized subpattern, and so on.
  101. * @param int $flags - flags can be the following flag:
  102. * PREG_OFFSET_CAPTURE If this flag is passed, for every occurring
  103. * match the appendant string offset will also be returned. Note that
  104. * this changes the value of matches into an array where every element is
  105. * an array consisting of the matched string at offset 0 and its string
  106. * offset into subject at offset 1.
  107. * @param int $offset - Normally, the search starts from the beginning of
  108. * the subject string. The optional parameter offset can be used to
  109. * specify the alternate place from which to start the search (in bytes).
  110. * Using offset is not equivalent to passing substr($subject, $offset)
  111. * to preg_match() in place of the subject string, because pattern can
  112. * contain assertions such as ^, $ or (?=x). Compare: while this
  113. * example will produce
  114. *
  115. * @return int - preg_match() returns 1 if the pattern matches given
  116. * subject, 0 if it does not, or FALSE if an error occurred.
  117. */
  118. <<__Native, __Rx>>
  119. function preg_match(string $pattern,
  120. string $subject,
  121. int $flags = 0,
  122. int $offset = 0): mixed;
  123. <<__Native, __Rx>>
  124. function preg_match_with_matches(string $pattern,
  125. string $subject,
  126. <<__OutOnly>>
  127. inout mixed $matches,
  128. int $flags = 0,
  129. int $offset = 0): mixed;
  130. /**
  131. * Quote regular expression characters
  132. *
  133. * @param string $str - The input string.
  134. * @param string $delimiter - If the optional delimiter is specified, it
  135. * will also be escaped. This is useful for escaping the delimiter that
  136. * is required by the PCRE functions. The / is the most commonly used
  137. * delimiter.
  138. *
  139. * @return string - Returns the quoted (escaped) string.
  140. */
  141. <<__IsFoldable, __Rx, __Native>>
  142. function preg_quote(string $str,
  143. ?string $delimiter = NULL): string;
  144. /**
  145. * Perform a regular expression search and replace using a callback
  146. *
  147. * @param mixed $pattern - The pattern to search for. It can be either a
  148. * string or an array with strings.
  149. * @param callable $callback - A callback that will be called and passed
  150. * an array of matched elements in the subject string. The callback
  151. * should return the replacement string. This is the callback signature:
  152. * stringhandler arraymatches You'll often need the callback
  153. * function for a preg_replace_callback() in just one place. In this case
  154. * you can use an anonymous function to declare the callback within the
  155. * call to preg_replace_callback(). By doing it this way you have all
  156. * information for the call in one place and do not clutter the function
  157. * namespace with a callback function's name not used anywhere else.
  158. * preg_replace_callback() and anonymous function
  159. * @param mixed $subject - The string or an array with strings to search
  160. * and replace.
  161. * @param int $limit - The maximum possible replacements for each pattern
  162. * in each subject string. Defaults to -1 (no limit).
  163. * @param int $count - If specified, this variable will be filled with
  164. * the number of replacements done.
  165. *
  166. * @return mixed - preg_replace_callback() returns an array if the
  167. * subject parameter is an array, or a string otherwise. On errors the
  168. * return value is NULL If matches are found, the new subject will be
  169. * returned, otherwise subject will be returned unchanged.
  170. */
  171. <<__Native, __Rx>>
  172. function preg_replace_callback(mixed $pattern,
  173. mixed $callback,
  174. mixed $subject,
  175. int $limit,
  176. <<__OutOnly("KindOfInt64")>>
  177. inout ?int $count): mixed;
  178. /**
  179. * Perform a regular expression search and replace using an associative array of
  180. * pattern and callback key/value pairs. In array order, each callback is called
  181. * for the pattern in question, and the return value is then used as the subject
  182. * for the next pattern/callback pair. This function alleviates the need for a
  183. * a bunch of branching checks that are required if you called something like
  184. * preg_replace_callback() that uses a single callback.
  185. *
  186. * @param mixed $patterns_and_callbacks - An associative array mapping patterns
  187. * (keys) to callbacks (values). Each callback that will be called will be
  188. * passed an array of matched elements in the subject string. The callback
  189. * should return the replacement string. This is the callback signature:
  190. * `string handler (array matches)`
  191. * If you need the callback function just in one place in the array, use an
  192. * anonymous function to declare the callback within the call to
  193. * preg_replace_callback_array(). By doing it this way you have all the
  194. * information for the call in one place and do not clutter the function
  195. * namespace with a callback function's name not used anywhere else.
  196. * @param mixed $subject - The string or an array with strings to search
  197. * and replace.
  198. * @param int $limit - The maximum possible replacements for each pattern
  199. * in each subject string. Defaults to -1 (no limit).
  200. * @param int $count - If specified, this variable will be filled with
  201. * the number of replacements done.
  202. *
  203. * @return mixed - preg_replace_callback_array() returns an array if the
  204. * subject parameter is an array, or a string otherwise. On errors the
  205. * return value is NULL If matches are found, the new subject will be
  206. * returned, otherwise subject will be returned unchanged.
  207. */
  208. <<__Native, __Rx>>
  209. function preg_replace_callback_array(mixed $patterns_and_callbacks,
  210. mixed $subject,
  211. int $limit,
  212. <<__OutOnly("KindOfInt64")>>
  213. inout ?int $count): mixed;
  214. /**
  215. * Perform a regular expression search and replace
  216. *
  217. * @param mixed $pattern - The pattern to search for. It can be either a
  218. * string or an array with strings. Several PCRE modifiers are also
  219. * available, including the deprecated 'e' (PREG_REPLACE_EVAL), which is
  220. * specific to this function.
  221. * @param mixed $replacement - The string or an array with strings to
  222. * replace. If this parameter is a string and the pattern parameter is an
  223. * array, all patterns will be replaced by that string. If both pattern
  224. * and replacement parameters are arrays, each pattern will be replaced
  225. * by the replacement counterpart. If there are fewer elements in the
  226. * replacement array than in the pattern array, any extra patterns will
  227. * be replaced by an empty string. replacement may contain references
  228. * of the form \\n or (since PHP 4.0.4) $n, with the latter form being
  229. * the preferred one. Every such reference will be replaced by the text
  230. * captured by the n'th parenthesized pattern. n can be from 0 to 99, and
  231. * \\0 or $0 refers to the text matched by the whole pattern. Opening
  232. * parentheses are counted from left to right (starting from 1) to obtain
  233. * the number of the capturing subpattern. To use backslash in
  234. * replacement, it must be doubled ("\\\\" PHP string). When working
  235. * with a replacement pattern where a backreference is immediately
  236. * followed by another number (i.e.: placing a literal number immediately
  237. * after a matched pattern), you cannot use the familiar \\1 notation for
  238. * your backreference. \\11, for example, would confuse preg_replace()
  239. * since it does not know whether you want the \\1 backreference followed
  240. * by a literal 1, or the \\11 backreference followed by nothing. In this
  241. * case the solution is to use \${1}1. This creates an isolated $1
  242. * backreference, leaving the 1 as a literal. When using the deprecated
  243. * e modifier, this function escapes some characters (namely ', ", \ and
  244. * NULL) in the strings that replace the backreferences. This is done to
  245. * ensure that no syntax errors arise from backreference usage with
  246. * either single or double quotes (e.g. 'strlen(\'$1\')+strlen("$2")').
  247. * Make sure you are aware of PHP's string syntax to know exactly how the
  248. * interpreted string will look.
  249. * @param mixed $subject - The string or an array with strings to search
  250. * and replace. If subject is an array, then the search and replace is
  251. * performed on every entry of subject, and the return value is an array
  252. * as well.
  253. * @param int $limit - The maximum possible replacements for each pattern
  254. * in each subject string. Defaults to -1 (no limit).
  255. * @param int $count - If specified, this variable will be filled with
  256. * the number of replacements done.
  257. *
  258. * @return mixed - preg_replace() returns an array if the subject
  259. * parameter is an array, or a string otherwise. If matches are found,
  260. * the new subject will be returned, otherwise subject will be returned
  261. * unchanged or NULL if an error occurred.
  262. */
  263. <<__Native, __Rx>>
  264. function preg_replace(mixed $pattern,
  265. mixed $replacement,
  266. mixed $subject,
  267. int $limit = -1): mixed;
  268. <<__Native, __Rx>>
  269. function preg_replace_with_count(mixed $pattern,
  270. mixed $replacement,
  271. mixed $subject,
  272. int $limit,
  273. <<__OutOnly("KindOfInt64")>>
  274. inout ?int $count): mixed;
  275. /**
  276. * Split string by a regular expression
  277. *
  278. * @param string $pattern - The pattern to search for, as a string.
  279. * @param string $subject - The input string.
  280. * @param int $limit - If specified, then only substrings up to limit are
  281. * returned with the rest of the string being placed in the last
  282. * substring. A limit of -1, 0 or NULL means "no limit" and, as is
  283. * standard across PHP, you can use NULL to skip to the flags parameter.
  284. * @param int $flags - flags can be any combination of the following
  285. * flags (combined with the | bitwise operator): PREG_SPLIT_NO_EMPTY
  286. * If this flag is set, only non-empty pieces will be returned by
  287. * preg_split(). PREG_SPLIT_DELIM_CAPTURE If this flag is set,
  288. * parenthesized expression in the delimiter pattern will be captured and
  289. * returned as well. PREG_SPLIT_OFFSET_CAPTURE If this flag is set,
  290. * for every occurring match the appendant string offset will also be
  291. * returned. Note that this changes the return value in an array where
  292. * every element is an array consisting of the matched string at offset 0
  293. * and its string offset into subject at offset 1.
  294. *
  295. * @return array - Returns an array containing substrings of subject
  296. * split along boundaries matched by pattern.
  297. */
  298. <<__Native, __Rx>>
  299. function preg_split(string $pattern,
  300. string $subject,
  301. mixed $limit = null,
  302. int $flags = 0): mixed;
  303. /**
  304. * Replace regular expression
  305. *
  306. * @param string $pattern - A POSIX extended regular expression.
  307. * @param string $replacement - If pattern contains parenthesized
  308. * substrings, replacement may contain substrings of the form \digit,
  309. * which will be replaced by the text matching the digit'th parenthesized
  310. * substring; \0 will produce the entire contents of string. Up to nine
  311. * substrings may be used. Parentheses may be nested, in which case they
  312. * are counted by the opening parenthesis.
  313. * @param string $string - The input string.
  314. *
  315. * @return string - The modified string is returned. If no matches are
  316. * found in string, then it will be returned unchanged.
  317. */
  318. <<__Native>>
  319. function ereg_replace(string $pattern,
  320. string $replacement,
  321. string $string): string;
  322. /**
  323. * Replace regular expression case insensitive
  324. *
  325. * @param string $pattern - A POSIX extended regular expression.
  326. * @param string $replacement - If pattern contains parenthesized
  327. * substrings, replacement may contain substrings of the form \digit,
  328. * which will be replaced by the text matching the digit'th parenthesized
  329. * substring; \0 will produce the entire contents of string. Up to nine
  330. * substrings may be used. Parentheses may be nested, in which case they
  331. * are counted by the opening parenthesis.
  332. * @param string $string - The input string.
  333. *
  334. * @return string - The modified string is returned. If no matches are
  335. * found in string, then it will be returned unchanged.
  336. */
  337. <<__Native>>
  338. function eregi_replace(string $pattern,
  339. string $replacement,
  340. string $string): string;
  341. /**
  342. * Split string into array by regular expression
  343. *
  344. * @param string $pattern - Case sensitive regular expression. If you
  345. * want to split on any of the characters which are considered special by
  346. * regular expressions, you'll need to escape them first. If you think
  347. * split() (or any other regex function, for that matter) is doing
  348. * something weird, please read the file regex.7, included in the regex/
  349. * subdirectory of the PHP distribution. It's in manpage format, so
  350. * you'll want to do something along the lines of man
  351. * /usr/local/src/regex/regex.7 in order to read it.
  352. * @param string $string - The input string.
  353. * @param int $limit - If limit is set, the returned array will contain a
  354. * maximum of limit elements with the last element containing the whole
  355. * rest of string.
  356. *
  357. * @return array - Returns an array of strings, each of which is a
  358. * substring of string formed by splitting it on boundaries formed by the
  359. * case-sensitive regular expression pattern. If there are n
  360. * occurrences of pattern, the returned array will contain n+1 items. For
  361. * example, if there is no occurrence of pattern, an array with only one
  362. * element will be returned. Of course, this is also true if string is
  363. * empty. If an error occurs, split() returns FALSE.
  364. */
  365. <<__Native>>
  366. function split(string $pattern,
  367. string $string,
  368. int $limit = -1): mixed;
  369. /**
  370. * Split string into array by regular expression case insensitive
  371. *
  372. * @param string $pattern - Case insensitive regular expression. If you
  373. * want to split on any of the characters which are considered special by
  374. * regular expressions, you'll need to escape them first. If you think
  375. * spliti() (or any other regex function, for that matter) is doing
  376. * something weird, please read the file regex.7, included in the regex/
  377. * subdirectory of the PHP distribution. It's in manpage format, so
  378. * you'll want to do something along the lines of man
  379. * /usr/local/src/regex/regex.7 in order to read it.
  380. * @param string $string - The input string.
  381. * @param int $limit - If limit is set, the returned array will contain a
  382. * maximum of limit elements with the last element containing the whole
  383. * rest of string.
  384. *
  385. * @return array - Returns an array of strings, each of which is a
  386. * substring of string formed by splitting it on boundaries formed by the
  387. * case insensitive regular expression pattern. If there are n
  388. * occurrences of pattern, the returned array will contain n+1 items. For
  389. * example, if there is no occurrence of pattern, an array with only one
  390. * element will be returned. Of course, this is also true if string is
  391. * empty. If an error occurs, spliti() returns FALSE.
  392. */
  393. <<__Native>>
  394. function spliti(string $pattern,
  395. string $string,
  396. int $limit = -1): mixed;
  397. /**
  398. * Make regular expression for case insensitive match
  399. *
  400. * @param string $string - The input string.
  401. *
  402. * @return string - Returns a valid regular expression which will match
  403. * string, ignoring case. This expression is string with each alphabetic
  404. * character converted to a bracket expression; this bracket expression
  405. * contains that character's uppercase and lowercase form. Other
  406. * characters remain unchanged.
  407. */
  408. <<__Native>>
  409. function sql_regcase(string $string): string;