#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 " ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKc3RkOjpzdHJpbmcgdW5pbmRlbnQoY29uc3QgY2hhciogcCkKewogICAgc3RkOjpzdHJpbmcgcmVzdWx0OwogICAgaWYgKHBbMF0gPT0gJ1xuJykgKytwOwogICAgY29uc3QgY2hhciogcF9sZWFkaW5nID0gcDsKICAgIHdoaWxlIChzdGQ6Omlzc3BhY2UoKnApICYmICpwICE9ICdcbicpCiAgICAgICAgKytwOwogICAgc2l6ZV90IGxlYWRpbmdfbGVuID0gcCAtIHBfbGVhZGluZzsKICAgIHdoaWxlICgqcCkKICAgIHsKICAgICAgICByZXN1bHQgKz0gKnA7CiAgICAgICAgaWYgKCpwID09ICdcbicpCiAgICAgICAgewogICAgICAgICAgICArK3A7CiAgICAgICAgICAgIGZvciAoc2l6ZV90IGkgPSAwOyBpIDwgbGVhZGluZ19sZW47ICsraSkKICAgICAgICAgICAgICAgIGlmIChwW2ldICE9IHBfbGVhZGluZ1tpXSkKICAgICAgICAgICAgICAgICAgICBnb3RvIGRvbnRfc2tpcF9sZWFkaW5nOwogICAgICAgICAgICBwICs9IGxlYWRpbmdfbGVuOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgICAgICsrcDsKICAgICAgZG9udF9za2lwX2xlYWRpbmc6IDsKICAgIH0KICAgIHJldHVybiByZXN1bHQ7Cn0KCgppbnQgbWFpbigpIHsKICAgIHN0ZDo6Y291dCA8PCAiW1siIDw8IHVuaW5kZW50KFIiKAogICAgICAgIFRoaXMgaXMgdGhlIGZpcnN0IGxpbmUuCiAgICAgICAgVGhpcyBpcyB0aGUgc2Vjb25kIGxpbmUuCiAgICAgICAgVGhpcyBpcyB0aGUgdGhpcmQgbGluZS4KICAgICAgICApIikgPDwgIl1dXG4iOwoKICAgIHN0ZDo6Y291dCA8PCAiW1siIDw8IHVuaW5kZW50KFIiKAogICAgICAgIFRoaXMgaXMgdGhlIGZpcnN0IGxpbmUuCiAgICAgICAgICAgIFRoaXMgaXMgdGhlIHNlY29uZCBsaW5lLCBub3cgaW5kZW50ZWQgZm91ciBtb3JlIHNwYWNlcy4KICAgICAgICBUaGlzIGlzIHRoZSB0aGlyZCBsaW5lLgogIFRoaXMgaXMgdGhlIGZvdXJ0aCBsaW5lLCBub3cgaW5kZW50ZWQgMiBzcGFjZXMsIHdoaWNoIGlzIGxlc3MgdGhhbiB0aGUgZmlyc3QuCiAgICAgICAgKSIpIDw8ICJdXVxuIjsKfQ==