StdChar.dcl 3.34 KB
Newer Older
1 2
system module StdChar

Camil Staps's avatar
Camil Staps committed
3 4 5 6
/**
 * Class instances and basic functions for the Char type.
 */

7
// ****************************************************************************************
8 9
//	Concurrent Clean Standard Library Module Version 3.0
//	Copyright 2019 University of Nijmegen
10 11 12 13
// ****************************************************************************************

import	StdOverloaded

14 15 16 17
instance + 				Char	:: !Char !Char -> Char		:== code { addI ; ItoC }
instance - 				Char	:: !Char !Char -> Char		:== code { subI; ItoC }
instance zero 			Char	:: Char						:== code { pushI 0; ItoC }
instance one 			Char	:: Char						:== code { pushI 1; ItoC }
18

19 20
instance ==				Char	:: !Char !Char -> Bool		:== code { eqC }
instance <  			Char	:: !Char !Char -> Bool		:== code { ltC }
21

22 23
instance toChar			Char	:: !Char -> Char			:== code { no_op }
instance toChar			Int		:: !Int -> Char				:== code { ItoC }
24

25 26 27
instance fromChar		Int		:: !Char -> Int				:== code { CtoI }
instance fromChar		Char	:: !Char -> Char			:== code { no_op }
instance fromChar		{#Char}	:: !Char -> {#Char}			:== code { CtoAC }
28 29 30

//	Additional conversions:

Camil Staps's avatar
Camil Staps committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/**
 * Converts a character from ['0'..'9'] to an integer.
 *
 * @param The character
 * @result 0-9 if the character was from ['0'..'9'], otherwise another Int
 */
digitToInt		:: !Char -> Int

/**
 * Converts a character to uppercase.
 *
 * @param The character
 * @result The same character, with bit 5 cleared
 */
toUpper			:: !Char -> Char

/**
 * Converts a character to lowercase.
 *
 * @param The character
 * @result The same character, with bit 5 set
 */
toLower			:: !Char -> Char
54 55 56

//	Tests on Characters:

Camil Staps's avatar
Camil Staps committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
/**
 * Check for uppercase
 *
 * @param The character
 * @result True iff the parameter is from ['A'..'Z']
 */
isUpper			:: !Char -> Bool

/**
 * Check for lowercase
 *
 * @param The character
 * @result True iff the parameter is from ['a'..'z']
 */
isLower			:: !Char -> Bool

/**
 * Check for an alphabetic character
 *
 * @param The character
 * @result True iff the parameter is from ['a'..'z'] ++ ['A'..'Z']
 */
isAlpha			:: !Char -> Bool

/**
 * Check for an alphabetic or numerical character
 *
 * @param The character
 * @result True iff the parameter is from ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9']
 */
isAlphanum		:: !Char -> Bool

/**
 * Check for a numerical character
 *
 * @param The character
 * @result True iff the parameter is from ['0'..'9']
 */
isDigit			:: !Char -> Bool

/**
 * Check for an octal digit
 *
 * @param The character
 * @result True iff the parameter is from ['0'..'7']
 */
isOctDigit		:: !Char -> Bool

/**
 * Check for a hexadecimal digit
 *
 * @param The character
 * @result True iff the parameter is from ['0'..'9'] ++ ['a'..'f'] ++ ['A'..'F']
 */
isHexDigit		:: !Char -> Bool

/**
 * Check for whitespace
 *
 * @param The character
 * @result True iff the parameter is one of ' ', '\t', '\n', '\r', '\f', '\v'
 */
isSpace			:: !Char -> Bool

/**
 * Check for an ASCII control character
 *
 * @param The character
 * @result True iff the parameter is from ['\x00'..'\x1f'] ++ ['\x7f']
 */
isControl		:: !Char -> Bool

/**
 * Check for a printable ASCII character
 *
 * @param The character
 * @result True iff the parameter is from [' '..'~']
 */
isPrint			:: !Char -> Bool

/**
 * Check for a 7-bit ASCII character
 *
 * @param The character
 * @result True iff the integer value of the parameter is less than 128
 */
isAscii			:: !Char -> Bool