StdCharList.icl 1021 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
implementation module StdCharList

// ****************************************************************************************
//	Concurrent Clean Standard Library Module Version 2.0
//	Copyright 1995 University of Nijmegen
// ****************************************************************************************

import StdList, StdInt, StdChar

cjustify::!.Int ![.Char] -> .[Char]
cjustify n s = spaces lmargin ++ s ++ spaces rmargin
where
	margin	= n - length s	
	lmargin	= margin / 2	
	rmargin	= margin - lmargin

ljustify::!.Int ![.Char] -> .[Char]
ljustify n s = s ++ spaces (n - length s)

rjustify::!.Int ![.Char] -> [Char]
rjustify n s = spaces (n - length s ) ++ s

flatlines::![[u:Char]] -> [u:Char]
flatlines [a:x]	= a ++ ['\n' : flatlines x]
flatlines []	= []

mklines::![Char] -> [[Char]]
mklines [] 					= []
mklines [a:x] | a == '\n'	= [[]:mklines x]
							= [[a:hd result]:tl result]
where 
	result	=	case x of
 					[]	->	[[]]
					n	->	mklines x
	
spaces::!.Int -> .[Char]
spaces n = repeatn n ' '