DEFINITION MODULE strUtils;

CONST 
  whitespace = ' \t\n\r\v\f';
  asciiLowercase = 'abcdefghijklmnopqrstuvwxyz';
  asciiUppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  asciiLetters = asciiLowercase + asciiUppercase;
  digits = '0123456789';
  hexdigits = digits + 'abcdef' + 'ABCDEF';
  octdigits = '01234567';
  punctuation = "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~" + '#';
  printable = digits + asciiLetters + punctuation + whitespace;
  alphanum = asciiLetters + digits;

(* pythonlike functions 
isalnum()	Returns True if all characters in the string are alphanumeric
isalpha()	Returns True if all characters in the string are in the alphabet
isascii()	Returns True if all characters in the string are ascii characters
isdigit()	Returns True if all characters in the string are digits
isidentifier()	Returns True if the string is an identifier
islower()	Returns True if all characters in the string are lower case
isprintable()	Returns True if all characters in the string are printable
isspace()	Returns True if all characters in the string are whitespaces
istitle() 	Returns True if the string follows the rules of a title
isupper()	Returns True if all characters in the string are upper case
*)

PROCEDURE isalnum(s : ARRAY OF CHAR) : BOOLEAN;	
(* Returns True if all characters in the string are alphanumeric*)

PROCEDURE isalpha(s : ARRAY OF CHAR) : BOOLEAN;	
(* Returns True if all characters in the string are in the alphabet *)

PROCEDURE isascii(s : ARRAY OF CHAR) : BOOLEAN;	
(* Returns True if all characters in the string are ascii characters *)

PROCEDURE isdigit(s : ARRAY OF CHAR) : BOOLEAN;	
(* Returns True if all characters in the string are digits *)
(* there is a dedicated procedure in CharClass for that *)

PROCEDURE isidentifier(s : ARRAY OF CHAR) : BOOLEAN;
(* Returns True if the string is an identifier *)

PROCEDURE islower(s : ARRAY OF CHAR) : BOOLEAN;	
(* 	eturns True if all characters in the string are lower case *)
(* there is a dedicated procedure in CharClass for that *)

PROCEDURE isprintable(s : ARRAY OF CHAR) : BOOLEAN;
(* Returns True if all characters in the string are printable *)

PROCEDURE isspace(s : ARRAY OF CHAR) : BOOLEAN;	
(* Returns True if all characters in the string are whitespaces *)
(* there is a dedicated procedure in CharClass for that *)

PROCEDURE istitle(s : ARRAY OF CHAR) : BOOLEAN;	
(*  Returns True if the string follows the rules of a title *)

PROCEDURE isupper(s : ARRAY OF CHAR) : BOOLEAN;	
(* Returns True if all characters in the string are upper case *)
(* there is a dedicated procedure in CharClass for that *)

(* end of python alike functions *)


(* this function copied from ooc source and may be considered a duplicate. *)
 PROCEDURE Compare (stringVal1, stringVal2: ARRAY OF CHAR): INTEGER ;
(**Returns @oconst{less}, @oconst{equal}, or @oconst{greater}, according as
   @oparam{stringVal1} is lexically less than, equal to, or greater than
   @oparam{stringVal2}.  Note that Oberon-2 and Oberon-07 already contains predefined comparison operators on strings.  *)
   
PROCEDURE Copy(VAR Ns: ARRAY OF CHAR; S: ARRAY OF CHAR);

(* this function copied from ooc source and may be considered a duplicate. *)
PROCEDURE Assign (source: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR);
(**Copies @oparam{source} to @oparam{destination}.  Equivalent to the
   predefined procedure @code{COPY}.  Unlike @code{COPY}, this procedure can be
   assigned to a procedure variable.  *)


PROCEDURE Pos (substr : CHAR ; s : ARRAY OF CHAR; n : CARDINAL ) : CARDINAL ;

PROCEDURE RemoveLeftChars (VAR s : ARRAY OF CHAR; ch : CHAR);

PROCEDURE RemoveRightChars (VAR s : ARRAY OF CHAR; ch : CHAR);

PROCEDURE WordCount (source : ARRAY OF CHAR; separator : CHAR) : CARDINAL ;

PROCEDURE NumberOfChar (s : ARRAY OF CHAR; ch : CHAR) : CARDINAL ;

PROCEDURE Rpos ( s : ARRAY OF CHAR ; ch : CHAR) : CARDINAL ;

PROCEDURE Lpos ( s : ARRAY OF CHAR ; ch : CHAR) : CARDINAL;

PROCEDURE copyBytes(VAR src, dst: ARRAY OF CHAR; start, quantity: CARDINAL );
(*
PROCEDURE appendNumChars(VAR extra: pstring; extraNum: LONGINT; VAR destination: pstring; destinationNum: LONGINT);

PROCEDURE string2pstring(s: ARRAY OF CHAR; VAR d : pstring);

PROCEDURE string2pstrings(VAR text: ARRAY OF CHAR): pstrings;

PROCEDURE ExtractWord (n : INTEGER; s : ARRAY OF CHAR; ch : CHAR) : pstring;

PROCEDURE tokenize(s : ARRAY OF CHAR; ch : CHAR) : pstrings;

*)
(* copies all array, even after 0X, but puts 0X in the end *)
PROCEDURE copyAll (src : ARRAY OF CHAR ; VAR dst : ARRAY OF CHAR);


(** fills whole array with zeroes, useful when one needs to get several strings which contain characters < ' ' and not necessarily end with 0X *)
PROCEDURE zeroStr(VAR str: ARRAY OF CHAR);

PROCEDURE appendLFCR(VAR str: ARRAY OF CHAR);
(*
PROCEDURE findChar(ch: CHAR; VAR line: ARRAY OF CHAR; VAR b: BOOLEAN; VAR pos: INTEGER);

(* cuts line, takes the part till the eol *)
PROCEDURE cutLine(VAR src, dst: ARRAY OF CHAR);

(* put 0X after eol in the string *)
PROCEDURE terminateLine(VAR str: ARRAY OF CHAR);

PROCEDURE getTillEOL(VAR src: ARRAY OF CHAR; spos: INTEGER; VAR dst: ARRAY OF CHAR); (* actually get till any character < ' ' *)

(* get next word starting from spos till the ' ' *)
PROCEDURE getNextWord(VAR src: ARRAY OF CHAR; spos: INTEGER; VAR dst: ARRAY OF CHAR);

PROCEDURE getNextAlphaNumWord(VAR src: ARRAY OF CHAR; spos: INTEGER; VAR dst: ARRAY OF CHAR);

PROCEDURE contains (VAR line : ARRAY OF CHAR; pattern: ARRAY OF CHAR): BOOLEAN;

PROCEDURE contains1(VAR line: ARRAY OF CHAR; pat : ARRAY OF CHAR): BOOLEAN;

(* IntToStr routine taken from
https://github.com/romiras/Oberon-F-components/blob/master/Ott/Mod/IntStr.cp
and modified to work on 64bit system by dcwbrown,
in order to avoid using oocIntStr, which has many dependencies *)
PROCEDURE Reverse0 (VAR str : ARRAY OF CHAR; start, end : INTEGER);
(* Reverses order of characters in the interval [start..end]. *)


PROCEDURE dumpChars(VAR s : ARRAY OF CHAR);

PROCEDURE dumpAllChars(VAR s : ARRAY OF CHAR);
*)
END strUtils.
