--
--	Inmos Libraries
--	Copyright (C) 1988, 1989, 1990, 1991, 1993  Inmos Limited
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser General Public
--	License as published by the Free Software Foundation; either
--	version 2 of the License, or (at your option) any later version.
--
--	This library is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library; if not, write to the Free Software
--	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
--

--** @module string

#OPTION "E V" -- no compiler libraries, no vector space
#COMMENT "String library V1.1 01/06/90"
#COMMENT "(c) Copyright INMOS Limited 1988"
--{{{  history
-- V1.0 1-Jul-88
-- Simply made the code more readable in is.hex.digit,
-- to.upper.case, to.lower.case; V1.1 1-Jun-90 SRH
--}}}
--{{{  FUNC is.in.range
--* Determine whether the value of a byte lies in the inclusive range
-- between two others.
--
-- @return TRUE if the value of char lies in the range [value of
--   bottom, value of top]; FALSE otherwise
-- @param char the byte the value of which is to be tested to see
--   whether it lies in a given range
-- @param bottom the lowermost limit of the test range
-- @param top the uppermost limit of the test range
BOOL FUNCTION is.in.range (VAL BYTE char, bottom, top) IS
 ((char >= bottom) AND (char <= top)) :
--}}}
--{{{  FUNC is.upper
--* Determine whether the value of a byte lies in the inclusive range
-- that delimits upper case ASCII characters.
--
-- @return TRUE if the value of char corresponds to an upper case ASCII
--   character; FALSE otherwise
-- @param char the byte the value of which is to be tested
BOOL FUNCTION is.upper (VAL BYTE char) IS ((char >= 'A') AND (char <= 'Z')) :
--}}}
--{{{  FUNC is.lower
--* Determine whether the value of a byte lies in the inclusive range
-- that delimits lower case ASCII characters.
--
-- @return TRUE if the value of char corresponds to a lower case ASCII
--   character; FALSE otherwise
-- @param char the byte the value of which is to be tested
BOOL FUNCTION is.lower (VAL BYTE char) IS ((char >= 'a') AND (char <= 'z')) :
--}}}
--{{{  FUNC is.digit
--* Determine whether the value of a byte lies in the inclusive range
-- that delimits ASCII decimal digits.
--
-- @return TRUE if the value of char corresponds to a decimal digit
--   according to the ASCII code; FALSE otherwise
-- @param char the byte the value of which is to be tested
BOOL FUNCTION is.digit (VAL BYTE char) IS ((char >= '0') AND (char <= '9')) :
--}}}
--{{{  FUNC is.hex.digit
--* Determine whether the value of a byte corresponds to the ASCII
-- value of any hexadecimal digit.
--
-- @return TRUE if the value of char corresponds to a hexadecimal digit
--   according to the ASCII code, where upper or lower case letters are
--   allowed; FALSE otherwise
-- @param char the byte the value of which is to be tested
BOOL FUNCTION is.hex.digit (VAL BYTE char) IS
 ((char >= '0') AND (char <= '9')) OR
 ((char >= 'A') AND (char <= 'F')) OR
 ((char >= 'a') AND (char <= 'f')) :
--}}}
--{{{  FUNC is.id.char
--* Determine whether the value of a byte corresponds to the ASCII code
-- of any legal occam identifier character.
--
-- @return TRUE if the value of char corresponds to the ASCII code of
--   any legal occam identifier character
-- @param char the byte the value of which is to be tested
BOOL FUNCTION is.id.char (VAL BYTE char) IS
    (char = '.') OR
    ((char >= 'a') AND (char <= 'z')) OR
    ((char >= 'A') AND (char <= 'Z')) OR
    ((char >= '0') AND (char <= '9')) :
--}}}
--{{{  PROC to.upper.case
--* Convert all lower case alphabetic characters in a given string to
-- upper case.
--
-- Assumes the ASCII character set. Characters which are not lower case
-- letters remain unchanged.
--
-- @param str the string the lower case characters of which are to be
--   converted to upper case
PROC to.upper.case ([]BYTE str)
  VAL to.upper IS (INT 'A') - (INT 'a') :
  SEQ i = 0 FOR (SIZE str)
    ch IS str[i] :
    IF
      is.lower(ch)
        ch := BYTE ((INT ch) + to.upper)
      TRUE
        SKIP
:
--}}}
--{{{  PROC to.lower.case
--* Convert all upper case alphabetic characters in a given string to
-- lower case.
--
-- Assumes the ASCII character set. Characters which are not upper case
-- letters remain unchanged.
--
-- @param str the string the upper case characters of which are to be
--   converted to lower case
PROC to.lower.case ([]BYTE str)
  VAL to.lower IS (INT 'a') - (INT 'A') :
  SEQ i = 0 FOR (SIZE str)
    ch IS str[i] :
    IF
      is.upper(ch)
        ch := BYTE ((INT ch) + to.lower)
      TRUE
        SKIP
:
--}}}
