ID:147350
 
I'm trying to make a command that will accept a code snippet and then send it back compressed(using ;, {, and }). I noticed that it seemed to mess up with the letter h, and after repeatedly telling my self that it was a coincidence, I started testing the h theory. As far as I can tell input()ting a tab("\t") followed by an h will use the \th macro, and I can tell if that's happening, but I'm not sure how to fix it. If I put a space in between the tab and the h, then someone who compiles the output will get at least an indentation error. I was hoping I could fix this without a serious overhaul, so here's what I've got:

client
verb
compress(code as message)
src<<browse(html_encode(Compress(code)),"window=compress")

proc/Compress(code,indentation="\t")
var/tablevel=1
var/compressed
var/h="h" //Tried
if(findtext(code,"\t[h]"))
world<<"found"
code=SwapText(code,"\t[h]","\t\ h") //to fix.
var/list/lines=SeparateLines(code)
lines+="\n"
for(var/v in lines)
var/tabs=1
for(tabs,copytext(v,tabs,tabs+length(indentation))==indentation,tabs++)
v=copytext(v,tabs)
if(tabs==tablevel)
if(v!=lines[1])
v=";[v]"
while(tabs<tablevel)
v="}[v]"
tablevel--
while(tabs>tablevel)
v="{[v]"
tablevel++
compressed+=v
sleep()
return compressed

proc/SeparateLines(txt)
var/list/L=new
while(findtext(txt,"\n"))
if(copytext(txt,1,findtext(txt,"\n"))) //"\t\th" appears to get lost here.
L+=copytext(txt,1,findtext(txt,"\n"))
txt=copytext(txt,findtext(txt,"\n")+1)
if(txt) L+=txt
return L


If the indentation is off, it's a mistake I made when converting the tabs to spaces for the forum(I don't like horizontal scolling). Any help would be appreciated.
It seems that this only happens when the line is atleast one tab followed by an h. If the h is followed by another visible character(in other words, adding a space to the end of each line won't work either) it appears to turn out fine(displays the h along with the rest of the line). The interesting part is that if the line is "\the"([tab]he) it works dispite the \the macro. So why does the \th macro mess it up? Any ideas? Any at all?


-YMIStillNotGettingThis