3535/**
3636 * AMD wrapper if running on server
3737 */
38- if ( typeof define === "undefined" )
39- {
40- var define = function ( factory )
41- {
38+ if ( typeof define === "undefined" ) {
39+ var define = function ( factory ) {
4240 factory ( require , exports , module ) ;
4341 } ;
4442}
4543
46- define ( function ( require , exports , module )
47- {
48- var PacketParser = exports . PacketParser = function ( options )
49- {
44+ define ( function ( require , exports , module ) {
45+ var PacketParser = exports . PacketParser = function ( options ) {
5046 this . API = options . API ;
5147 this . options = options ;
5248 this . listeners = { } ;
5349 this . buffer = "" ;
5450
5551 if ( ! this . API . XML2JS )
5652 throw new Error ( "No converter API at `options.API.XML2JS`!" ) ;
57- }
53+ } ;
5854
59- PacketParser . prototype . on = function ( name , callback )
60- {
55+ PacketParser . prototype . on = function ( name , callback ) {
6156 if ( ! this . listeners [ name ] )
6257 this . listeners [ name ] = [ ] ;
6358 this . listeners [ name ] . push ( callback ) ;
64- }
59+ } ;
6560
66- PacketParser . prototype . emit = function ( name , args )
67- {
61+ PacketParser . prototype . emit = function ( name , args ) {
6862 if ( ! this . listeners [ name ] )
6963 return ;
7064 args = args || { } ;
71- for ( var i = 0 , ic = this . listeners [ name ] . length ; i < ic ; i ++ ) {
65+ for ( var i = 0 , ic = this . listeners [ name ] . length ; i < ic ; i ++ )
7266 this . listeners [ name ] [ i ] . call ( null , args ) ;
73- }
74- }
67+ } ;
7568
76- PacketParser . prototype . parseChunk = function ( chunk )
77- {
69+ PacketParser . prototype . parseChunk = function ( chunk ) {
7870 var self = this ;
7971
8072 // 6.4 debugger engine to IDE communications
8173 // @see http://www.xdebug.org/docs-dbgp.php#id31
8274
8375 // If chunk does not end in delimiter we got a partial chunk and need to buffer it.
8476 if ( this . buffer !== "" ) {
85- chunk = this . buffer + chunk ;
86- this . buffer = "" ;
77+ chunk = this . buffer + chunk ;
78+ this . buffer = "" ;
8779 }
8880 if ( ! / \u0000 $ / . test ( chunk ) ) {
89- this . buffer = chunk ;
90- // TODO: Parse as much of the buffer as we can right away
91- return ;
81+ this . buffer = chunk ;
82+ // TODO: Parse as much of the buffer as we can right away
83+ return ;
9284 }
9385
9486 var parts = chunk . split ( / \u0000 / g) ,
95- lastPart ;
87+ lastPart ;
9688 if ( ( lastPart = parts . pop ( ) ) !== "" )
97- throw new Error ( "Chunk does not end in `\u0000`! Found instead: " + lastPart ) ;
89+ throw new Error ( "Chunk does not end in `\u0000`! Found instead: " + lastPart ) ;
9890 if ( ( parts . length ) % 2 )
9991 throw new Error ( "Invalid chunk format. Expecting `length[NULL]data[NULL]...`. Got: " + chunk ) ;
10092
10193 var length ,
102- data ;
94+ data ;
10395
104- while ( parts . length > 0 )
105- {
106- length = parts . shift ( ) ;
107- data = parts . shift ( ) ;
96+ while ( parts . length > 0 ) {
97+ length = parts . shift ( ) ;
98+ data = parts . shift ( ) ;
10899
109- if ( length != data . length )
100+ if ( length != data . length )
110101 throw new Error ( "Announced packet length '" + length + "' does not match actual data length '" + data . length + "' for data '" + data + "'!" ) ;
111102
112- // Check if we need to convert the XML message to a JSON one
113- if ( / \s * < \? x m l \s / . test ( data ) )
114- {
103+ // Check if we need to convert the XML message to a JSON one
104+ if ( / \s * < \? x m l \s / . test ( data ) ) {
115105 var parser = new this . API . XML2JS . Parser ( ) ;
116- parser . addListener ( "end" , function ( result )
117- {
118- if ( typeof result [ "#" ] !== "undefined" && result [ "@" ] . encoding === "base64" )
119- {
120- result [ "#" ] = exports . base64_decode ( result [ "#" ] ) ;
121- }
106+ parser . addListener ( "end" , function ( result ) {
107+ if ( typeof result [ "#" ] !== "undefined" && result [ "@" ] . encoding === "base64" )
108+ result [ "#" ] = exports . base64_decode ( result [ "#" ] ) ;
122109 self . emit ( "packet" , result ) ;
123110 } ) ;
124111 parser . parseString ( data ) ;
125112 }
126113 else
127114 throw new Error ( "Cannot parse chunk. Chunk not in XML format!" ) ;
128115 }
129- }
116+ } ;
130117
131118
132- exports . formatCommand = function ( name , args , data )
133- {
119+ exports . formatCommand = function ( name , args , data ) {
134120 // 6.3 IDE to debugger engine communications
135121 // @see http://www.xdebug.org/docs-dbgp.php#id30
136122
137- if ( ! args || typeof args . i === "undefined" )
138- throw new Error ( "The 'i' argument must be set!" ) ;
123+ if ( ! args || typeof args . i === "undefined" )
124+ throw new Error ( "The 'i' argument must be set!" ) ;
139125
140126 // command [SPACE] [arguments] [SPACE] -- base64(data) [NULL]
141127 var command = [ name ] ;
142- for ( var key in args ) {
128+ for ( var key in args )
143129 command . push ( " -" + key + " " + args [ key ] ) ;
144- }
145130 if ( typeof data !== "undefined" && data !== null )
146131 command . push ( " --" + exports . base64_encode ( data ) ) ;
147132
148133 command . push ( "\u0000" ) ;
149134
150135 return command . join ( "" ) ;
151- }
136+ } ;
152137
153138
154139 /**
@@ -176,11 +161,10 @@ define(function(require, exports, module)
176161 enc = "" ,
177162 tmp_arr = [ ] ;
178163
179- if ( ! data ) {
164+ if ( ! data )
180165 return data ;
181- }
182166
183- data = exports . utf8_encode ( data + '' ) ;
167+ data = exports . utf8_encode ( data + "" ) ;
184168
185169 do { // pack three octets into four hexets
186170 o1 = data . charCodeAt ( i ++ ) ;
@@ -201,16 +185,16 @@ define(function(require, exports, module)
201185 enc = tmp_arr . join ( '' ) ;
202186
203187 switch ( data . length % 3 ) {
204- case 1 :
205- enc = enc . slice ( 0 , - 2 ) + '==' ;
206- break ;
207- case 2 :
208- enc = enc . slice ( 0 , - 1 ) + '=' ;
209- break ;
188+ case 1 :
189+ enc = enc . slice ( 0 , - 2 ) + "==" ;
190+ break ;
191+ case 2 :
192+ enc = enc . slice ( 0 , - 1 ) + "=" ;
193+ break ;
210194 }
211195
212196 return enc ;
213- }
197+ } ;
214198
215199 /**
216200 * @see http://phpjs.org/functions/base64_decode:357
@@ -240,11 +224,10 @@ define(function(require, exports, module)
240224 dec = "" ,
241225 tmp_arr = [ ] ;
242226
243- if ( ! data ) {
227+ if ( ! data )
244228 return data ;
245- }
246229
247- data += '' ;
230+ data += "" ;
248231
249232 do { // unpack four hexets into three octets using index points in b64
250233 h1 = b64 . indexOf ( data . charAt ( i ++ ) ) ;
@@ -267,11 +250,11 @@ define(function(require, exports, module)
267250 }
268251 } while ( i < data . length ) ;
269252
270- dec = tmp_arr . join ( '' ) ;
253+ dec = tmp_arr . join ( "" ) ;
271254 dec = exports . utf8_decode ( dec ) ;
272255
273256 return dec ;
274- }
257+ } ;
275258
276259 /**
277260 * @see http://phpjs.org/functions/utf8_encode:577
@@ -290,11 +273,10 @@ define(function(require, exports, module)
290273 // * example 1: utf8_encode('Kevin van Zonneveld');
291274 // * returns 1: 'Kevin van Zonneveld'
292275
293- if ( argString === null || typeof argString === "undefined" ) {
276+ if ( argString === null || typeof argString === "undefined" )
294277 return "" ;
295- }
296278
297- var string = ( argString + '' ) ; // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
279+ var string = ( argString + "" ) ; // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
298280 var utftext = "" ,
299281 start , end , stringl = 0 ;
300282
@@ -306,26 +288,26 @@ define(function(require, exports, module)
306288
307289 if ( c1 < 128 ) {
308290 end ++ ;
309- } else if ( c1 > 127 && c1 < 2048 ) {
291+ }
292+ else if ( c1 > 127 && c1 < 2048 ) {
310293 enc = String . fromCharCode ( ( c1 >> 6 ) | 192 ) + String . fromCharCode ( ( c1 & 63 ) | 128 ) ;
311- } else {
294+ }
295+ else {
312296 enc = String . fromCharCode ( ( c1 >> 12 ) | 224 ) + String . fromCharCode ( ( ( c1 >> 6 ) & 63 ) | 128 ) + String . fromCharCode ( ( c1 & 63 ) | 128 ) ;
313297 }
314298 if ( enc !== null ) {
315- if ( end > start ) {
299+ if ( end > start )
316300 utftext += string . slice ( start , end ) ;
317- }
318301 utftext += enc ;
319302 start = end = n + 1 ;
320303 }
321304 }
322305
323- if ( end > start ) {
306+ if ( end > start )
324307 utftext += string . slice ( start , stringl ) ;
325- }
326308
327309 return utftext ;
328- }
310+ } ;
329311
330312 /**
331313 * @see http://phpjs.org/functions/utf8_decode:576
@@ -349,18 +331,20 @@ define(function(require, exports, module)
349331 c2 = 0 ,
350332 c3 = 0 ;
351333
352- str_data += '' ;
334+ str_data += "" ;
353335
354336 while ( i < str_data . length ) {
355337 c1 = str_data . charCodeAt ( i ) ;
356338 if ( c1 < 128 ) {
357339 tmp_arr [ ac ++ ] = String . fromCharCode ( c1 ) ;
358340 i ++ ;
359- } else if ( c1 > 191 && c1 < 224 ) {
341+ }
342+ else if ( c1 > 191 && c1 < 224 ) {
360343 c2 = str_data . charCodeAt ( i + 1 ) ;
361344 tmp_arr [ ac ++ ] = String . fromCharCode ( ( ( c1 & 31 ) << 6 ) | ( c2 & 63 ) ) ;
362345 i += 2 ;
363- } else {
346+ }
347+ else {
364348 c2 = str_data . charCodeAt ( i + 1 ) ;
365349 c3 = str_data . charCodeAt ( i + 2 ) ;
366350 tmp_arr [ ac ++ ] = String . fromCharCode ( ( ( c1 & 15 ) << 12 ) | ( ( c2 & 63 ) << 6 ) | ( c3 & 63 ) ) ;
@@ -369,6 +353,6 @@ define(function(require, exports, module)
369353 }
370354
371355 return tmp_arr . join ( '' ) ;
372- }
356+ } ;
373357
374358} ) ;
0 commit comments