Run-length encoding: Difference between revisions
Content added Content deleted
m (→{{header|Java}}: reduce indentation to hkeep code on page) |
(rle in autohotkey) |
||
Line 194: | Line 194: | ||
Decode output: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW |
Decode output: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW |
||
</pre> |
</pre> |
||
=={{header|AutoHotkey}}== |
|||
<lang AutoHotkey> |
|||
msgbox % key := rle_encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW") |
|||
msgbox % rle_decode(key) |
|||
rle_encode(message) |
|||
{ |
|||
StringLeft, previous, message, 1 |
|||
StringRight, last, message, 1 |
|||
message .= asc(chr(last)+1) |
|||
count = 0 |
|||
loop, parse, message |
|||
{ |
|||
if (previous == A_LoopField) |
|||
count +=1 |
|||
else |
|||
{ |
|||
output .= previous . count |
|||
previous := A_LoopField |
|||
count = 1 |
|||
} |
|||
} |
|||
return output |
|||
} |
|||
rle_decode(message) |
|||
{ |
|||
pos = 1 |
|||
while, item := RegExMatch(message, "\D", char, pos) |
|||
{ |
|||
digpos := RegExMatch(message, "\d+", dig, item) |
|||
loop, % dig |
|||
{ |
|||
output .= char |
|||
} |
|||
pos := digpos |
|||
} |
|||
return output |
|||
} |
|||
</lang> |
|||
=={{header|C}}== |
=={{header|C}}== |