@@ -280,64 +280,27 @@ function __extractTokens() {
280
280
}
281
281
}
282
282
unset($ allTokens );
283
- $ this ->basic ( );
284
- $ this ->basic ( ' __c ' );
285
- $ this ->extended ( );
286
- $ this ->extended ( ' __dc ' , 2 );
287
- $ this ->extended ( ' __n ' , 0 , true );
288
- $ this ->extended ('__dn ' , 2 , true );
289
- $ this ->extended ('__dcn ' , 4 , true );
283
+ $ this ->__parse ( ' __ ' , array ( ' singular ' ) );
284
+ $ this ->__parse ( ' __n ' , array ( ' singular ' , ' plural ' ) );
285
+ $ this ->__parse ( ' __d ' , array ( ' domain ' , ' singular ' ) );
286
+ $ this ->__parse ( ' __c ' , array ( ' singular ' ) );
287
+ $ this ->__parse ( ' __dc ' , array ( ' domain ' , ' singular ' ) );
288
+ $ this ->__parse ('__dn ' , array ( ' domain ' , ' singular ' , ' plural ' ) );
289
+ $ this ->__parse ('__dcn ' , array ( ' domain ' , ' singular ' , ' plural ' ) );
290
290
}
291
291
$ this ->__buildFiles ();
292
292
$ this ->__writeFiles ();
293
293
$ this ->out ('Done. ' );
294
294
}
295
295
296
296
/**
297
- * Will parse __(), __c() functions
297
+ * Parse tokens
298
298
*
299
299
* @param string $functionName Function name that indicates translatable string (e.g: '__')
300
+ * @param array $map Array containing what variables it will find (e.g: domain, singular, plural)
300
301
* @access public
301
302
*/
302
- function basic ($ functionName = '__ ' ) {
303
- $ count = 0 ;
304
- $ tokenCount = count ($ this ->__tokens );
305
-
306
- while (($ tokenCount - $ count ) > 3 ) {
307
- list ($ countToken , $ parenthesis , $ middle , $ right ) = array ($ this ->__tokens [$ count ], $ this ->__tokens [$ count + 1 ], $ this ->__tokens [$ count + 2 ], $ this ->__tokens [$ count + 3 ]);
308
- if (!is_array ($ countToken )) {
309
- $ count ++;
310
- continue ;
311
- }
312
-
313
- list ($ type , $ string , $ line ) = $ countToken ;
314
- if (($ type == T_STRING ) && ($ string == $ functionName ) && ($ parenthesis == '( ' )) {
315
-
316
- if (in_array ($ right , array (') ' , ', ' ))
317
- && (is_array ($ middle ) && ($ middle [0 ] == T_CONSTANT_ENCAPSED_STRING ))) {
318
-
319
- if ($ this ->__oneFile === true ) {
320
- $ this ->__strings [$ this ->__formatString ($ middle [1 ])][$ this ->__file ][] = $ line ;
321
- } else {
322
- $ this ->__strings [$ this ->__file ][$ this ->__formatString ($ middle [1 ])][] = $ line ;
323
- }
324
- } else {
325
- $ this ->__markerError ($ this ->__file , $ line , $ functionName , $ count );
326
- }
327
- }
328
- $ count ++;
329
- }
330
- }
331
-
332
- /**
333
- * Will parse __d(), __dc(), __n(), __dn(), __dcn()
334
- *
335
- * @param string $functionName Function name that indicates translatable string (e.g: '__')
336
- * @param integer $shift Number of parameters to shift to find translateable string
337
- * @param boolean $plural Set to true if function supports plural format, false otherwise
338
- * @access public
339
- */
340
- function extended ($ functionName = '__d ' , $ shift = 0 , $ plural = false ) {
303
+ function __parse ($ functionName , $ map ) {
341
304
$ count = 0 ;
342
305
$ tokenCount = count ($ this ->__tokens );
343
306
@@ -362,50 +325,28 @@ function extended($functionName = '__d', $shift = 0, $plural = false) {
362
325
$ position ++;
363
326
}
364
327
365
- if ( $ plural ) {
366
- $ end = $ position + $ shift + 7 ;
367
-
368
- if ($ this ->__tokens [$ position + $ shift + 5 ] === ' ) ' ) {
369
- $ end = $ position + $ shift + 5 ;
328
+ $ mapCount = count ( $ map );
329
+ $ strings = array () ;
330
+ while ( count ( $ strings ) < $ mapCount && ( $ this -> __tokens [ $ position ] == ' , ' || $ this -> __tokens [ $ position ][ 0 ] == T_CONSTANT_ENCAPSED_STRING )) {
331
+ if ($ this ->__tokens [$ position][ 0 ] == T_CONSTANT_ENCAPSED_STRING ) {
332
+ $ strings [] = $ this -> __tokens [ $ position ][ 1 ] ;
370
333
}
371
-
372
- if (empty ($ shift )) {
373
- list ($ singular , $ firstComma , $ plural , $ seoncdComma , $ endParenthesis ) = array ($ this ->__tokens [$ position ], $ this ->__tokens [$ position + 1 ], $ this ->__tokens [$ position + 2 ], $ this ->__tokens [$ position + 3 ], $ this ->__tokens [$ end ]);
374
- $ condition = ($ seoncdComma == ', ' );
375
- } else {
376
- list ($ domain , $ firstComma , $ singular , $ seoncdComma , $ plural , $ comma3 , $ endParenthesis ) = array ($ this ->__tokens [$ position ], $ this ->__tokens [$ position + 1 ], $ this ->__tokens [$ position + 2 ], $ this ->__tokens [$ position + 3 ], $ this ->__tokens [$ position + 4 ], $ this ->__tokens [$ position + 5 ], $ this ->__tokens [$ end ]);
377
- $ condition = ($ comma3 == ', ' );
378
- }
379
- $ condition = $ condition &&
380
- (is_array ($ singular ) && ($ singular [0 ] == T_CONSTANT_ENCAPSED_STRING )) &&
381
- (is_array ($ plural ) && ($ plural [0 ] == T_CONSTANT_ENCAPSED_STRING ));
382
- } else {
383
- if ($ this ->__tokens [$ position + $ shift + 5 ] === ') ' ) {
384
- $ comma = $ this ->__tokens [$ position + $ shift + 3 ];
385
- $ end = $ position + $ shift + 5 ;
386
- } else {
387
- $ comma = null ;
388
- $ end = $ position + $ shift + 3 ;
389
- }
390
-
391
- list ($ domain , $ firstComma , $ text , $ seoncdComma , $ endParenthesis ) = array ($ this ->__tokens [$ position ], $ this ->__tokens [$ position + 1 ], $ this ->__tokens [$ position + 2 ], $ comma , $ this ->__tokens [$ end ]);
392
- $ condition = ($ seoncdComma == ', ' || $ seoncdComma === null ) &&
393
- (is_array ($ domain ) && ($ domain [0 ] == T_CONSTANT_ENCAPSED_STRING )) &&
394
- (is_array ($ text ) && ($ text [0 ] == T_CONSTANT_ENCAPSED_STRING ));
334
+ $ position ++;
395
335
}
396
336
397
- if (($ endParenthesis == ') ' ) && $ condition ) {
337
+ if ($ mapCount == count ($ strings )) {
338
+ extract (array_combine ($ map , $ strings ));
398
339
if ($ this ->__oneFile === true ) {
399
- if ($ plural ) {
400
- $ this ->__strings [$ this ->__formatString ($ singular[ 1 ] ) . "\0" . $ this ->__formatString ($ plural[ 1 ] )][$ this ->__file ][] = $ line ;
340
+ if (isset ( $ plural) ) {
341
+ $ this ->__strings [$ this ->__formatString ($ singular ) . "\0" . $ this ->__formatString ($ plural )][$ this ->__file ][] = $ line ;
401
342
} else {
402
- $ this ->__strings [$ this ->__formatString ($ text [ 1 ] )][$ this ->__file ][] = $ line ;
343
+ $ this ->__strings [$ this ->__formatString ($ singular )][$ this ->__file ][] = $ line ;
403
344
}
404
345
} else {
405
346
if ($ plural ) {
406
- $ this ->__strings [$ this ->__file ][$ this ->__formatString ($ singular[ 1 ] ) . "\0" . $ this ->__formatString ($ plural[ 1 ] )][] = $ line ;
347
+ $ this ->__strings [$ this ->__file ][$ this ->__formatString ($ singular ) . "\0" . $ this ->__formatString ($ plural )][] = $ line ;
407
348
} else {
408
- $ this ->__strings [$ this ->__file ][$ this ->__formatString ($ text [ 1 ] )][] = $ line ;
349
+ $ this ->__strings [$ this ->__file ][$ this ->__formatString ($ singular )][] = $ line ;
409
350
}
410
351
}
411
352
} else {
0 commit comments