~ubuntu-branches/ubuntu/trusty/ocamlnet/trusty

« back to all changes in this revision

Viewing changes to src/netstring/netaux.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-09-02 14:12:33 UTC
  • mfrom: (18.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110902141233-zbj0ygxb92u6gy4z
Tags: 3.4-1
* New upstream release
  - add a new NetcgiRequire directive to ease dependency management
    (Closes: #637147)
  - remove patches that were applied upstream:
    + Added-missing-shebang-lines-in-example-shell-scripts
    + Try-also-ocamlc-for-POSIX-threads

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(* $Id: netaux.ml 1003 2006-09-24 15:17:15Z gerd $
 
1
(* $Id: netaux.ml 1588 2011-04-28 13:59:54Z gerd $
2
2
 * ----------------------------------------------------------------------
3
3
 *
4
4
 *)
8
8
  type pattern = { len : int; 
9
9
                   p : string; 
10
10
                   fail : int array;
11
 
                   rex : Pcre.regexp;
 
11
                   rex : Netstring_str.regexp;
12
12
                 }
13
13
 
14
14
  let rec delta pat state c =
19
19
  let make_pattern p =
20
20
    let l = String.length p in
21
21
    if l = 0 then invalid_arg "Netaux.KMP.make_pattern";
22
 
    let rex = Pcre.regexp (Pcre.quote (String.make 1 p.[0])) in
 
22
    let rex = 
 
23
      Netstring_str.regexp (Netstring_str.quote (String.make 1 p.[0])) in
23
24
    let pat = { len = l; p = p; fail = Array.make l 0; rex = rex } in
24
25
    for n = 0 to l - 2 do
25
26
      pat.fail.(n + 1) <- delta pat pat.fail.(n) p.[n]
36
37
        else
37
38
          if state = 0 then
38
39
            (* run_loop 0 (pos+1) *)
39
 
            run_pcre (pos+1)
 
40
            run_regexp (pos+1)
40
41
          else
41
42
            let state' = fail.(state-1) in
42
43
            run_delta p.[state'] state' pos
51
52
          let state' = fail.(state-1) in
52
53
          run_delta p.[state'] state' pos
53
54
 
54
 
    and run_pcre pos =
55
 
      (* Does the same as [run_loop 0 pos], but uses PCRE to skip all the
 
55
    and run_regexp pos =
 
56
      (* Does the same as [run_loop 0 pos], but uses regexps to skip all the
56
57
       * non-matching characters. Improves the speed of bytecode dramatically,
57
58
       * but does not cost very much for native code.
58
59
       *)
62
63
           * but this might lead to problems in multi-threaded programs.
63
64
           * So we don't do it here. Better fix Pcre someday...
64
65
           *)
65
 
          let a = Pcre.pcre_exec ~rex ~pos s in  (* FIXME: no ~len *)
66
 
          a.(0)
 
66
          let p, _ =
 
67
            Netstring_str.search_forward rex s pos in (* FIXME: no ~len *)
 
68
          p
67
69
        with
68
70
            Not_found -> endpos
69
71
      in