mIRC Home    About    Download    Register    News    Help

Print Thread
Case dependent sort flag for sorttok #263509 13/08/18 04:06 PM
Joined: Nov 2004
Posts: 802
Jigsy Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Nov 2004
Posts: 802
I wanted to sort a range of tokens alphabetically depending on their case size.

At the moment a doesn't work because it does this:

Code:
$sorttok(z A b a Z y,32,a) > A a b y z Z


What I'm proposing is something like this:

Code:
$sorttok(z A b a Z y,32,A) > a b y z A Z
$sorttok(z A b a Z y,32,Ar) > Z A z y b a


What do you do at the end of the world? Are you busy? Will you save us?
Re: Case dependent sort flag for sorrtok [Re: Jigsy] #263510 13/08/18 04:16 PM
Joined: Jul 2006
Posts: 3,584
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,584
$sorttokcs is a case sensitive version, did you overlook this one?

//echo -a $sorttokcs(z A b a Z y,32,a)

Edit: your order is not possible to get with $sorttok* though, $sorttok* uses the code point to sort the characterslooks like it's not an oversight, you really want a new option 'A' to get $sorttok* to put the uppercase letters after lowercases, instead of how it is currently: uppercase first.

Last edited by Wims; 13/08/18 06:05 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Case dependent sort flag for sorrtok [Re: Jigsy] #263512 13/08/18 06:02 PM
Joined: Jan 2004
Posts: 1,214
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,214
If you really want to flip the sort order of upper/lower case, you can invert the case of the string, then sort it, then invert the case of the sorted-string.

Code:
alias invert_case return $regsubex( $1- ,/([a-zA-Z])/g, $chr($xor($asc(\t),32)) )

//echo -a $invert_case($sorttokcs($invert_case(z A b a Z y),32,A))

Re: Case dependent sort flag for sorrtok [Re: maroon] #263513 13/08/18 06:29 PM
Joined: Jul 2006
Posts: 3,584
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,584
That's not efficient at all though, you can use one regex match to match all the uppercase at the beginning, capture them and the rest, and replace the match with \2 \1.


//echo -a $regsubex( A Z a b y z ,/^((?:\p{Lu}+ )*\p{Lu}+) (.*)/u,\2 \1)

But I'd say OP is looking for the built-in feature, that he already knows how to workaround it.


Last edited by Wims; 13/08/18 06:29 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Case dependent sort flag for sorrtok [Re: Wims] #263529 15/08/18 02:56 AM
Joined: Feb 2003
Posts: 2,668
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,668
It's going to be long, but $ReplacExCS() is VERY FAST. Faster than $SortTok() or your $RegSubEx().

$replacexcs(%s,A,a,a,A,B,b,b,B,C,c,c,C,D,d,d,D,E,e,e,E,F,f,f,F,G,g,g,G,H,h,h,H,I,i,i,I,J,j,j,J,K,k,k,K,L,l,l,L,M,m,m,M,N,n,n,N,O,o,o,O,P,p,p,P,Q,q,q,Q,R,r,r,R,S,s,s,S,T,t,t,T,U,u,u,U,V,v,v,V,W,w,w,W,X,x,x,X,Y,y,y,Y,Z,z,z,Z)


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: Case dependent sort flag for sorrtok [Re: Raccoon] #263531 15/08/18 03:33 AM
Joined: Jul 2006
Posts: 3,584
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,584
Well that's ok for Latin letters only, if you have to include non Latin letters.... grin


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net