File: main.cxx

package info (click to toggle)
cmake 4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 152,344 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (55 lines) | stat: -rw-r--r-- 1,243 bytes parent folder | download | duplicates (3)
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
54
55
#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;
}