• entries
    707
  • comments
    1173
  • views
    433807

Sucks to be you!

Sign in to follow this  
Programmer16

77 views

You poor saps have to put up with this journal for another year. It's ok, you can cry.

In other news, I finally finished my C++ source-code highlighting PHP script. I say finally because I started it in '04. I just picked it up off of an old CD and finished it (after about 30 minutes of complaining.) Getting the comment highlighting code to work was the only thing left to do so I finished it.

You can check out an example over here:highlight_example.php
As you can it isn't perfect, but it works so I'm happy.

Here is my function if anybody is having problems with the same thing:

function FormatCpp($CodeToFormat)
{
$CodeToFormat = str_replace("\t", " ", $CodeToFormat);
$CodeToFormat = str_replace(" ", " ", $CodeToFormat);

$Regex= array(
"/\basm\b/",
"/\bauto\b/",
"/\bbad_cast\b/",
"/\bbad_typeid\b/",
"/\bbool\b/",
"/\bbreak\b/",
"/\bcase\b/",
"/\bcatch\b/",
"/\bchar\b/",
"/\bclass\b/",
"/\bconst\b/",
"/\bconst_cast\b/",
"/\bcontinue\b/",
"/\bdefault\b/",
"/\bdelete\b/",
"/\bdo\b/",
"/\bdouble\b/",
"/\bdynamic_cast\b/",
"/\belse\b/",
"/\benum\b/",
"/\bexcept\b/",
"/\bexplicit\b/",
"/\bextern\b/",
"/\bfalse\b/",
"/\bfinally\b/",
"/\bfloat\b/",
"/\bfor\b/",
"/\bfriend\b/",
"/\bgoto\b/",
"/\bif\b/",
"/\binline\b/",
"/\bint\b/",
"/\blong\b/",
"/\bmutable\b/",
"/\bnamespace\b/",
"/\bnew\b/",
"/\boperator\b/",
"/\bprivate\b/",
"/\bprotected\b/",
"/\bpublic\b/",
"/\bregister\b/",
"/\breinterpret_cast\b/",
"/\breturn\b/",
"/\bshort\b/",
"/\bsigned\b/",
"/\bsizeof\b/",
"/\bstatic\b/",
"/\bstatic_cast\b/",
"/\bstruct\b/",
"/\bswitch\b/",
"/\btemplate\b/",
"/\bthis\b/",
"/\bthrow\b/",
"/\btrue\b/",
"/\btry\b/",
"/\btype_info\b/",
"/\btypedef\b/",
"/\btypeid\b/",
"/\btypename\b/",
"/\bunion\b/",
"/\bunsigned\b/",
"/\busing\b/",
"/\bvirtual\b/",
"/\bvoid\b/",
"/\bvolatile\b/",
"/\bwhile\b/",
"/\ballocate\b/",
"/\b__inline\b/",
"/\bproperty\b/",
"/\b__asm\b/",
"/\b__int8\b/",
"/\bselectany\b/",
"/\b__based\b/",
"/\b__int16\b/",
"/\b__single_inheritance\b/",
"/\b__cdecl\b/",
"/\b__int32\b/",
"/\b__stdcall\b/",
"/\b__declspec\b/",
"/\b__int64\b/",
"/\bthread\b/",
"/\bdllexport\b/",
"/\b__leave\b/",
"/\b__try\b/",
"/\bdllimport\b/",
"/\b__multiple_inheritance\b/",
"/\buuid\b/",
"/\b__except\b/",
"/\bnaked\b/",
"/\b__uuidof\b/",
"/\b__fastcall\b/",
"/\bnothrow\b/",
"/\b__virtual_inheritance\b/",
"/\b__finally\b/",
"/\b#define\b/",
"/\b#error\b/",
"/\b#import\b/",
"/\b#undef\b/",
"/\b#elif\b/",
"/\b#if\b/",
"/\b#include\b/",
"/\b#else\b/",
"/\b#ifdef\b/",
"/\b#line\b/",
"/\b#endif\b/",
"/\b#ifndef\b/",
"/\b#pragma\b/",
"/(\/\/.*)/",
"/(\/\*.*?\*\/)/s",
);

$Replace = array(
"asm",
"auto",
"bad_cast",
"bad_typeid",
"bool",
"break",
"case",
"catch",
"char",
"class",
"const",
"const_cast",
"continue",
"default",
"delete",
"do",
"double",
"dynamic_cast",
"else",
"enum",
"except",
"explicit",
"extern",
"false",
"finally",
"float",
"for",
"friend",
"goto",
"if",
"inline",
"int",
"long",
"mutable",
"namespace",
"new",
"operator",
"private",
"protected",
"public",
"register",
"reinterpret_cast",
"return",
"short",
"signed",
"sizeof",
"static",
"static_cast",
"struct",
"switch",
"template",
"this",
"throw",
"true",
"try",
"type_info",
"typedef",
"typeid",
"typename",
"union",
"unsigned",
"using",
"virtual",
"void",
"volatile",
"while",
"allocate",
"__inline",
"property",
"__asm",
"__int8",
"selectany",
"__based",
"__int16",
"__single_inheritance",
"__cdecl",
"__int32",
"__stdcall",
"__declspec",
"__int64",
"thread",
"dllexport",
"__leave",
"__try",
"dllimport",
"__multiple_inheritance",
"uuid",
"__except",
"naked",
"__uuidof",
"__fastcall",
"nothrow",
"__virtual_inheritance",
"__finally",
"#define",
"#error",
"#import",
"#undef",
"#elif",
"#if",
"#include",
"#else",
"#ifdef",
"#line",
"#endif",
"#ifndef",
"#pragma",

"$1",
"$1",
);

$CodeToFormat = preg_replace($Regex, $Replace, $CodeToFormat);
$CodeToFormat = str_replace("\n", "
"
, $CodeToFormat);
$CodeToFormat = "
" . $CodeToFormat . "
"
;

return $CodeToFormat;
}






More GUI, Malathedra, and website stuff in tomorrow's episode.

Edit: I finally put a new site up. You can go here to check it out, but it is no where near completed. I need to figure out how to add an admin panel and such still.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now