File: pcre.sl

package info (click to toggle)
slang2 2.3.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,488 kB
  • sloc: ansic: 101,756; sh: 3,435; makefile: 1,046; pascal: 440
file content (48 lines) | stat: -rw-r--r-- 1,248 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% Copyright (C) 2012-2021,2022 John E. Davis
%
% This file is part of the S-Lang Library and may be distributed under the
% terms of the GNU General Public License.  See the file COPYING for
% more information.
%---------------------------------------------------------------------------
import("pcre");

define pcre_matches ()
{
   variable nargs = _NARGS;
   if (nargs < 2)
     usage ("\
strings = pcre_matches (regexp, str [,pcre_exec_options])\n\
Qualifiers:\n\
  options=0       pcre_compile options if regexp is a string\n\
  offset=0        pcre_exec start matching offset in bytes\n\
";
	   );
   variable re, str, options;
   if (nargs == 2)
     0;
   (re, str, options) = ();
   variable pos = qualifier ("offset", 0);
   if (typeof (re) != PCRE_Type)
     {
	variable compile_options = qualifier ("options", 0);
	re = pcre_compile (re, compile_options);
     }

   variable n = pcre_exec (re, str, pos, options);
   if (n == 0)
     return NULL;

   variable matches = String_Type[n];
   _for (0, n-1, 1)
     {
	variable i = ();
	matches[i] = pcre_nth_substr (re, str, i);
     }
   return matches;
}

$1 = path_concat (path_dirname (__FILE__), "help/pcrefuns.hlp");
if (NULL != stat_file ($1))
  add_doc_file ($1);

provide("pcre");