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

C++ String Parsing

Name: Anonymous 2011-09-20 0:32

A little explanation before I get to my copypasta....Each line in an array (already populated), parseLinks is called to determine if at any point in that line a quotation mark is found as one of the characters. If it is, I want to begin copying from the next letter, until the letter before a closing quotation mark. From there, I want to determine if the string is in-fact a link, which is where the compare comes in. Links are passed back to main, whereas an empty string is passed back if it isn't a link. (and a counter I have in main isn't iterated, so it skips that one and tries to re-write in that array block...but that's irrelevant)

I'm guessing my code is fucked up for the detection of the quotation mark(s), because I'm not getting any values sent back in the string.


string parseLinks(string str)
{
    const int len = str.length();
    string link = "";
    bool quotes = false, islink = false;
    string compare[5] = {".htm",".html",".php",".asp",".pdf"};
   
    //Parse all quoted text
    for (int i = 0; i != len; i++)
    {
        //Change bool if quote found
        if (str[i] == '"')
        {
            if (quotes == false)
                quotes = true;
            else
                quotes = false;
        }

        //If bool true, and char is not a quote, add to link string
        if (quotes == true && str[i] != '"')
            link += str[i];
    }

    //Discard non-link text
    for (int i = 0; i < 5; i++)
    {
        if (link.compare(compare[i]) == 0)
            islink = true;
    }

    //If not a link, empty return string
    if (islink == false)
        link = "";

    return link;
}

Name: Anonymous 2011-09-20 1:49



    //Parse all quoted text
    int i, c=0;
    for (i = 0; i <= len; i++)
    {

    //>> bool true, and char is not a quote, add to link string
        if ((quotes == true) + ((int)str[i] != 34) == 2)
            c++;
            link[c] = str[i]; //??

        //Change bool if quote found
        if ((int)str[i] == 34)
            quotes = !quotes;
    }


doesn't look like it's broken though....

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