Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Beautiful Code

Name: Anonymous 2008-10-02 19:21

Sup /prog/-riders
In this thread we post beautiful code. They can be from your job, school, whatever.

Here's a recursive regex parser with support for character classes, $ and & anchors, and the . and * metachars.


int matchhere(char* regexp, char* text);
int matchstar(int c, char* regexp, char* text)
{
    do {
        if (matchhere(regexp, text))
            return 1;
    } while (*text != '\0' && (*text++ == c || c == '.'));
    return 0;
}

int matchhere(char* regexp, char* text)
{
    if (regexp[0] == '\0')
        return 1;
    if (regexp[1] == '*')
        return matchstar(regexp[0], regexp+2, text);
    if (regexp[0] == '$' && regexp[1] == '\0')
        return *text == '\0';
    if (*text != '\0' && (regexp[0] == '.' || regexp[0] == *text))
        return matchhere(regexp+1, text+1);
    return 0;
}

int match(char* regexp, char* text)
{
    if (regexp[0] == '^')
        return matchhere(regexp+1, text);
    do {
        if (matchhere(regexp, text))
            return 1;
    } while (*text++ != '\0');
    return 0;
}

Name: Anonymous 2008-10-03 22:47

>>40
_lower

Name: Anonymous 2008-10-04 1:18

__LOWER__

Name: Anonymous 2008-10-04 1:54

>>37
>>38
>>39
if you already know they're letters, then use this:
#define my_tolower(A) ((A)|32)

Name: Anonymous 2008-10-04 2:07

>>38-39
too bad it doesn't work.

Name: Anonymous 2008-10-04 2:21

>>44
What are you talking about?  It supports all 8 ASCII characters and successfully converts them to lowercase letters 7 out of 8 times!

Name: Anonymous 2008-10-04 2:54

ITT: People who think America is the whole world.

Name: Anonymous 2008-10-04 3:13

>>46
It's not the whole world but it is the standard.

Name: Anonymous 2008-10-04 3:50

>>46
i did the getline and I'm brazilian
o:

Name: Anonymous 2008-10-04 4:38

>>47
>>48
Eat UTF and die.

Name: Anonymous 2008-10-04 5:28

if OP thinks that code is beatufil they are fucking clueless

Name: Anonymous 2008-10-04 5:38

ITT IDIOCY

Name: Anonymous 2008-10-04 6:47

ITT Amerifags

Name: Anonymous 2008-10-04 10:07

ITB fags

Name: Anonymous 2008-10-04 10:08

IHBTC

Name: Anonymous 2008-10-05 3:19

>>40
it doesnt work

Name: Anonymous 2008-10-06 8:38


function buildTree($f)
{
    $tree = array();
    foreach ($f as $k => $z) {
        $tree[$k] = array();
    }
    foreach ($f as $k => $v) {
        $tree[$v['parent']][$k] = &$tree[$k];
    }
    return $tree;
}

Name: ​​​​​​​​​​ 2010-09-07 19:40


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List