Fixed string_trim, updated xmlm.ml

This commit is contained in:
John Whitington 2017-06-19 18:00:41 +01:00
parent 26647cdbd3
commit a69d4ee835
2 changed files with 390 additions and 382 deletions

View File

@ -3227,8 +3227,8 @@ let rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
(* For OCaml < 4.00 *)
let string_trim s =
implode
(dropwhile
Pdf.is_whitespace (rev (dropwhile Pdf.is_whitespace (explode s))))
(rev (dropwhile
Pdf.is_whitespace (rev (dropwhile Pdf.is_whitespace (explode s)))))
let combine_with_spaces strs =
string_trim

72
xmlm.ml
View File

@ -1,7 +1,7 @@
(*---------------------------------------------------------------------------
Copyright 2007 Daniel C. Bünzli. All rights reserved.
Distributed under a BSD3 license, see license at the end of the file.
%%NAME%% release %%VERSION%%
Copyright (c) 2007 Daniel C. Bünzli. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
%%NAME%% %%VERSION%%
---------------------------------------------------------------------------*)
module Std_string = String
@ -961,7 +961,7 @@ struct
let make_output ?(decl = true) ?(nl = false) ?(indent = None)
?(ns_prefix = fun _ ->None) d =
let outs, outc = match d with
| `Channel c -> (output c), (output_char c)
| `Channel c -> (output_substring c), (output_char c)
| `Buffer b -> (Std_buffer.add_substring b), (Std_buffer.add_char b)
| `Fun f ->
let os s p l =
@ -1173,35 +1173,43 @@ end
include Make(String) (Buffer)
(* Pretty printers *)
let pp = Format.fprintf
let rec pp_list ?(pp_sep = Format.pp_print_cut) pp_v ppf = function
| [] -> ()
| v :: vs ->
pp_v ppf v; if vs <> [] then (pp_sep ppf (); pp_list ~pp_sep pp_v ppf vs)
let pp_name ppf (p, l) = if p <> "" then pp ppf "%s:%s" p l else pp ppf "%s" l
let pp_attribute ppf (n, v) = pp ppf "@[<1>(%a,@,%S)@]" pp_name n v
let pp_tag ppf (name, atts) =
let pp_sep ppf () = pp ppf ";@ " in
pp ppf "@[<1>(%a,@,@[<1>[%a]@])@]"
pp_name name (pp_list ~pp_sep pp_attribute) atts
let pp_dtd ppf = function
| None -> pp ppf "None"
| Some dtd -> pp ppf "@[<1>(Some@ %S)@]" dtd
let pp_signal ppf = function
| `Data s -> pp ppf "@[`Data %S@]" s
| `El_end -> pp ppf "`El_end"
| `El_start tag -> pp ppf "@[`El_start %a@]" pp_tag tag
| `Dtd dtd -> pp ppf "@[`Dtd %a@]" pp_dtd dtd
(*----------------------------------------------------------------------------
Copyright 2007 Daniel C. Bünzli
All rights reserved.
Copyright (c) 2007 Daniel C. Bünzli
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
3. Neither the name of Daniel C. Bünzli nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------------*)