Jump to content


Photo

Sort command bugs out with `r


  • Please log in to reply
4 replies to this topic

#1 Eedis

Eedis
  • Members
  • 1591 posts

Posted 07 October 2012 - 11:11 PM

So I was having some issues with a script while using the Sort command. tidbit finally solved the issue with me after some tinkering on IRC.
When the contents of Genre.txt are:Action
Cartoon
Comedy
Crime
Documentary
Drama
Family
Fantasy
Film Noir
Foreign
Hacker
Horror
Kung Fu
Puzzle
Romantic
Sci Fi
Sport
Thriller
Trilogy
Twistthis script will remove the trailing 't' in the word Twist.
FileRead, GenreCont, %a_desktop%\Genres.txt
CurGenre=Jesus
GenreCont.="`n" CurGenre

Msgbox, % GenreCont
Sort, GenreCont
Msgbox, % GenreCont
But when adding this extra line to remove all of the instances of `r, it works perfectly fine.
FileRead, GenreCont, %a_desktop%\Genres.txt
CurGenre=Jesus
GenreCont.="`n" CurGenre

[color=#BF0000]StringReplace, GenreCont, GenreCont, `r,, ALL[/color]

Msgbox, % GenreCont
Sort, GenreCont
Msgbox, % GenreCont
I'm not sure if this would constitute a bug or not, so remove if you must. If it's not, an explanation at why this little gremlin exists would be grand. :)

Thanks!

#2 tidbit

tidbit
  • Moderators
  • 2283 posts

Posted 08 October 2012 - 02:20 AM

Note:
This happened on AHKL v1.1.08.01 unicode x64.
OS: Win7 64bit

#3 just me

just me
  • Members
  • 1175 posts

Posted 08 October 2012 - 02:22 PM

Behavior confirmed for AHK 1.1.07.01 U32 on WinXP.

Edit: Also confirmed for AHK 1.0.48.05 (latest stable version) on WinXP.

Just another "workaround":
GenreCont .= "[color=#BF0000]`r[/color]`n" . CurGenre


#4 TLM

TLM
  • Members
  • 3586 posts

Posted 09 October 2012 - 05:31 PM

ah I using just me's 'workaround format' pretty much all the time that's why I couldn't reproduce it.
Yep its happening here now too 1.1.08.01 + 1.0.48.05

#5 Lexikos

Lexikos
  • Administrators
  • 8835 posts

Posted 03 November 2012 - 01:43 AM

If the first item ends with `r, all items must end with `r. Aside from the truncation you've noticed, detection of duplicates (option U) relies on the delimiters being consistent. If the input is inconsistent, the output will be inconsistent. Make sense?

I suppose the options are:
  • Leave everything as is, and require that the delimiters are consistent.
  • Fix the truncation, but not the inconsistency with detection of duplicates.
  • Fix the truncation and improve consistency by unconditionally treating `r as part of the item, rather than the delimiter.
  • Treat `r as part of the delimiter, discarding it and arbitrarily deciding whether the output should contain `n or `r`n between each and every item.
Except with the last option, the recommendation would be to always use consistent delimiters. In that case, I'm inclined to assign a very low priority to this issue.

This demonstrates the inconsistency:
v=
(Join
one`r`n
one`r`n
two`n
two
)
Sort v, U
MsgBox % v  ; one, two, two