Advertisement
Guest User

Untitled

a guest
Jan 24th, 2011
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. function compress(%from,%to)
  2. {
  3.     new fileobject(c).openforread(findfirstFile(%from));
  4.     %current = 0;
  5.     deleteVariables("$v*");
  6.    
  7.     while(!c.isEOF())
  8.     {
  9.         %line    = c.readline();
  10.         %comment = 0;
  11.        
  12.         while((%comment = strpos(%line,"//",%comment)) >= 0)
  13.         {
  14.             if(!wS(%line,%comment))
  15.                 %line = getsubstr(%line,0,%comment);
  16.             else
  17.                 %comment++;
  18.         }
  19.        
  20.         %func = -1;
  21.        
  22.         while(wS(%line,%func = stripos(%line,"function",%func + 1)))
  23.         {
  24.         }
  25.        
  26.         %compressed = %compressed NL %line;
  27.     }
  28.    
  29.     %compressed = rws(" ",rws("\t",rws("\n",%compressed)));
  30.    
  31.     c.delete();
  32.     new fileobject(c).openforwrite(%to);
  33.     c.writeline(%compressed);
  34.     c.delete();
  35. }
  36.  
  37. function wS(%text,%pos)
  38. {
  39.     while(%first < strlen(%text) && (%first = strpos(%text,"\"",%first)) >= 0 && %first < %pos)
  40.     {
  41.         %second = %first + 1;
  42.        
  43.         while(%second < strlen(%text) && (%second = strpos(%text,"\"",%second)) >= 0 && %first < %pos)
  44.         {
  45.             %escaped = 0;
  46.            
  47.             for(%it = %second - 1; getsubstr(%text,%it,1) $= "\\"; %it--)
  48.                 %escaped = !%escaped;
  49.            
  50.             if(%escaped)
  51.             {
  52.                 %second++;
  53.                 continue;
  54.             }
  55.            
  56.             if(%first < %pos && %second > %pos)
  57.             {
  58.                 return true;
  59.             }
  60.            
  61.             %first = %second + 1;
  62.             break;
  63.         }
  64.     }
  65.    
  66.     return false;
  67. }
  68.  
  69. function rWs(%type,%text)
  70. {
  71.     for(%it = 0; %it < strlen(%text); %it++)
  72.     {
  73.         %char = getsubstr(%text,%it,1);
  74.        
  75.         if(%inside || %char !$= %type || (%char $= %type && %it > 0 &&
  76.         (strpos("!^\"'$@,.(){}[];=?:-+*/%<>&|\t\r\n ",getsubstr(%text,%it - 1,1)) == -1 &&
  77.          strpos("!^\"'$@,.(){}[];=?:-+*/%<>&|\t\r\n ",getsubstr(%text,%it + 1,1)) == -1)))
  78.             %result = %result @ %char;
  79.        
  80.         if(%char $= "\"")
  81.         {
  82.             if(%inside)
  83.             {
  84.                 %escaped = 0;
  85.                
  86.                 for(%nt = %it - 1; getsubstr(%text,%nt,1) $= "\\"; %nt--)
  87.                     %escaped = !%escaped;
  88.                
  89.                 if(%escaped)
  90.                     continue;
  91.             }
  92.            
  93.             %inside = !%inside;
  94.         }
  95.     }
  96.    
  97.     return %result;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement