Text-handling experiment in Design Philosophy
|
|
I have been doing a little experimenting with text-handling and I've managed to create two functions: reversing text and scrambling text. I wanted to know if these functions are fine the way they are, or if they could be improved.
proc text_scramble(string)
if(string) var oldstring = string newstring copy_pos rand_character
for(var/textleft = length(oldstring), textleft, textleft --) copy_pos = rand(1,textleft) rand_character = copytext(oldstring, copy_pos, copy_pos+1)
newstring += rand_character oldstring = copytext(oldstring, 1, copy_pos) + copytext(oldstring, copy_pos+1, 0)
return newstring
text_reverse(string)
if(string) var/newstring
for(var/textleft = length(string), textleft, textleft --) newstring += copytext(string, textleft, textleft+1)
return newstring
|
|
That's probably what I would do. Not much different to what you have. I don't know if you would call it much improved, even if you optimized a bit more. It's fine.