I have to wonder... Why did you not use the already existing syntaxhighlighting class that is behind the SRC_EMBED code in the main site? It has a great coverage of different languages (and a cooler color theme selection!)*.
I'm just sad seeing that my code is not being used :(
*) At least, when you upgrade it in case it's an older version
So here's my test on PHP, from
http://bisqwit.iki.fi/story/howto/php/#StringConstructs.
[code php]<?php
// These two statements are equivalent:
$a = "Apples are $x each.";
$a = 'Apples are ' . $x . ' each.';
// These two statements are equivalent:
$a = "Apples are \$x each.";
$a = 'Apples are $x each.';
// These three statements are equivalent:
$a = "Your {$item->name} is {$item->kind} and expires in {$item->eta} days.";
$a = "Your ${item->name} is ${item->kind} and expires in ${item->eta} days.";
$a = 'Your ' . $item->name . ' is '
. $item->kind . ' and expires in '
. $item->eta . ' days.';
// These four statements are equivalent:
$a = "The file is {$stat["size"]} bytes long.";
$a = "The file is {$stat['size']} bytes long.";
$a = 'The file is ' . $stat["size"] . ' bytes long.';
$a = 'The file is ' . $stat['size'] . ' bytes long.';
// Variable inclusions may be very complex, even recursive,
// to the chagrin of writers of syntax highlighters.
// These two statements are equivalent:
$a = "This is {$table["subtable{$subnums["current"]}"][$position['now']]}.";
$a = 'This is ' . $table[ 'subtable' . $subnums['current'] ]
[ $position['now'] ]
. '.'; /* still in sync? */[/code]
Another one, of BASIC:[code basic]10 DEFINT A-Z
20 SCREEN 0: WIDTH 40,25: KEY OFF
30 ' Define all distinct tetromino shapes as bitmasks
31 DATA CC,8C4,6C,4444,F0,264,C6,E4,4C4,4E0,464,8E,C88,E2,226,2E,88C,E8,622
32 REM e.g. 8C4 = 1000, 2E = 0010
33 REM 1100 1110
34 REM 0100 and so on.
35 DIM SHAPES(18): FOR A=0 TO 18: READ S$: SHAPES(A)=VAL("&H"+S$): NEXT
40 ' Define the mappings of block number -> block shape
41 DATA 0,0,0,0, 1,2,1,2, 3,4,3,4, 5,6,5,6, 7,8,9,10, 11,12,13,14, 15,16,17,18
45 DIM INDICES(28): FOR A=0 TO 27: READ INDICES(A): NEXT
50 ' This function reads the given slot from the given block in given rotation.
52 DIM BITMASKS(15): FOR A=0 TO 14: BITMASKS(A) = 2^A: NEXT'Note: 2^15=overflow
55 DEF FNBLOCK(BL,ROT,X,Y) = SHAPES(INDICES(BL*4+ROT))AND BITMASKS(Y*4+X)
900 ' Subroutine for drawing a "pixel", i.e. one block slot.
901 ' Params: x,y, c
910 LOCATE Y+1,X+1: AREA(X,Y)=C
920 IF C THEN COLOR C AND 15: PRINT CHR$(219); : RETURN
930 COLOR 1: PRINT FNEMPTY$(X);
940 RETURN
999 WIDTH 80: COLOR 7,0: PRINT "GAME OVER": KEY ON: END ' simple.[/code]Gotcha.
And for C++:
[code c++]template<typename T>
struct Array256x256of: public Array256x256of_Base
{
public:
T data[256*256];
public:
Array256x256of() { }
virtual ~Array256x256of() { }
public:
virtual uint32 GetLive(unsigned method, unsigned index, unsigned timer) const
{
return (data[index].*(T::methods[method]))(timer);
}
virtual uint32 GetStatic(unsigned index) const
{
return GetLive(bgmethod, index, 0);
}
virtual void Set(unsigned index, uint32 p, unsigned timer)
{
data[index].set(p, timer);
}
};[/code]