>>94
Providing a mIRC implementation.
Usage: /bs testing buttsort
Can be used as an identifier, e.g. $buttsort(testing buttsort)
Caveat: Will not function well at all if the output ends up being > 900 characters. This means that you can only do roughly 90 characters worth of input text.
alias bs { say $buttsort($$1-) }
alias bbcode { return $+($chr(91), $1, $chr(93)) }
alias endbbcode { return $bbcode($+($chr(47), $1)) }
alias buttsort {
var %text = $$1-
var %output = $bbcode(b) $+ $bbcode(i)
var %i = 1
var %ctr = 1
var %t = $len(%text)
while (%i <= %t) {
var %g = $mid(%text, %i, 1)
var %spacequantity = 0
while (%i <= %t && %g == $chr(32)) {
inc %i
inc %spacequantity
var %g = $mid(%text, %i, 1)
}
if (%i > %t && %spacequantity > 0) { break }
if (%ctr == 1) {
var %output = %output $+ $str($chr(32), %spacequantity) $+ $bbcode(u) $+ %g $+ $endbbcode(u)
var %ctr = 0
}
else {
var %output = %output $+ $str($chr(32), %spacequantity) $+ $bbcode(o) $+ %g $+ $endbbcode(o)
var %ctr = 1
}
inc %i
}
var %output = %output $+ $endbbcode(i) $+ $endbbcode(b)
return %output
}