Cannot sort lines ending with \n or \r only
-
Hi, I cannot sort lines terminating with just the “\n” or “\r” characters.
If they end with “\r\n” the sort command works correctly.
Could you please fix this?
Thank you -
@niente-00 said in Cannot sort lines ending with \n or \r only:
Hi, I cannot sort lines terminating with just the “\n” or “\r” characters.
If they end with “\r\n” the sort command works correctly.
Could you please fix this?
Thank youFirstly we (as in forum members) cannot fix this, we are just users trying to help other users.
Secondly I don’t think it is broken. There was a post here talking about the same thing. There was a post from @PeterJones that shows it working at the bottom of the first page of that thread.
Confirm that you don’t have mixed line endings. You could use the built-in function to change line endings (EOL Conversion under Edit menu), rotating through all three options back to your preferred one. See if that seems to solve your issue.
Terry
PS I should add that when reporting a bug, here is a good place to start as often members can confirm the issue, or supply how it really works. But to really report a bug to the developer, please read the FAQ section on where that report needs to go, but it isn’t in this forum sorry.
-
@terry-r said in Cannot sort lines ending with \n or \r only:
I don’t think it is broken
Opinions vary on this.
See HERE.
The real problem might be, that line-endings that don’t match a file’s setting (per what is shown in the status bar), are allowed to be in a file. Meaning that if this situation was not allowed to exist, sorting would not have a problem.
On the other hand, restricting line-endings to be of one type may be limiting to some users. I don’t know of a use-case for mixed line-endings, but there probably are some.
-
THIS is also a comment by @Niente-00 on this subject.
-
Sorting happens HERE in the Notepad++ source code.
The data is divided into a sortable list of lines based on the current end-of-line setting with this:
std::vector<generic_string> splitText = stringSplit(text, getEOLString());
Looking into the stringSplit function, we can see that the lines of a file are decided based upon exactly and only the single line-ending type that is the file’s end-of-line type:
std::vector<generic_string> stringSplit(const generic_string& input, const generic_string& delimiter) { size_t start = 0U; size_t end = input.find(delimiter); std::vector<generic_string> output; const size_t delimiterLength = delimiter.length(); while (end != std::string::npos) { output.push_back(input.substr(start, end - start)); start = end + delimiterLength; end = input.find(delimiter, start); } output.push_back(input.substr(start, end)); return output; }
For the OP’s desire to happen, a new version of the stringSplit function would be needed to where the 3 types of possible line-endings are looked for, and then the exact line-ending of every given line would need to be retained (at the end of each string) in the list of strings generated by the function.
-
I made a suggestion for a replacement function for
stringSplit()
, to allow proper handling of mixed line-endings in the sort, but I did it HERE rather than, well, here.