User Tools

Site Tools


script_autoformat

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

====== About the script ====== * Purpose : This script will autoindent and remove unneeded spaces and line breaks in other scripts * Author : [[https://plus.google.com/+LukasMorawietz|LM13]] * Current Version : 1.0 * Link : ====== Changelog ====== * Version 1.0 (22/7/2014): initial release in wiki ====== How to use the script ====== * Run from anywhere * type in the exact name of the script you want to format * copy/paste the output * test it, before replacing the old! //please report all bugs in the g+ community!// ====== Script ====== <sxh javascript;>var s=LL.getScriptByName(prompt("Which script?","")); try { var t=s.getText(); } catch(NullPointerException) { alert("script not found"); return; } var out=""; var i=0; var inString=false; var newLine=true; var inFor=-1; for(a=0;a<t.length;a++) { if(t[a]==" "&&!inString&&(t[a-1].toLowerCase()==t[a-1].toUpperCase()||t[a+1].toLowerCase()==t[a+1].toUpperCase()))continue; if(t[a]=="\n"&&!inString&&t[a+1]!="\n")continue; if(t[a]=="\t"&&!inString)continue; if(t[a]=="\""||t[a]=="\'")inString=!inString; if(!inString) { if(t[a]=="{") { out=out.concat("\n"); for(b=0;b<i;b++)out=out.concat("\t"); out=out.concat("{\n"); i++; newLine=true; continue; } if(t[a]=="}") { i--; for(b=0;b<i;b++)out=out.concat("\t"); out=out.concat("}\n"); newLine=true; continue; } if(newLine&&t[a]!="\n") { for(b=0;b<i;b++)out=out.concat("\t"); newLine=false; } if(t[a]==";"&&inFor<1) { out=out.concat(";\n"); newLine=true; inFor=-1; continue; } if(t.slice(a,a+4)=="for(") { inFor=0; } if(inFor>=0&&t[a]=="(") { inFor+=1; } if(inFor>=0&&t[a]==")") { inFor-=1; } } out=out.concat(t[a]); } while(out[out.length-1]=="\n")out=out.slice(0,out.length-1); prompt("",out); </sxh>

script_autoformat.1406064861.txt.gz · Last modified: 2014/07/22 21:34 by lm13