snippet that manipulated token

By zonirc on Sep 12, 2005

UPDATED: Just copy n paste it into your remote :p Its just a snippet that manipulated token(got 2 snippets actually)

/*
Date: Sat Sep 10 20:56:54 2005
Updated:
Thu Sep 15 02:57:57 2005
- Fixed $switchtok will return total token insteadt of Nth token when
Nth specified as '0'.
- $switchtok now accept more than two Nth parameter.(Thanks to hantu
for giving that idea)
- Added .pair properties for $switchtok

Forgot the date :P
- Added $getstok into collections.
- Fixed $switchtok will not return a value when N1 or N2 not specified.
- Change $addtok+ to $addedtok for typing convenient.
- Edited comments.
==================================
=                          ENGLISH                                 =
==================================
Name:$switchtok
Author:zonIRC
Email:zonirc@email.com
Description:Switches the position of the token
Syntax:$switchtok(<token>,<N1>,<N2>[, <N?>] ,<C>)[.properties]
Properties:
.pair - when this properties being specified, you need to specify
two pairs of Nth. Its will switches N1 with N2, N3 with N4 and
so on.
- its will stop switches token when the next Nth token didn't exist or
not find its pair.
- when .pair properties not specified then it will switch N2 to N1, N3 to N2
and so on. Where the last Nth will be switches with N1.
Example:
$switchtok(one two three four,2,3,32) will return 'one three two four'
$switchtok(one two three four five,1,3,5,32) will return 'three two five four one'
$switchtok(one two three four five,1,2,4,5,32).pair will return 'two one three five four'
$switchtok(one two three four five,1,2,5,6,32).pair will return 'two one three four five'
$switchtok(one two three four five,1,2,4,32).pair will return 'two one three four five'
Info:
If token N1 or/and N2 doesnt exist it will return the same <token> without
any token being switched.
===========================================
=                             BAHASA MALAYSIA                                   =
===========================================
Nama:$switchtok
Penulis:zonIRC
Email:zonirc@email.com
Deskripsi:Mengubah kedudukan token
Sintaks:$switchtok(<token>,<N1>,<N2>[, <N?>],<C>)[.properties]
Properties:
.pair - sekiranya ianya dinyatakan, anda perlu menetapkan sepasang Nth. Di mana,
ianya akan menukar token N1 dengan N2, N3 dengan N4 dan seterusnya.
- ia akan berhenti menukar kedudukan token apabila token N seterusnya tidak wujud
atau tidak mempunyai pasangannya.
- sekiranya properties .pair tidak dinyatakan, ia akan mengubah kedudukan token
N2 ke N1, N3 ke N2 dan seterusnya. Di mana token terakhir akan di ganti dengan
token N1.
Contoh:
$switchtok(satu dua tiga empat,2,3,32) menghasilkan 'satu tiga dua empat'
$switchtok(satu dua tiga empat lima,1,3,5,32) menghasilkan 'tiga dua lima empat satu'
$switchtok(satu dua tiga empat lima,1,2,4,5,32).pair menghasilkan 'dua satu tiga lima empat'
$switchtok(satu dua tiga empat lima,1,2,5,6,32).pair menghasilkan 'dua satu tiga empat lima'
$switchtok(satu dua tiga empat lima,1,2,4,32).pair menghasilkan 'dua satu tiga empat lima'
Info:
Jika token posisi N1 atau/dan N2 tidak wujud ianya akan menghasilkan <token>
yang sama tanpa sebarang perubahan.
*/

alias switchtok {
  var %x = 2, %c = $($+($,$0),2), %res = $1
  while ($calc(%x + 1) < $0) {
    var %t2 = $($+($,$v1),2), %t1 = $($+($,%x),2), %n = $numtok($1,%c), %1 = $iif(!$prop,1,%t1)
    if (%t2 > %n) || (%t1 > %n) || (!%t2) || (!%t1) break
    %res = $puttok($puttok(%res,$gettok($1,$iif(%t2 = %n,%1,%t1),%c),%t2,%c),$gettok($1,%t2,%c),%t1,%c)
    %x = %x + $iif($prop = pair,2,1)
  }
  return %res
}

/*
==================================
=                          ENGLISH                                 =
==================================
Name:$addedtok
Author:zonIRC
Email:zonirc@email.com
Description:Added string at the start or/and end or middle of the Nth token
Syntax:$addedtok(<token>,<string>,<N>,<C>)
- to add string at the start of Nth token use <string>*
- to add string at the end of Nth token use *<string>
- to put Nth token at the start and end of string use *<string>*
- to add string at the start and end of Nth token use <string>*<string>
- if characther '*' didnt specified then it will add string into the end of Nth token.
Example:
$addedtok(this boy,cow*,2,32) will return 'this cowboy'
$addedtok(this boy,*s,2,32) will return 'this boys'
$addedtok(this boy,*ish-*,2,32) will return 'this boyish-boy'
$addedtok(this boy,cow*s,2,32) will return 'this cowboys'
$addedtok(this boy,s,2,32) will return 'this boys'
Info:
If Nth token not exist nothing will be added.
===========================================
=                             BAHASA MALAYSIA                                   =
===========================================
Nama:$addedtok
Penulis:zonIRC
Email:zonirc@email.com
Deskripsi:Menambah teks(string) pada permulaan atau/dan pengakhiran atau pada pertengahan token berposisi N.
Sintaks:$addedtok(<token>,<teks>,<A>,<N>,<C>,<wildstring>)
- untuk menambah teks pada permulaan token gunakan <teks>*
- untuk menambah teks pada pengakhiran token gunakan *<teks>
- untuk meletakkan N token pada permulaan dan pengakhiran teks gunakan *<teks>*
- untuk menambah teks pada permulaan dan pengakhiran token gunakan <teks>*<teks>
- jika karekter '*' tidak dinyatakan pada <teks> maka ia akan menambah <teks> pada pengakhiran token.
Contoh:
$addedtok(apa ni?,si*,1,32) menghasilkan 'siapa ni?'
$addedtok(apa ni?,*kah,1,32) menghasilkan 'apakah ni?'
$addedtok(apa ni?,* dan si*,1,32) menghasilkan 'apa dan siapa ni?'
$addedtok(apa ni?,si*kah,1,32) menghasilkan 'siapakah ni?'
$addedtok(apa ni?,kah,1,32) menghasilkan 'apakah ni?'
Info:
Jika token posisi N tidak wujud, tiada sebarang penambahan akan dilakukan.
*/

alias addedtok {
  var %e = echo -ftsc Info * $!addedtok:, %w = $iif($6,$6,*)
  if (!$isid) $replace(%e,$,/) Unknown Command
  elseif (!$1) %e Missing Token Parameter
  elseif (!$2) %e Missing String Parameter
  elseif (!$3) %e Missing Ascii Parameter
  elseif ($4 !isnum) %e $iif($4,Invalid,Missing) N Parameter
  elseif ($5 !isnum) %e $iif($6,Invalid,Missing) C Parameter
  else {
    var %s = $2 $+ $iif($3 !isincs $2,$3), %x = $iif($4,44,1), %r = $1
    while ($wildtok(%r,%w,%x,$5)) {
      %r = $puttok(%r,$replacex(%s,$3,$v1),%x,$5)
      if (%x = $4) break
      inc %x
    }
    return %r
  }
}

/*
==================================
=                          ENGLISH                                 =
==================================
Name:$getstok
Author:zonIRC
Email:zonirc@email.com
Description:Get one or more Nth token.
Syntax:$getstok(<token>,<N1>[,<N2>[,<N?>]],<C>)
Example:
$getstok(how to using getstok made by zonIRC,1,3,6,32) will return 'how using by'
$getstok(how.to.using.getstok.made.by.zonIRC,3,5,6,7,46) will return 'using.made.by.zonIRC'
Info:
- If token not separated by character 'C' then nothing will be returned
===========================================
=                             BAHASA MALAYSIA                                   =
===========================================
Nama:$getstok
Penulis:zonIRC
Email:zonirc@email.com
Deskripsi:Mendapatkan satu atau lebih token.
Sintaks:$getstok(<token>,<N1>[,<N2>[,<N?>]],<C>)
Contoh:
$getstok(how to using getstok made by zonIRC,1,3,6,32) menghasilkan 'how using by'
$getstok(how.to.using.getstok.made.by.zonIRC,2,3,4,6,7,46) menghasilkan 'to.using.getstok.by.zonIRC'
Info:
- Jika token tidak dibahagikan oleh karekter 'C', tiada nilai yang akan dikembalikan.
*/

alias getstok {
  var %x = 2, %c = $($+($,$0),2), %res
  while ($gettok($1,$($+($,%x),2),%c)) {
    var %y = $v1
    %res = $iif(%res,%res $+ $chr(%c)) $+ %y
    inc %x
  }
  return %res
}

Comments

Sign in to comment.
zonirc   -  Sep 14, 2005

Thanx QuickStep... that rite and i just edited it now plus with the updated version....

 Respond  
QuickStep   -  Sep 13, 2005

it might since you forgot a \'/*\' somewhere

 Respond  
Yoinx   -  Sep 13, 2005

No, it shouldnt affect the speed at all.

 Respond  
zonirc   -  Sep 13, 2005

I like to put some comment on my snippet... anyway if anyone using it prefer it w/o a comment then they free to remove it didnt they :P
Anyway is that comment line also count as speedness of the code???
May someone??

 Respond  
ch1zra   -  Sep 13, 2005

depends.. at least no one can say that it\'s not well documented :)

 Respond  
Yoinx   -  Sep 12, 2005

looks good, though I didnt try it. it\'s pretty crazy though having like 10x the amount of code in comments.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.