Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function compress(%from,%to)
- {
- new fileobject(c).openforread(findfirstFile(%from));
- %current = 0;
- deleteVariables("$v*");
- while(!c.isEOF())
- {
- %line = c.readline();
- %comment = 0;
- while((%comment = strpos(%line,"//",%comment)) >= 0)
- {
- if(!wS(%line,%comment))
- %line = getsubstr(%line,0,%comment);
- else
- %comment++;
- }
- %func = -1;
- while(wS(%line,%func = stripos(%line,"function",%func + 1)))
- {
- }
- %compressed = %compressed NL %line;
- }
- %compressed = rws(" ",rws("\t",rws("\n",%compressed)));
- c.delete();
- new fileobject(c).openforwrite(%to);
- c.writeline(%compressed);
- c.delete();
- }
- function wS(%text,%pos)
- {
- while(%first < strlen(%text) && (%first = strpos(%text,"\"",%first)) >= 0 && %first < %pos)
- {
- %second = %first + 1;
- while(%second < strlen(%text) && (%second = strpos(%text,"\"",%second)) >= 0 && %first < %pos)
- {
- %escaped = 0;
- for(%it = %second - 1; getsubstr(%text,%it,1) $= "\\"; %it--)
- %escaped = !%escaped;
- if(%escaped)
- {
- %second++;
- continue;
- }
- if(%first < %pos && %second > %pos)
- {
- return true;
- }
- %first = %second + 1;
- break;
- }
- }
- return false;
- }
- function rWs(%type,%text)
- {
- for(%it = 0; %it < strlen(%text); %it++)
- {
- %char = getsubstr(%text,%it,1);
- if(%inside || %char !$= %type || (%char $= %type && %it > 0 &&
- (strpos("!^\"'$@,.(){}[];=?:-+*/%<>&|\t\r\n ",getsubstr(%text,%it - 1,1)) == -1 &&
- strpos("!^\"'$@,.(){}[];=?:-+*/%<>&|\t\r\n ",getsubstr(%text,%it + 1,1)) == -1)))
- %result = %result @ %char;
- if(%char $= "\"")
- {
- if(%inside)
- {
- %escaped = 0;
- for(%nt = %it - 1; getsubstr(%text,%nt,1) $= "\\"; %nt--)
- %escaped = !%escaped;
- if(%escaped)
- continue;
- }
- %inside = !%inside;
- }
- }
- return %result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement