[tab]h turning into \th. {edited} in Developer Help
|
|
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" if(findtext(code,"\t[h]")) world<<"found" code=SwapText(code,"\t[h]","\t\ h") 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"))) 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.
|
-YMIStillNotGettingThis