mIRC Homepage
Posted By: Jigsy Case dependent sort flag for sorttok - 13/08/18 04:06 PM
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
Posted By: Wims Re: Case dependent sort flag for sorrtok - 13/08/18 04:16 PM
$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.
Posted By: maroon Re: Case dependent sort flag for sorrtok - 13/08/18 06:02 PM
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))
Posted By: Wims Re: Case dependent sort flag for sorrtok - 13/08/18 06:29 PM
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.

Posted By: Raccoon Re: Case dependent sort flag for sorrtok - 15/08/18 02:56 AM
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)
Posted By: Wims Re: Case dependent sort flag for sorrtok - 15/08/18 03:33 AM
Well that's ok for Latin letters only, if you have to include non Latin letters.... grin
© mIRC Discussion Forums