This is an exercise to use C++, Cevelop IDE & libtidy rather than the HTML Tidy command line tool. The program just reads from standarg input, processes the contents with HTML Tidy then puts the cleaned up version to standard out. Errors and diagnostics go to standard error. Function tidyit takes a std::string and returns one with error messages going to stderr while main handles the standard I/O.I am using the most current C++17 with no concerns for older versions. The version of Cevelop IDE is 1.7.1. HTML Tidy provides both a command line tool and a C library, libtidy. The code is based upon the C code in the Sample Program. I am looking for improvements given it is in C++ rather than the original in C.// tidyit.cpp#include <sstream>#include <iostream>#include <string>const std::string tidyit(const std::string a_input);           // Change to auto in cevelop 1.8.int main(int argc, char **argv) {   std::stringstream input;   input << std::cin.rdbuf();   std::cout << tidyit(input.str());   }#include <tidy/tidy.h>#include <tidy/buffio.h>bool is_severe_error(int a_code){return (a_code<0);}           // Change to auto in cevelop 1.8.const std::string tidyit(const std::string a_input) {          // Change to auto in cevelop 1.8.   TidyBuffer errbuf = {0}, outbuf = {0};   TidyDoc tdoc = tidyCreate();   tidyOptSetInt(tdoc, TidyIndentContent, yes);   tidyOptSetBool(tdoc, TidyXhtmlOut, yes);   tidyOptSetBool(tdoc, TidyForceOutput,yes);   int rc{-1};                                                 // Change to auto in cevelop 1.8.   if (is_severe_error(rc=tidySetErrorBuffer(tdoc, &errbuf))         || is_severe_error(rc=tidyParseString(tdoc, a_input.c_str()))         || is_severe_error(rc=tidyCleanAndRepair(tdoc))         || is_severe_error(rc=tidyRunDiagnostics(tdoc))         || is_severe_error(rc=tidySaveBuffer(tdoc,&outbuf))){      std::cerr << tidyit-A severe error ( << rc << ) occurred.\n;      }   else {      if(errbuf.bp)         std::cerr << tidyit-Diagnostics:\n\n << errbuf.bp << \n;      }   const std::string outstr{(char*)(outbuf.bp)};   tidyBufFree(&outbuf);   tidyBufFree(&errbuf);   tidyRelease(tdoc);   return outstr;   }Cevelop C++ IDE Version: 1.7.1-201704211123Compiler infoCommand: clang++-4.0All options: -std=c++1z -O0 -g3 -Wall -c -fmessage-length=0  -Wno-attributesLibrary infoLibraries: tidyUpdated code available at: CodeReview - HTML Tidy Sample Program in C++17 (pastebin)
HTML Tidy Sample Program in C++17
c++;html;formatting;c++17