tsunami

log in
history

URL Grammar code

Luke Breuer
2008-12-26 04:56 UTC
tags: tsunami

string lettersNumbers = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string wikiLegal = lettersNumbers + "-_.~";
string wikiReserved = "!*'();:@&=+$,/?%#[]";
string illegal = @"#&?|%*:<>""/";
string legal = lettersNumbers + "~`!@$^()_-+=[]{};',. ";
string[] lines = new string[] 
    {
        "             ",
        "             ",
        "             ",
        "             ",
        "wiki legal   ",
        "wiki reserve ",
        "exp. legal   ",
        "exp. illegal ",
        "questionable ",
        "ASP.NET rest ",
    };



for (int i = 33; i < 128; i++)
{
    char c = (char)i;
    if (char.IsLetterOrDigit(c))
    {
        if (Array.IndexOf(new char[] { 'b', 'B', '1' }, c) >= 0)
        {
            for (int k = 0; k < lines.Length; k++)
                lines[k] += '-';

            continue;
        }
        if (Array.IndexOf(new char[] { 'a', 'A', 'z', 'Z', '0', '9' }, c) < 0)
            continue;

    }

    Converter<string, bool> contains = delegate(string s)
    {
        return s.IndexOf(c) >= 0;
    };
    Converter<string, char> check = delegate(string s)
    {
        return contains(s) ? 'x' : ' ';
    };

    int j = -1;
    lines[++j] += (i / 100).ToString();
    lines[++j] += ((i % 100) / 10).ToString();
    lines[++j] += (i % 10).ToString();
    lines[++j] += c;
    lines[++j] += check(wikiLegal);
    lines[++j] += check(wikiReserved);
    lines[++j] += check(legal);
    lines[++j] += check(illegal);
    lines[++j] += contains(legal) && !contains(wikiLegal + wikiReserved) ? 'x' : ' ';
    lines[++j] += contains(wikiLegal + wikiReserved) && !contains(legal) ? 'x' : ' ';
}

foreach (string line in lines)
    Console.WriteLine(line);