#include <iostream>
#include <string>

std::string unindent(const char* p)
{
    std::string result;
    if (p[0] == '\n') ++p;
    const char* p_leading = p;
    while (std::isspace(*p) && *p != '\n')
        ++p;
    size_t leading_len = p - p_leading;
    while (*p)
    {
        result += *p;
        if (*p == '\n')
        {
            ++p;
            for (size_t i = 0; i < leading_len; ++i)
                if (p[i] != p_leading[i])
                    goto dont_skip_leading;
            p += leading_len;
        }
        else
            ++p;
      dont_skip_leading: ;
    }
    return result;
}


int main() {
    std::cout << "[[" << unindent(R"(
        This is the first line.
        This is the second line.
        This is the third line.
        )") << "]]\n";

    std::cout << "[[" << unindent(R"(
        This is the first line.
            This is the second line, now indented four more spaces.
        This is the third line.
  This is the fourth line, now indented 2 spaces, which is less than the first.
        )") << "]]\n";
}