Module JavaString

module JavaString: sig .. end
Utility functions for Java strings.


OCaml-compatible signature

 
module OCaml: sig .. end
Module providing functions that can be used as drop-in replacements for function from String.
 

String operations

 
type t = java'lang'String java_instance
The type of strings.
 
val char_at : t -> java_int -> java_char
Returns the character at the passed index; see charAt(...).
Raises Java_exception if index is invalid
 
val length : t -> java_int
Returns the length of the passed string; see length(...).
 
val is_empty : t -> bool
Tests whether the passed string is empty; see isEmpty(...).
 
val trim : t -> t
Returns a copy of the passed string, without leading and trailing spaces; see trim(...).
 
val split : t ->
t -> java'lang'String java_instance java_reference_array
split s regexp splits s using regular expression regexp; see split(...).
Raises Java_exception if regexp is invalid
 
val matches : t -> t -> bool
matches s regexp tests whether s matches regular expression regexp; see matches(...).
Raises Java_exception if regexp is invalid
 
val index_of : t -> t -> java_int
index_of s sub returns the index of the first occurrence of sub in s if any, -1l otherwise; see indexOf(...).
 
val last_index_of : t -> t -> java_int
last_index_of s sub returns the index of the last occurrence of sub in s if any, -1l otherwise; see lastIndexOf(...).
 
val starts_with : t -> t -> bool
starts_with s prefix tests whether s starts with prefix; see startsWith(...).
 
val ends_with : t -> t -> bool
ends_with s suffix tests whether s ends with suffix; see endsWith(...).
 
val substring : t -> java_int -> java_int -> t
substring s start_idx end_idx returns the substring of s beginning at index start_idx (inclusive) and ending at index end_idx (exclusive); see substring(...).
 
val to_char_array : t -> java_char java_char_array
Converts the passed string into an array of characters; see toCharArray(...).
 
val to_lower_case : t -> t
Returns a copy of the passed string with all characters converted to lower case; see toLowerCase(...).
 
val to_upper_case : t -> t
Returns a copy of the passed string with all characters converted to upper case; see toUpperCase(...).
 
val equals : t -> t -> bool
Tests whether the passed strings are equal; see equals(...).
 
val equals_ignore_case : t -> t -> bool
Similar to JavaString.equals, but ignoring case when comparing strings; see equalsIgnoreCase(...).
 
val compare_to : t -> t -> java_int
Compares the passed strings; see compareTo(...).
 
val compare_to_ignore_case : t -> t -> java_int
Similar to JavaString.compare_to, but ignoring case when comparing strings; see compareToIgnoreCase(...).
 

Conversion from/to OCaml strings

 
val of_string : string -> java'lang'String java_instance
of_string s converts the OCaml string s into a Java string.
 
val to_string : java'lang'String java_instance -> string
to_string s converts the Java string s into an OCaml string.
Raises Java_exeption if s is null
 

Null value

 
val null : java'lang'String java_instance
The null value.
 
val is_null : java'lang'String java_instance -> bool
is_null x returns true iff x is equal to null.
 
val is_not_null : java'lang'String java_instance -> bool
is_not_null x returns false iff x is equal to null.
 

Output functions

 
val print_string : java'lang'String java_instance -> unit
print_string s prints s onto the standard ouput.
 
val print_endline : java'lang'String java_instance -> unit
print_endline s prints s followed by a newline character onto the standard ouput.
 
val print_newline : unit -> unit
print_newline () prints a newline character onto the standard ouput.
 
val prerr_string : java'lang'String java_instance -> unit
prerr_string s prints s onto the error ouput.
 
val prerr_endline : java'lang'String java_instance -> unit
prerr_endline s prints s followed by a newline character onto the error ouput.
 
val prerr_newline : unit -> unit
prerr_newline () prints a newline character onto the error ouput.
 
val output_string : Pervasives.out_channel -> java'lang'String java_instance -> unit
output_string ch s prints s onto channel ch.
 

Input functions

 
val read_line : unit -> java'lang'String java_instance
read_line () reads a line from the standard input. Returns null when end of input is reached.
 
val input_line : Pervasives.in_channel -> java'lang'String java_instance
input_line ch reads a line from channel ch. Returns null when end of input is reached.
 

Miscellaneous

 
val wrap : java'lang'String java_instance -> java'lang'String java_instance option
wrap x wraps the reference x into an option type:
  • Some x if x is not null;
  • None if x is null.

 
val unwrap : 'a java_instance option -> 'a java_instance
unwrap obj unwraps the option obj into a bare reference:
  • Some x is mapped to x;
  • None is mapped to null.