Blame src/uTF8.mli

rpm-build 0f2925
(* 
rpm-build 0f2925
 * UTF-8 - UTF-8 encoded Unicode string
rpm-build 0f2925
 * Copyright 2002, 2003 (C) Yamagata Yoriyuki. 
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is free software; you can redistribute it and/or
rpm-build 0f2925
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0f2925
 * License as published by the Free Software Foundation; either
rpm-build 0f2925
 * version 2.1 of the License, or (at your option) any later version,
rpm-build 0f2925
 * with the special exception on linking described in file LICENSE.
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is distributed in the hope that it will be useful,
rpm-build 0f2925
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0f2925
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0f2925
 * Lesser General Public License for more details.
rpm-build 0f2925
 *
rpm-build 0f2925
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0f2925
 * License along with this library; if not, write to the Free Software
rpm-build 0f2925
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rpm-build 0f2925
 *)
rpm-build 0f2925
rpm-build 0f2925
(** UTF-8 encoded Unicode strings. 
rpm-build 0f2925
rpm-build 0f2925
   The Module for UTF-8 encoded Unicode strings.
rpm-build 0f2925
*)
rpm-build 0f2925
rpm-build 0f2925
open UChar
rpm-build 0f2925
rpm-build 0f2925
(** UTF-8 encoded Unicode strings. the type is normal string. *)
rpm-build 0f2925
type t = string
rpm-build 0f2925
rpm-build 0f2925
exception Malformed_code
rpm-build 0f2925
rpm-build 0f2925
(** [validate s]
rpm-build 0f2925
   Succeeds if s is valid UTF-8, otherwise raises Malformed_code.
rpm-build 0f2925
   Other functions assume strings are valid UTF-8, so it is prudent
rpm-build 0f2925
   to test their validity for strings from untrusted origins. *)
rpm-build 0f2925
val validate : t -> unit
rpm-build 0f2925
rpm-build 0f2925
(* All functions below assume string are valid UTF-8.  If not,
rpm-build 0f2925
 * the result is unspecified. *)
rpm-build 0f2925
rpm-build 0f2925
(** [get s n] returns [n]-th Unicode character of [s].
rpm-build 0f2925
   The call requires O(n)-time. *)
rpm-build 0f2925
val get : t -> int -> uchar
rpm-build 0f2925
rpm-build 0f2925
(** [init len f] 
rpm-build 0f2925
   returns a new string which contains [len] Unicode characters.
rpm-build 0f2925
   The i-th Unicode character is initialized by [f i] *)
rpm-build 0f2925
val init : int -> (int -> uchar) -> t
rpm-build 0f2925
rpm-build 0f2925
(** [length s] returns the number of Unicode characters contained in s *)
rpm-build 0f2925
val length : t -> int
rpm-build 0f2925
    
rpm-build 0f2925
(** Positions in the string represented by the number of bytes from the head.
rpm-build 0f2925
   The location of the first character is [0] *)
rpm-build 0f2925
type index = int
rpm-build 0f2925
rpm-build 0f2925
(** [nth s n] returns the position of the [n]-th Unicode character. 
rpm-build 0f2925
   The call requires O(n)-time *)
rpm-build 0f2925
val nth : t -> int -> index
rpm-build 0f2925
rpm-build 0f2925
(** The position of the head of the last Unicode character. *)
rpm-build 0f2925
val last : t -> index
rpm-build 0f2925
rpm-build 0f2925
(** [look s i]
rpm-build 0f2925
   returns the Unicode character of the location [i] in the string [s]. *)
rpm-build 0f2925
val look : t -> index -> uchar
rpm-build 0f2925
rpm-build 0f2925
(** [substring s i len] returns the substring made of the Unicode locations [i] to [i + len - 1] inclusive.
rpm-build 0f2925
   The string is always copied *)
rpm-build 0f2925
val substring : t -> int -> int -> t
rpm-build 0f2925
rpm-build 0f2925
(** [out_of_range s i]
rpm-build 0f2925
   tests whether [i] is a position inside of [s]. *)
rpm-build 0f2925
val out_of_range : t -> index -> bool
rpm-build 0f2925
rpm-build 0f2925
(** [compare_index s i1 i2] returns
rpm-build 0f2925
   a value < 0 if [i1] is the position located before [i2], 
rpm-build 0f2925
   0 if [i1] and [i2] points the same location,
rpm-build 0f2925
   a value > 0 if [i1] is the position located after [i2]. *)
rpm-build 0f2925
val compare_index : t -> index -> index -> int
rpm-build 0f2925
rpm-build 0f2925
(** [next s i]
rpm-build 0f2925
   returns the position of the head of the Unicode character
rpm-build 0f2925
   located immediately after [i]. 
rpm-build 0f2925
   If [i] is inside of [s], the function always successes.
rpm-build 0f2925
   If [i] is inside of [s] and there is no Unicode character after [i],
rpm-build 0f2925
   the position outside [s] is returned.  
rpm-build 0f2925
   If [i] is not inside of [s], the behaviour is unspecified. *)
rpm-build 0f2925
val next : t -> index -> index
rpm-build 0f2925
rpm-build 0f2925
(** [prev s i]
rpm-build 0f2925
   returns the position of the head of the Unicode character
rpm-build 0f2925
   located immediately before [i]. 
rpm-build 0f2925
   If [i] is inside of [s], the function always successes.
rpm-build 0f2925
   If [i] is inside of [s] and there is no Unicode character before [i],
rpm-build 0f2925
   the position outside [s] is returned.  
rpm-build 0f2925
   If [i] is not inside of [s], the behaviour is unspecified. *)
rpm-build 0f2925
val prev : t -> index -> index
rpm-build 0f2925
rpm-build 0f2925
(** [move s i n]
rpm-build 0f2925
   returns [n]-th Unicode character after [i] if n >= 0,
rpm-build 0f2925
   [n]-th Unicode character before [i] if n < 0.
rpm-build 0f2925
   If there is no such character, the result is unspecified. *)
rpm-build 0f2925
val move : t -> index -> int -> index
rpm-build 0f2925
    
rpm-build 0f2925
(** [iter f s]
rpm-build 0f2925
   applies [f] to all Unicode characters in [s].  
rpm-build 0f2925
   The order of application is same to the order 
rpm-build 0f2925
   of the Unicode characters in [s]. *)
rpm-build 0f2925
val iter : (uchar -> unit) -> t -> unit
rpm-build 0f2925
rpm-build 0f2925
(** Code point comparison by the lexicographic order.
rpm-build 0f2925
   [compare s1 s2] returns
rpm-build 0f2925
   a positive integer if [s1] > [s2],
rpm-build 0f2925
   0 if [s1] = [s2],
rpm-build 0f2925
   a negative integer if [s1] < [s2]. *)
rpm-build 0f2925
val compare : t -> t -> int
rpm-build 0f2925
rpm-build 0f2925
(** Buffer module for UTF-8 strings *)
rpm-build 0f2925
module Buf : sig
rpm-build 0f2925
  (** Buffers for UTF-8 strings. *) 
rpm-build 0f2925
  type buf
rpm-build 0f2925
rpm-build 0f2925
  (** [create n] creates a buffer with the initial size [n]-bytes. *)   
rpm-build 0f2925
  val create : int -> buf
rpm-build 0f2925
rpm-build 0f2925
  (* The rest of functions is similar to the ones of Buffer in stdlib. *)
rpm-build 0f2925
  (** [contents buf] returns the contents of the buffer. *)
rpm-build 0f2925
  val contents : buf -> t
rpm-build 0f2925
rpm-build 0f2925
  (** Empty the buffer, 
rpm-build 0f2925
     but retains the internal storage which was holding the contents *)
rpm-build 0f2925
  val clear : buf -> unit
rpm-build 0f2925
rpm-build 0f2925
  (** Empty the buffer and de-allocate the internal storage. *)
rpm-build 0f2925
  val reset : buf -> unit
rpm-build 0f2925
rpm-build 0f2925
  (** Add one Unicode character to the buffer. *)
rpm-build 0f2925
  val add_char : buf -> uchar -> unit
rpm-build 0f2925
rpm-build 0f2925
  (** Add the UTF-8 string to the buffer. *)
rpm-build 0f2925
  val add_string : buf -> t -> unit
rpm-build 0f2925
rpm-build 0f2925
  (** [add_buffer b1 b2] adds the contents of [b2] to [b1].
rpm-build 0f2925
     The contents of [b2] is not changed. *)
rpm-build 0f2925
  val add_buffer : buf -> buf -> unit
rpm-build 0f2925
end