From WikiChip
Difference between revisions of "mirc/identifiers/$sorttok"
< mirc‎ | identifiers

(Add'l example and detail)
Line 8: Line 8:
  
 
* '''<list>''' - The list of tokens (can be empty)
 
* '''<list>''' - The list of tokens (can be empty)
* '''<C>''' - The ascii number (or code point) of the character seperating the tokens
+
* '''<C>''' - The ascii number (or code point) of the character separating the tokens
 
* '''ncra''' - default is alphabetical sort (ASCII order) if 3rd parameter not used, n = numeric sort; c = channel prefix sort; r = reverse; a = ASCII sort
 
* '''ncra''' - default is alphabetical sort (ASCII order) if 3rd parameter not used, n = numeric sort; c = channel prefix sort; r = reverse; a = ASCII sort
  
 
Note: 'a' sort is case-insensitive. For case-insensitive use $sorttokcs
 
Note: 'a' sort is case-insensitive. For case-insensitive use $sorttokcs
 +
Note: 'n' sort makes no attempt to sort non-numerics, so using the numeric sort in $sorttokcs has no effect.
  
 
== Properties ==
 
== Properties ==
Line 28: Line 29:
 
</source>
 
</source>
  
 +
Note: the above NumericMax assumes the input already contains only numbers, because in a numeric sort, non-numeric is treated as if zero, and is sorted between the positives vs the negative numbers. It appears that, except for stripping the negative from the front, it evaluates each token individually the same was as evaluated by $abs().<br />
 +
 +
This means non-numerics are chopped from the end of the token if it begins with a number, though it treats 'e' or 'E' as potentially being part of a number in scientific notation. Tokens 2+2 or +2*2 or 2-2 are treated the same as '2' because that's the number prior to encountering a non-numeric. All tokens which evaluate to the same number appear to always be left together in the order they appear in the input, so $sorttok(64 64.0,32,n) and $sorttok(64.0 64,32,n) both return an unchanged string.
 +
 +
<source lang="mIRC">
 +
//var %a $regsubex($str(x,94),/x/g,$chr($calc(32+ \n)) $chr(32)) | echo -a $sorttokcs(11 -11 -1 1 +1 -2 2 $true $false $true -x1xa 0 $false +2*2 0 0.0 %a 5-1 5-11 5-2 2+2 =4 101 99 1E2xx $false 0.1,32,n)
 +
 +
Returns: -11 -2 -1 $true $false $true -x1xa 0 $false 0 0.0 ! " # $ % & ' ( ) * + , - . / 0 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ =4 $false 0.1 1 +1 1 2 +2*2 2 2+2 3 4 5 5-1 5-11 5-2 6 7 8 9 11 99 1E2xx 101
 +
</source>
 +
 +
Note: The first $true through the last $false appear in the same order as in the input because they all evaluate as zero. The same happens to the several tokens which all evaluate as 2 or 5. 1E2xx sorts between 99 and 101 because it evaluates 1E2 as scientific notation for 100.
 +
 +
Note: The 'r' switch is a modifier which reverses the direction of the sort for the anc sort orders. For numeric sort, it does not always put the tokens into inverse order. It only changes the direction of the sort after each token has been evaluated to its numeric equivalent. Using 'r' by itself is the same as 'ar' because 'a' is the default sort order.
 +
 +
Note: changing the sort order from 'n' to 'c' changes the output to an ASCII order sort, except that tokens beginning with any of the channel prefix symbols are sorted to the front. These prefixes are shown by the $prefix identifier, so the above display will be different in a blank status window created with "/server -n" that it would be at a network which recognizes ~ and & as nick prefixes.
 
== Compatibility ==
 
== Compatibility ==
 
{{mIRC compatibility|4.7}}
 
{{mIRC compatibility|4.7}}
 
 
== See also ==
 
== See also ==
 
* {{mIRC|$addtok}}
 
* {{mIRC|$addtok}}
Line 44: Line 59:
 
* {{mIRC|$reptok}}
 
* {{mIRC|$reptok}}
 
* {{mIRC|$wildtok}}
 
* {{mIRC|$wildtok}}
{{mIRC identifier list}}
 
 
[[Category:mIRC identifiers|sorttok]]
 

Revision as of 13:21, 9 November 2018

$sorttok sorts the tokens in text. $sorttokcs is the case sensitive version

Synopsis

$sorttok(<list>,C[,nrca])
$sorttokcs(<list>,C[,nrca])

Parameters

  • <list> - The list of tokens (can be empty)
  • <C> - The ascii number (or code point) of the character separating the tokens
  • ncra - default is alphabetical sort (ASCII order) if 3rd parameter not used, n = numeric sort; c = channel prefix sort; r = reverse; a = ASCII sort

Note: 'a' sort is case-insensitive. For case-insensitive use $sorttokcs Note: 'n' sort makes no attempt to sort non-numerics, so using the numeric sort in $sorttokcs has no effect.

Properties

None

Example

//echo -a $sorttok(C a c b A B,32,a)
 
//echo -a Sorted in ASCII order: $sorttok( $chr(10004) $chr(9650) $chr(9660) , 32)
alias NumericMax {
  return $gettok($sorttok($1- , 32 , rn),1,32)
}

Note: the above NumericMax assumes the input already contains only numbers, because in a numeric sort, non-numeric is treated as if zero, and is sorted between the positives vs the negative numbers. It appears that, except for stripping the negative from the front, it evaluates each token individually the same was as evaluated by $abs().

This means non-numerics are chopped from the end of the token if it begins with a number, though it treats 'e' or 'E' as potentially being part of a number in scientific notation. Tokens 2+2 or +2*2 or 2-2 are treated the same as '2' because that's the number prior to encountering a non-numeric. All tokens which evaluate to the same number appear to always be left together in the order they appear in the input, so $sorttok(64 64.0,32,n) and $sorttok(64.0 64,32,n) both return an unchanged string.

//var %a $regsubex($str(x,94),/x/g,$chr($calc(32+ \n)) $chr(32)) | echo -a $sorttokcs(11 -11 -1 1 +1 -2 2 $true $false $true -x1xa 0 $false +2*2 0 0.0 %a 5-1 5-11 5-2 2+2 =4 101 99 1E2xx $false 0.1,32,n)
 
Returns: -11 -2 -1 $true $false $true -x1xa 0 $false 0 0.0 ! " # $ % & ' ( ) * + , - . / 0 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ =4 $false 0.1 1 +1 1 2 +2*2 2 2+2 3 4 5 5-1 5-11 5-2 6 7 8 9 11 99 1E2xx 101

Note: The first $true through the last $false appear in the same order as in the input because they all evaluate as zero. The same happens to the several tokens which all evaluate as 2 or 5. 1E2xx sorts between 99 and 101 because it evaluates 1E2 as scientific notation for 100.

Note: The 'r' switch is a modifier which reverses the direction of the sort for the anc sort orders. For numeric sort, it does not always put the tokens into inverse order. It only changes the direction of the sort after each token has been evaluated to its numeric equivalent. Using 'r' by itself is the same as 'ar' because 'a' is the default sort order.

Note: changing the sort order from 'n' to 'c' changes the output to an ASCII order sort, except that tokens beginning with any of the channel prefix symbols are sorted to the front. These prefixes are shown by the $prefix identifier, so the above display will be different in a blank status window created with "/server -n" that it would be at a network which recognizes ~ and & as nick prefixes.

Compatibility

Added: mIRC v4.7
Added on: 09 Dec 1996
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.

See also