StdString.dcl 1.92 KB
Newer Older
1 2
system module StdString

Camil Staps's avatar
Camil Staps committed
3 4 5 6
/**
 * Class instances and basic functions for the String 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
instance ==			{#Char}	:: !{#Char} !{#Char} -> Bool					:== code { .d 2 0 ; jsr eqAC ; .o 0 1 b	}
instance <  		{#Char} :: !{#Char} !{#Char} -> Bool					:== code { .d 2 0 ; jsr cmpAC ; .o 0 1 i ; pushI 0 ; gtI }
16

17
instance fromString	{#Char}	:: !{#Char} -> {#Char}							:== code { no_op }
18

19
instance toString	Int		:: !Int -> {#Char}								:== code { .d 0 1 i ; jsr ItoAC ; .o 1 0 }
20

21
instance toString	Char	:: !Char -> {#Char}								:== code { CtoAC }
22

23
instance toString	Real	:: !Real -> {#Char}								:== code { .d 0 2 r ; jsr RtoAC ; .o 1 0 }
24

25
instance toString	Bool	:: !Bool -> {#Char}								:== code { .d 0 1 b ; jsr BtoAC ; .o 1 0 }
26

27
instance toString	{#Char}	:: !{#Char} -> {#Char}							:== code { no_op }
28

29
instance %			{#Char}	:: !{#Char} !(!Int,!Int) -> {#Char}				:== code { .d 1 2 ii ; jsr sliceAC ; .o 1 0 }
30

31 32
instance +++		{#Char}	:: !{#Char} !{#Char} -> {#Char}					:== code { .d 2 0 ; jsr catAC ; .o 1 0 }
													// string concatenation
33

Camil Staps's avatar
Camil Staps committed
34 35 36 37 38 39 40 41
/**
 * Concatenate two strings with a unique result. This is similar to +++, except
 * that the result type is unique.
 *
 * @param A string
 * @param A string
 * @result The concatenation of the two strings
 */
42
(+++.) infixr 5 :: !{#Char} !{#Char} -> .{#Char}							:== code { .d 2 0 ; jsr catAC ; .o 1 0 }
Camil Staps's avatar
Camil Staps committed
43 44 45 46 47 48 49 50

/**
 * Update a character in a string.
 *
 * @param The string
 * @param A tuple of the index and the new character
 * @result The new string, with the new character on the specified position
 */
51
(:=) infixl 9 :: !{#Char} !(!Int,!Char) -> {#Char}							:== code { .d 1 2 ic ; jsr updateAC ; .o 1 0 }