dxml icon indicating copy to clipboard operation
dxml copied to clipboard

stripIndent removes any run of the "right" number of whitespaces

Open MWumpusZ opened this issue 5 years ago • 2 comments

stripIndent(" foo\n\t\tbar")

Results in "foo\nbar"

stripIndent has apparently determined that the ident is "two whitespaces", and will consume such from the beginning of every line of the file - regardless of what kind of whitespace it is.

Almost certainly a very minor corner case, but it still seems incorrect?

MWumpusZ avatar Apr 29 '19 12:04 MWumpusZ

No, stripIndent doesn't care what combination of ' ', '\t', and '\r' is used - only how many whitespace characters there are. It's designed with the idea that for it to have any chance of working reasonably, the text has to be reasonably formatted. If a file does something like mix normal spaces and tabs, then there's pretty much no way that you're going to be able to cleanly strip whitespace. stripIndent could certainly be made to remember exactly what the whitespace was on the first line and only strip that, but I would expect it to be less efficient, and I seriously question that it would actually work well in the general case. If the text isn't cleanly formatted, then the best way to strip the whitespace is going to depend on exactly what was done with that particular document.

I don't know. I can see why someone might want to strip only a specific sequence of whitespace, but stripIndent is doing exactly what it was intended to do, and the assumption from the get-go was that a function like this was only going to have any chance of working if the document was well-formatted.

jmdavis avatar May 03 '19 08:05 jmdavis

Fair enough. For our case, we decided we don't want to do stripIndent at all - at least not in the very general case where we were doing it until now.

MWumpusZ avatar May 06 '19 07:05 MWumpusZ