~ubuntu-branches/ubuntu/jaunty/pxp/jaunty

« back to all changes in this revision

Viewing changes to src/pxp-engine/pxp_lib_ocamlopt.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2002-03-27 20:47:53 UTC
  • Revision ID: james.westby@ubuntu.com-20020327204753-1lmazhm839pz62pq
Tags: upstream-1.1.4
ImportĀ upstreamĀ versionĀ 1.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* $Id: pxp_lib_ocamlopt.ml,v 1.2 2001/01/13 22:48:15 gerd Exp $
 
2
 * ----------------------------------------------------------------------
 
3
 * PXP: The polymorphic XML parser for Objective Caml.
 
4
 * Copyright by Gerd Stolpmann. See LICENSE for details.
 
5
 *)
 
6
 
 
7
(* WARNING: This file is pxp_lib_ocamlopt.ml *)
 
8
 
 
9
(* Functions optimized for the native code compiler *)
 
10
 
 
11
let rec index_rec s i =
 
12
  let s_i = String.unsafe_get s i in
 
13
  if s_i = '\010' or s_i = '\013'
 
14
  then i
 
15
  else index_rec s (i+1)
 
16
;;
 
17
 
 
18
let rec index_lim_rec s lim i =
 
19
  if i >= lim then -1 else
 
20
    let s_i = String.unsafe_get s i in
 
21
    if s_i = '\010' or s_i = '\013'
 
22
    then i
 
23
    else index_lim_rec s lim (i+1)
 
24
;;
 
25
 
 
26
let crlf_index_from s i =
 
27
  let lim = String.length s in
 
28
  assert (i>=0 && i <= lim);
 
29
  if lim = 0 || i = lim then
 
30
    -1
 
31
  else if lim <= 9 then begin
 
32
    index_lim_rec s lim i
 
33
  end
 
34
  else begin
 
35
    let c = String.unsafe_get s (lim-1) in
 
36
    String.unsafe_set s (lim-1) '\010';
 
37
    let k = index_rec s i in
 
38
    String.unsafe_set s (lim-1) c;
 
39
    if k = lim-1 then begin
 
40
      if c = '\010' then
 
41
        k
 
42
      else
 
43
        -1
 
44
    end
 
45
    else
 
46
      k
 
47
  end
 
48
;;
 
49
 
 
50
exception Found;;
 
51
 
 
52
let only_whitespace s =
 
53
  let l = String.length s in
 
54
  try
 
55
    for i=0 to l - 1 do
 
56
      match String.unsafe_get s i with
 
57
          ('\009'|'\010'|'\013'|'\032') -> ()
 
58
        | _ ->
 
59
            raise Found
 
60
    done;
 
61
    true
 
62
  with
 
63
      Found -> false
 
64
;;
 
65
 
 
66
(* ======================================================================
 
67
 * History:
 
68
 *
 
69
 * $Log: pxp_lib_ocamlopt.ml,v $
 
70
 * Revision 1.2  2001/01/13 22:48:15  gerd
 
71
 *      Fix: Avoid that array indexes get out of bounds
 
72
 *
 
73
 * Revision 1.1  2000/10/01 19:50:29  gerd
 
74
 *      Initial revision.
 
75
 *
 
76
 *)