1. ed.ex Bug/error in function clean(sequence line)
- Posted by K_D_R Jul 15, 2013
- 1239 views
I kept finding the CONTROL_CHAR inserted at the beginning of a blank line in my source code, when loading a dos file. The CONTROL_CHAR remained, even after saving the file after selecting the option to convert the file to LINUX line endings.
function clean(sequence line) -- replace control characters with a graphics character -- Linux: replace CR-LF with LF (for now) integer c if line[$] != '\n' then line &= '\n' end if ifdef UNIX then --if length(line) > 2 and line[$-1] = '\r' then --<= ERROR ? if length(line) > 1 and line[$-1] = '\r' then -- seems to work correctly -- DOS file: remove CR cr_removed = TRUE line = line[1..$-2] & '\n' end if end ifdef for i = 1 to length(line)-1 do c = line[i] if c < SAFE_CHAR and c != '\t' then line[i] = CONTROL_CHAR -- replace with displayable character control_chars = TRUE end if end for return line end function