Skip to content

Commit

Permalink
replace token ~#~ with ~::~
Browse files Browse the repository at this point in the history
  • Loading branch information
vkiryukhin committed Feb 29, 2012
1 parent 36b43af commit 3dc9563
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function loadTemplate(name)
case 'basicsql':
$('#ta').width(600);
$('#leftpanel').show();
document.getElementById('ta').value = "SELECT ca.proj_id AS proj_id, ca.ca_name AS proj_name, ca.ca_date_start AS proj_start, ca.ca_date_end AS proj_end,(SELECT COUNT(*) FROM rotations r WHERE r.proj_id = proj_id AND r.r_status = 'R' GROUP BY r.proj_id) r_count, (SELECT count(*) FROM rotations r WHERE r.proj_id = proj_id AND r.channel_id = 24 ) r_rtb_count, ca.ca_service_type FROM projs ca, clients c, proj_auth caa WHERE ca.client_id = 12345 AND ca.client_id = c.client_id AND ca_type = 'zzz' AND c.agency_id = 0 AND ca.client_id = NVL( caa.client_id, ca.client_id ) AND proj_id = NVL( caa.proj_id, proj_id ) AND caa.contact_id = 7890";
document.getElementById('ta').value = "SELECT ca.proj_id AS proj_id, ca.ca_name AS proj_name, ca.ca_date_start AS proj_start, ca.ca_date_end AS proj_end,(SELECT COUNT(*) FROM rotations r WHERE r.proj_id = proj_id AND r.r_status = 'R' GROUP BY r.proj_id) r_count, (SELECT count(*) FROM rotations r WHERE r.proj_id = proj_id AND r.channel_id = 24 ) r_rtb_count FROM projs ca, clients c, proj_auth caa WHERE ca.client_id = 12345 AND ca.client_id = c.client_id AND ca_type = 'zzz' AND c.agency_id = 0 AND ca.client_id = NVL( caa.client_id, ca.client_id ) AND proj_id = NVL( caa.proj_id, proj_id ) AND caa.contact_id = 7890";
$('#rightpanel').empty().load('html/basicsql.html');
$('#rightpanel').empty();
$('#mode').html('SQL');
Expand Down
96 changes: 48 additions & 48 deletions vkbeautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function vkbeautify(){

vkbeautify.prototype.xml = function(text) {

var ar = text.replace(/>\s{0,}</g,"><").replace(/</g,"~#~<").split('~#~'),
var ar = text.replace(/>\s{0,}</g,"><").replace(/</g,"~::~<").split('~::~'),
len = ar.length,
inComment = false,
deep = 0,
Expand Down Expand Up @@ -117,14 +117,14 @@ vkbeautify.prototype.json = function(text) {
.replace(/:\s{0,}\"/g,':"')
.replace(/:\s{0,}\[/g,':[')

.replace(/\{/g,"~#~{~#~")
.replace(/\[/g,"[~#~")
.replace(/\}/g,"~#~}")
.replace(/\]/g,"~#~]")
.replace(/\"\,/g,'",~#~')
.replace(/\,\"/g,',~#~"')
.replace(/~#~\s{0,}~#~/g,"~#~")
.split('~#~'),
.replace(/\{/g,"~::~{~::~")
.replace(/\[/g,"[~::~")
.replace(/\}/g,"~::~}")
.replace(/\]/g,"~::~]")
.replace(/\"\,/g,'",~::~')
.replace(/\,\"/g,',~::~"')
.replace(/~::~\s{0,}~::~/g,"~::~")
.split('~::~'),

len = ar.length,
deep = 0,
Expand Down Expand Up @@ -153,13 +153,13 @@ vkbeautify.prototype.json = function(text) {
vkbeautify.prototype.css = function(text) {

var ar = text.replace(/\s{1,}/g,' ')
.replace(/\{/g,"{~#~")
.replace(/\}/g,"~#~}~#~")
.replace(/\;/g,";~#~")
.replace(/\/\*/g,"~#~/*")
.replace(/\*\//g,"*/~#~")
.replace(/~#~\s{0,}~#~/g,"~#~")
.split('~#~'),
.replace(/\{/g,"{~::~")
.replace(/\}/g,"~::~}~::~")
.replace(/\;/g,";~::~")
.replace(/\/\*/g,"~::~/*")
.replace(/\*\//g,"*/~::~")
.replace(/~::~\s{0,}~::~/g,"~::~")
.split('~::~'),
len = ar.length,
deep = 0,
str = '',
Expand Down Expand Up @@ -193,40 +193,40 @@ function split_sql(str, tab) {

return str.replace(/\s{1,}/g," ")

.replace(/ AND /ig,"~#~"+tab+tab+"AND ")
.replace(/ BETWEEN /ig,"~#~"+tab+"BETWEEN ")
.replace(/ CASE /ig,"~#~"+tab+"CASE ")
.replace(/ ELSE /ig,"~#~"+tab+"ELSE ")
.replace(/ END /ig,"~#~"+tab+"END ")
.replace(/ FROM /ig,"~#~FROM ")
.replace(/ GROUP\s{1,}BY/ig,"~#~GROUP BY ")
.replace(/ HAVING /ig,"~#~HAVING ")
//.replace(/ IN /ig,"~#~"+tab+"IN ")
.replace(/ AND /ig,"~::~"+tab+tab+"AND ")
.replace(/ BETWEEN /ig,"~::~"+tab+"BETWEEN ")
.replace(/ CASE /ig,"~::~"+tab+"CASE ")
.replace(/ ELSE /ig,"~::~"+tab+"ELSE ")
.replace(/ END /ig,"~::~"+tab+"END ")
.replace(/ FROM /ig,"~::~FROM ")
.replace(/ GROUP\s{1,}BY/ig,"~::~GROUP BY ")
.replace(/ HAVING /ig,"~::~HAVING ")
//.replace(/ IN /ig,"~::~"+tab+"IN ")
.replace(/ IN /ig," IN ")

.replace(/ JOIN /ig,"~#~JOIN ")
.replace(/ CROSS~#~{1,}JOIN /ig,"~#~CROSS JOIN ")
.replace(/ INNER~#~{1,}JOIN /ig,"~#~INNER JOIN ")
.replace(/ LEFT~#~{1,}JOIN /ig,"~#~LEFT JOIN ")
.replace(/ RIGHT~#~{1,}JOIN /ig,"~#~RIGHT JOIN ")
.replace(/ JOIN /ig,"~::~JOIN ")
.replace(/ CROSS~::~{1,}JOIN /ig,"~::~CROSS JOIN ")
.replace(/ INNER~::~{1,}JOIN /ig,"~::~INNER JOIN ")
.replace(/ LEFT~::~{1,}JOIN /ig,"~::~LEFT JOIN ")
.replace(/ RIGHT~::~{1,}JOIN /ig,"~::~RIGHT JOIN ")

.replace(/ ON /ig,"~#~"+tab+"ON ")
.replace(/ OR /ig,"~#~"+tab+tab+"OR ")
.replace(/ ORDER\s{1,}BY/ig,"~#~ORDER BY ")
.replace(/ OVER /ig,"~#~"+tab+"OVER ")
.replace(/ ON /ig,"~::~"+tab+"ON ")
.replace(/ OR /ig,"~::~"+tab+tab+"OR ")
.replace(/ ORDER\s{1,}BY/ig,"~::~ORDER BY ")
.replace(/ OVER /ig,"~::~"+tab+"OVER ")

.replace(/\(\s{0,}SELECT /ig,"~#~(SELECT ")
.replace(/\)\s{0,}SELECT /ig,")~#~SELECT ")
.replace(/\(\s{0,}SELECT /ig,"~::~(SELECT ")
.replace(/\)\s{0,}SELECT /ig,")~::~SELECT ")

.replace(/ THEN /ig," THEN~#~"+tab+"")
.replace(/ UNION /ig,"~#~UNION~#~")
.replace(/ USING /ig,"~#~USING ")
.replace(/ WHEN /ig,"~#~"+tab+"WHEN ")
.replace(/ WHERE /ig,"~#~WHERE ")
.replace(/ WITH /ig,"~#~WITH ")
.replace(/ THEN /ig," THEN~::~"+tab+"")
.replace(/ UNION /ig,"~::~UNION~::~")
.replace(/ USING /ig,"~::~USING ")
.replace(/ WHEN /ig,"~::~"+tab+"WHEN ")
.replace(/ WHERE /ig,"~::~WHERE ")
.replace(/ WITH /ig,"~::~WITH ")

//.replace(/\,\s{0,}\(/ig,",~#~( ")
//.replace(/\,/ig,",~#~"+tab+tab+"")
//.replace(/\,\s{0,}\(/ig,",~::~( ")
//.replace(/\,/ig,",~::~"+tab+tab+"")

.replace(/ ALL /ig," ALL ")
.replace(/ AS /ig," AS ")
Expand All @@ -239,15 +239,15 @@ function split_sql(str, tab) {
.replace(/ LIKE /ig," LIKE ")
.replace(/\s{0,}SELECT /ig,"SELECT ")

.replace(/~#~{1,}/g,"~#~")
.split('~#~');
.replace(/~::~{1,}/g,"~::~")
.split('~::~');
}

vkbeautify.prototype.sql = function(text, brakeOnComma) {

var ar_by_quote = text.replace(/\s{1,}/g," ")
.replace(/\'/ig,"~#~\'")
.split('~#~'),
.replace(/\'/ig,"~::~\'")
.split('~::~'),
len = ar_by_quote.length,
ar = [],
deep = 0,
Expand Down

0 comments on commit 3dc9563

Please sign in to comment.