Community
    • Login

    Cannot sort lines ending with \n or \r only

    Scheduled Pinned Locked Moved General Discussion
    sort linessort bug
    6 Posts 3 Posters 470 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Niente-00N
      Niente-00
      last edited by

      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

      Terry RT 1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R @Niente-00
        last edited by Terry R

        @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 you

        Firstly 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.

        Alan KilbornA 1 Reply Last reply Reply Quote 2
        • Alan KilbornA
          Alan Kilborn @Terry R
          last edited by

          @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.

          1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn
            last edited by Alan Kilborn

            THIS is also a comment by @Niente-00 on this subject.

            1 Reply Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn
              last edited by

              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.

              1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn
                last edited by

                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.

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors