diff options
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/format.mli | 8 | ||||
-rw-r--r-- | stdlib/genlex.mli | 5 | ||||
-rw-r--r-- | stdlib/lazy.ml | 12 | ||||
-rw-r--r-- | stdlib/lazy.mli | 22 | ||||
-rw-r--r-- | stdlib/marshal.ml | 1 | ||||
-rw-r--r-- | stdlib/scanf.ml | 31 | ||||
-rw-r--r-- | stdlib/stdLabels.mli | 1 | ||||
-rw-r--r-- | stdlib/string.ml | 21 | ||||
-rw-r--r-- | stdlib/string.mli | 6 | ||||
-rw-r--r-- | stdlib/stringLabels.mli | 15 | ||||
-rw-r--r-- | stdlib/sys.mli | 3 | ||||
-rw-r--r-- | stdlib/sys.mlp | 4 |
12 files changed, 95 insertions, 34 deletions
diff --git a/stdlib/format.mli b/stdlib/format.mli index c8146d747..f660b1f24 100644 --- a/stdlib/format.mli +++ b/stdlib/format.mli @@ -631,13 +631,19 @@ val fprintf : formatter -> ('a, formatter, unit) format -> 'a;; For more details about tags, see the functions [open_tag] and [close_tag]. - [@\}]: close the most recently opened tag. - - [@@]: print a plain [@] character. - [@%]: print a plain [%] character. Example: [printf "@[%s@ %d@]@." "x =" 1] is equivalent to [open_box (); print_string "x ="; print_space (); print_int 1; close_box (); print_newline ()]. It prints [x = 1] within a pretty-printing box. + + Note: the old [@@] ``pretty-printing indication'' is now deprecated, since + it had no pretty-printing indication semantics. If you need to prevent + the pretty-printing indication interpretation of a [@] character, simply + use the regular way to escape a character in format string: write [%@]. + @since 3.12.2. + *) val printf : ('a, formatter, unit) format -> 'a;; diff --git a/stdlib/genlex.mli b/stdlib/genlex.mli index 41ce68d0f..b1098f097 100644 --- a/stdlib/genlex.mli +++ b/stdlib/genlex.mli @@ -37,6 +37,11 @@ [< 'Kwd "+"; n2 = parse_expr >] -> n1+n2 | ... ]} + + One should notice that the use of the [parser] keyword and associated + notation for streams are only available through camlp4 extensions. This + means that one has to preprocess its sources {i e. g.} by using the + ["-pp"] command-line switch of the compilers. *) (** The type of tokens. The lexical classes are: [Int] and [Float] diff --git a/stdlib/lazy.ml b/stdlib/lazy.ml index 359fcaa63..6a114245e 100644 --- a/stdlib/lazy.ml +++ b/stdlib/lazy.ml @@ -57,13 +57,13 @@ external force : 'a t -> 'a = "%lazy_force";; let force_val = CamlinternalLazy.force_val;; -let lazy_from_fun (f : unit -> 'arg) = +let from_fun (f : unit -> 'arg) = let x = Obj.new_block Obj.lazy_tag 1 in Obj.set_field x 0 (Obj.repr f); (Obj.obj x : 'arg t) ;; -let lazy_from_val (v : 'arg) = +let from_val (v : 'arg) = let t = Obj.tag (Obj.repr v) in if t = Obj.forward_tag || t = Obj.lazy_tag || t = Obj.double_tag then begin make_forward v @@ -72,4 +72,10 @@ let lazy_from_val (v : 'arg) = end ;; -let lazy_is_val (l : 'arg t) = Obj.tag (Obj.repr l) <> Obj.lazy_tag;; +let is_val (l : 'arg t) = Obj.tag (Obj.repr l) <> Obj.lazy_tag;; + +let lazy_from_fun = from_fun;; + +let lazy_from_val = from_val;; + +let lazy_is_val = is_val;; diff --git a/stdlib/lazy.mli b/stdlib/lazy.mli index 4a3b5df0f..4a4419c22 100644 --- a/stdlib/lazy.mli +++ b/stdlib/lazy.mli @@ -62,15 +62,23 @@ val force_val : 'a t -> 'a;; whether [force_val x] raises the same exception or [Undefined]. *) -val lazy_from_fun : (unit -> 'a) -> 'a t;; -(** [lazy_from_fun f] is the same as [lazy (f ())] but slightly more - efficient. *) +val from_fun : (unit -> 'a) -> 'a t;; +(** [from_fun f] is the same as [lazy (f ())] but slightly more efficient. *) -val lazy_from_val : 'a -> 'a t;; -(** [lazy_from_val v] returns an already-forced suspension of [v] +val from_val : 'a -> 'a t;; +(** [from_val v] returns an already-forced suspension of [v]. This is for special purposes only and should not be confused with [lazy (v)]. *) -val lazy_is_val : 'a t -> bool;; -(** [lazy_is_val x] returns [true] if [x] has already been forced and +val is_val : 'a t -> bool;; +(** [is_val x] returns [true] if [x] has already been forced and did not raise an exception. *) + +val lazy_from_fun : (unit -> 'a) -> 'a t;; +(** @deprecated synonym for [from_fun]. *) + +val lazy_from_val : 'a -> 'a t;; +(** @deprecated synonym for [from_val]. *) + +val lazy_is_val : 'a t -> bool;; +(** @deprecated synonym for [is_val]. *) diff --git a/stdlib/marshal.ml b/stdlib/marshal.ml index c42851504..638f05434 100644 --- a/stdlib/marshal.ml +++ b/stdlib/marshal.ml @@ -16,6 +16,7 @@ type extern_flags = No_sharing | Closures +(* note: this type definition is used in 'byterun/debugger.c' *) external to_channel: out_channel -> 'a -> extern_flags list -> unit = "caml_output_value" diff --git a/stdlib/scanf.ml b/stdlib/scanf.ml index 9c6ecef62..37740765d 100644 --- a/stdlib/scanf.ml +++ b/stdlib/scanf.ml @@ -1111,7 +1111,7 @@ let make_char_bit_vect bit set = ;; (* Compute the predicate on chars corresponding to a char set. *) -let make_pred bit set stp = +let make_predicate bit set stp = let r = make_char_bit_vect bit set in List.iter (fun c -> set_bit_of_range r (int_of_char c) (bit_not bit)) stp; @@ -1131,9 +1131,9 @@ let make_setp stp char_set = (fun c -> if c == p1 || c == p2 then 1 else 0) | 3 -> let p1 = set.[0] and p2 = set.[1] and p3 = set.[2] in - if p2 = '-' then make_pred 1 set stp else + if p2 = '-' then make_predicate 1 set stp else (fun c -> if c == p1 || c == p2 || c == p3 then 1 else 0) - | _ -> make_pred 1 set stp + | _ -> make_predicate 1 set stp end | Neg_set set -> begin match String.length set with @@ -1146,9 +1146,9 @@ let make_setp stp char_set = (fun c -> if c != p1 && c != p2 then 1 else 0) | 3 -> let p1 = set.[0] and p2 = set.[1] and p3 = set.[2] in - if p2 = '-' then make_pred 0 set stp else + if p2 = '-' then make_predicate 0 set stp else (fun c -> if c != p1 && c != p2 && c != p3 then 1 else 0) - | _ -> make_pred 0 set stp + | _ -> make_predicate 0 set stp end ;; @@ -1335,18 +1335,10 @@ let scan_format ib ef fmt rv f = let rec scan_fmt ir f i = if i > lim then ir, f else match Sformat.unsafe_get fmt i with - | ' ' -> skip_whites ib; scan_fmt ir f (succ i) | '%' -> scan_skip ir f (succ i) - | '@' -> skip_indication ir f (succ i) + | ' ' -> skip_whites ib; scan_fmt ir f (succ i) | c -> check_char ib c; scan_fmt ir f (succ i) - and skip_indication ir f i = - if i < lim then - match Sformat.unsafe_get fmt i with - | '@' | '%' as c -> check_char ib c; scan_fmt ir f (succ i) - | c -> check_char ib c; scan_fmt ir f i - else incomplete_format fmt - and scan_skip ir f i = if i > lim then ir, f else match Sformat.get fmt i with @@ -1393,6 +1385,12 @@ let scan_format ib ef fmt rv f = | '%' | '@' as c -> check_char ib c; scan_fmt ir f (succ i) + | '!' -> + if not (Scanning.end_of_input ib) + then bad_input "end of input not found" else + scan_fmt ir f (succ i) + | ',' -> + scan_fmt ir f (succ i) | 's' -> let i, stp = scan_indication (succ i) in let _x = scan_string stp width ib in @@ -1451,11 +1449,6 @@ let scan_format ib ef fmt rv f = | _ -> scan_fmt ir (stack f (token_int64 conv1 ib)) (succ i) end (* This is not an integer conversion, but a regular %l, %n or %L. *) | _ -> scan_fmt ir (stack f (get_count conv0 ib)) i end - | '!' -> - if Scanning.end_of_input ib then scan_fmt ir f (succ i) - else bad_input "end of input not found" - | ',' -> - scan_fmt ir f (succ i) | '(' | '{' as conv (* ')' '}' *) -> let i = succ i in (* Find the static specification for the format to read. *) diff --git a/stdlib/stdLabels.mli b/stdlib/stdLabels.mli index cb1ba01a4..1360081a2 100644 --- a/stdlib/stdLabels.mli +++ b/stdlib/stdLabels.mli @@ -117,6 +117,7 @@ module String : unit val concat : sep:string -> string list -> string val iter : f:(char -> unit) -> string -> unit + val trim : string -> string val escaped : string -> string val index : string -> char -> int val rindex : string -> char -> int diff --git a/stdlib/string.ml b/stdlib/string.ml index 7eafec02f..f3906f353 100644 --- a/stdlib/string.ml +++ b/stdlib/string.ml @@ -85,6 +85,27 @@ external is_printable: char -> bool = "caml_is_printable" external char_code: char -> int = "%identity" external char_chr: int -> char = "%identity" +let is_space = function + | ' ' | '\012' | '\n' | '\r' | '\t' -> true + | _ -> false + +let trim s = + let len = length s in + let i = ref 0 in + while !i < len && is_space (unsafe_get s !i) do + incr i + done; + let j = ref (len - 1) in + while !j >= !i && is_space (unsafe_get s !j) do + decr j + done; + if !i = 0 && !j = len - 1 then + s + else if !j >= !i then + sub s !i (!j - !i + 1) + else + "" + let escaped s = let n = ref 0 in for i = 0 to length s - 1 do diff --git a/stdlib/string.mli b/stdlib/string.mli index d1ae9356b..2405ac6ad 100644 --- a/stdlib/string.mli +++ b/stdlib/string.mli @@ -132,6 +132,12 @@ val map : (char -> char) -> string -> string the characters of [s] and stores the results in a new string that is returned. *) +val trim : string -> string +(** Return a copy of the argument, without leading and trailing whitespace. + The characters regarded as whitespace are: [' '], ['\012'], ['\n'], + ['\r'], and ['\t']. If there is no whitespace character in the argument, + return the original string itself, not a copy. *) + val escaped : string -> string (** Return a copy of the argument, with special characters represented by escape sequences, following the lexical diff --git a/stdlib/stringLabels.mli b/stdlib/stringLabels.mli index 5a17c67da..84f618be2 100644 --- a/stdlib/stringLabels.mli +++ b/stdlib/stringLabels.mli @@ -86,11 +86,22 @@ val iter : f:(char -> unit) -> string -> unit val iteri : f:(int -> char -> unit) -> string -> unit (** Same as {!String.iter}, but the - function is applied to the index of the element as first argument (counting from 0), - and the character itself as second argument. + function is applied to the index of the element as first argument + (counting from 0), and the character itself as second argument. @since 3.13.0 *) +val map : f:(char -> char) -> string -> string +(** [String.map f s] applies function [f] in turn to all + the characters of [s] and stores the results in a new string that + is returned. *) + +val trim : string -> string +(** Return a copy of the argument, without leading and trailing whitespace. + The characters regarded as whitespace are: [' '], ['\012'], ['\n'], + ['\r'], and ['\t']. If there is no whitespace character in the argument, + return the original string itself, not a copy. *) + val escaped : string -> string (** Return a copy of the argument, with special characters represented by escape sequences, following the lexical diff --git a/stdlib/sys.mli b/stdlib/sys.mli index 4913bef8e..b127bc00b 100644 --- a/stdlib/sys.mli +++ b/stdlib/sys.mli @@ -84,6 +84,9 @@ val word_size : int (** Size of one word on the machine currently executing the OCaml program, in bits: 32 or 64. *) +val big_endian : bool +(** Whether the machine currently executing the Caml program is big-endian. *) + val max_string_length : int (** Maximum length of a string. *) diff --git a/stdlib/sys.mlp b/stdlib/sys.mlp index b83cbb287..c7271794d 100644 --- a/stdlib/sys.mlp +++ b/stdlib/sys.mlp @@ -19,11 +19,11 @@ (* System interface *) -external get_config: unit -> string * int = "caml_sys_get_config" +external get_config: unit -> string * int * bool = "caml_sys_get_config" external get_argv: unit -> string * string array = "caml_sys_get_argv" let (executable_name, argv) = get_argv() -let (os_type, word_size) = get_config() +let (os_type, word_size, big_endian) = get_config() let max_array_length = (1 lsl (word_size - 10)) - 1;; let max_string_length = word_size / 8 * max_array_length - 1;; |