/*************************************** INFORMATION *********************************************/
// This is suppose to be a scanned that are used on in a web-based situation
// I want to achive a syntax-highligter that replaces the text between my codeStarter-point and
// the end-point with HTML code. An example is this:
//
// ---- OTHER HTML CODE HERE ----
// [code]
// using System;
// using System.Web;
// namespace
// {
// class Scanner
// {
// public static string test = "blah";
// }
// }
// [/code]
// ---- OTHER HTML CODE HERE ----
//
//
//
// Author frw@frw.se, Filip Ekberg
/*************************************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace scanner
{
class Scanner
{
static void Main(string[] args)
{
Console.WriteLine(replaceCode("Here comes alot of code\n
\n[code]\n
\nusing System;\n
\npublic class frW\n
\n{\n
\n}\n
\n[/code]\n
\nThere was alot of code!", "[code]", "[/code]"));
Console.Read();
}
///
/// This method will let us send in a big text and then re-write it and add the C# highligting
/// This will return in HTML, all line-breaks inside the code will be replaced with
///
/// The string that we want to scan through
/// The code highlighting startpoint, ie [code]
/// The code highlighting endpoint, ie [/code]
/// The fixed string with all HTML replacements
public static string replaceCode(string strScan, string codeStarter, string codeEnder)
{
/******************** THE ARRAY *************************/
// ArrayList arrHighlight = new ArrayList();
// arrHighligt[0] = new ArrayList();
// arrHighlight[0].add("class", "namespace");
//
// This ArrayList is used to store the words that are supose to be replaced inside the codeStarter
// and codeEnder.
//
// [0] = identyfiers
// [1] = Operators
// [2] = misc
/********************************************************/
// This will be set to true when we are inside codeStarter
string[,] strArrIdent = new string[,] {
{"blue", "using"},
{"blue", "namepsace"}
};
string strFinalCode = string.Empty;
bool boInsideCodeStarter = false;
string[] arrScan = strScan.Split(' ');
for (int i = 0; i < arrScan.Length; i++)
{
if (arrScan[i] == codeStarter)
{
boInsideCodeStarter = true;
}
else if (boInsideCodeStarter == true)
{
for (int a = 0; a < strArrIdent.Length; a++)
{
if (arrScan[i] == strArrIdent[i][1])
{
strFinalCode = strFinalCode + "" + arrScan + "";
strFinalCode = strFinalCode.Replace("\n", "
");
}
}
}
else
{
strFinalCode = strFinalCode + arrScan[i];
}
}
return strScan;
}
}
}