Rex.hx 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C)2005-2018 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package lua.lib.lrexlib;
  23. import haxe.extern.EitherType;
  24. @:luaRequire("rex_pcre")
  25. extern class Rex {
  26. inline public static function create(expr : String, flag : EitherType<Int,String>) : Rex{
  27. return untyped Rex['new'](expr, flag);
  28. }
  29. /**
  30. The function searches for the first match of the regexp `patt` in the
  31. string `subj`, starting from offset `init`, subject to flags `cf` and `ef`.
  32. @return matched string, or array of strings.
  33. **/
  34. public static function match(patt : EitherType<Rex,String>, subj : String, ?init : Int, ?ef : Int) : Dynamic;
  35. /**
  36. The function searches for the first match of the regexp patt in the string
  37. `subj`, starting from offset `init`, subject to flags `cf` and `ef`.
  38. **/
  39. public static function find(patt : EitherType<Rex,String>, subj : String, ?init : Int, ?ef : Int) : Dynamic;
  40. /**
  41. The function is intended for use in the generic for Lua construct. It is
  42. used for splitting a subject string `subj` into parts (sections). The `sep`
  43. parameter is a regular expression pattern representing separators between
  44. the sections.
  45. **/
  46. public static function split( subj : String, sep : EitherType<Rex,String>, ?cf : Int, ?ef : Int) : Void->String;
  47. /**
  48. This function counts matches of the pattern `patt` in the string `subj`.
  49. **/
  50. public static function count(subj : String, patt : EitherType<Rex,String>, cf : Int, ef : Int) : Dynamic;
  51. public static function flags(?tb:Dynamic) : Dynamic;
  52. /**
  53. The function searches for the first match of the regexp in the string
  54. `subj`, starting from offset `init`, subject to execution flags `ef`.
  55. **/
  56. public function tfind(subj : String, ?init : Int, ?ef : Int) : Dynamic;
  57. /**
  58. This function searches for the first match of the regexp in the string
  59. `subj`, starting from offset `init`, subject to execution flags `ef`.
  60. **/
  61. public function exec(subj : String, ?init : Int, ?ef : Int) : Dynamic;
  62. /**
  63. The function is intended for use in the generic for Lua construct. It
  64. returns an iterator for repeated matching of the pattern patt in the
  65. string `subj`, subject to flags `cf` and `ef`.
  66. **/
  67. public static function gmatch(subj : String, patt : EitherType<Rex,String>, ?cf : Int, ?ef : Int) : Void->String;
  68. /**
  69. This function searches for all matches of the pattern `patt` in the string
  70. `subj` and replaces them according to the parameters `repl` and `n`.
  71. **/
  72. public static function gsub(subj : String, patt : EitherType<Rex,String>, repl: Dynamic, ?n: Int, ?cf : Int, ?ef : Int) : String;
  73. }