UtilNewlinesFile.dcl 1.2 KB
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 38
definition module UtilNewlinesFile

from StdClass import class ==, class toString

:: NewlineConvention
	=	NewlineConventionNone | NewlineConventionMac | NewlineConventionUnix | NewlineConventionDos

HostNativeNewlineConvention	:==	NewlineConventionUnix

instance == NewlineConvention
instance toString NewlineConvention

// read a line with any newline convention
// 	the file should have been opened with mode FReadData
//  the line returned ends with one '\n' (except for the last line)

readAnyLine :: !*File -> (NewlineConvention, !.{#Char}, !*File)

// same as readAnyLine, but discards newline convention (compatible with freadline)

readLine file
	:==	(line, file`)
	where
		(_, line, file`)
			=	readAnyLine file

// write a line with a specified newline convention
//	the first argument is the line
//  	(only the last character of the line is inspected for a newline character,
//		 their shouldn't be any newlines in the middle of the line)
//	the second argument is the newline string
// 	the file should have been opened with mode FWriteData

writeAnyLine :: !{#Char} !{#Char} !*File -> *File

convertLine :: !*{#Char} -> (NewlineConvention, *{#Char})

readConvLines :: !*File -> (NewlineConvention,[String],*File)