1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 11:18:40 +08:00
Files
CMake/Tests/FindOpenSP/Test/main.cxx
Kitware Robot 0b96ae1f6a Revise C++ coding style using clang-format with "east const"
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`, now with "east const" enforcement.
Use `clang-format` version 18.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.

Issue: #26123
2025-01-23 13:09:50 -05:00

56 lines
1.2 KiB
C++

#include <cassert>
#include <string>
#include "ParserEventGeneratorKit.h"
std::string CharStringtostring(SGMLApplication::CharString const source)
{
// The CharString type might have multi-byte characters if SP_MULTI_BYTE was
// defined
std::string result;
result.resize(source.len);
for (size_t i = 0; i < source.len; i++) {
result[i] = static_cast<char>(source.ptr[i]);
}
return result;
}
class OutlineApplication : public SGMLApplication
{
public:
OutlineApplication()
: depth_(0)
{
}
void startElement(StartElementEvent const& event)
{
for (unsigned i = 0; i < depth_; i++)
parsedOutput += "\t";
parsedOutput += CharStringtostring(event.gi);
depth_++;
}
void endElement(EndElementEvent const&) { depth_--; }
std::string parsedOutput;
private:
unsigned depth_;
};
int main()
{
std::string expectedOutput = "TESTDOC\tTESTELEMENT";
char file_name[] = "test.sgml";
char* files[] = { file_name, 0 };
ParserEventGeneratorKit parserKit;
EventGenerator* egp = parserKit.makeEventGenerator(1, files);
OutlineApplication app;
unsigned nErrors = egp->run(app);
assert(nErrors == 0);
assert(app.parsedOutput.compare(expectedOutput) == 0);
delete egp;
return 0;
}