Comment detail

/*コメント*/を取り除く (Nested Flatten)
std::stringで。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>

std::string remove_comment(const std::string& s)
{
    std::string ret;

    std::string::size_type i1 = 0;

    while (1)
    {
        std::string::size_type i2;

        if ((i2 = s.find("/*", i1)) == std::string::npos)
        {
            ret.append(s.substr(i1));

            break;
        }
        else
        {
            ret.append(s.substr(i1, i2 - i1));

            i1 = i2 + 2;
        }

        if ((i2 = s.find("*/", i1)) == std::string::npos)
        {
            break;
        }
        else
        {
            i1 = i2 + 2;
        }
    }

    return ret;
}

void run(const std::string& s)
{
    std::cout << remove_comment(s) << std::endl;
}

int main()
{
    run("AAA");
    run("AAA/*BBB*/");
    run("AAA/*BBB");
    run("AAA/*BBB*/CCC");
    run("AAA/*BBB/*CCC*/DDD*/EEE");
    run("AAA/a//*BB*B**/CCC");
}

Index

Feed

Other

Link

Pathtraq

loading...