3 |
#include <algorithm> |
#include <algorithm> |
4 |
#include "string_utility/Converter.hh" |
#include "string_utility/Converter.hh" |
5 |
|
|
6 |
|
#define TAG_SEPARATOR " " |
7 |
|
|
8 |
|
std::string const NEWLINE = "\n"; |
9 |
|
|
10 |
void GEDCOMParser::GEDCOMWriter::WriteString(std::string const &name, std::string const &value) |
void GEDCOMParser::GEDCOMWriter::WriteString(std::string const &name, std::string const &value) |
11 |
{ |
{ |
12 |
if (value != "") |
if (value != "") |
13 |
{ |
{ |
14 |
outfile << name << " " << value << std::endl; |
_buffer = _buffer + name + TAG_SEPARATOR + value + NEWLINE; |
15 |
} |
} |
16 |
return; |
return; |
17 |
} |
} |
34 |
|
|
35 |
void GEDCOMParser::GEDCOMWriter::WriteText(std::string const &name, std::string const &value, int ref_level) |
void GEDCOMParser::GEDCOMWriter::WriteText(std::string const &name, std::string const &value, int ref_level) |
36 |
{ |
{ |
|
std::string const NEWLINE = "\n"; |
|
37 |
int const LINE_LENGTH = 255; |
int const LINE_LENGTH = 255; |
38 |
std::string const level = toString < int >(ref_level + 1); |
std::string const level = toString < int >(ref_level + 1); |
39 |
|
|
46 |
std::string line_prefix = ""; |
std::string line_prefix = ""; |
47 |
|
|
48 |
bool found = false; |
bool found = false; |
49 |
outfile << name << " "; |
_buffer = _buffer + name + TAG_SEPARATOR; |
50 |
do |
do |
51 |
{ |
{ |
52 |
found = false; |
found = false; |
85 |
} |
} |
86 |
head = std::string(tmp, 0, head_length); |
head = std::string(tmp, 0, head_length); |
87 |
|
|
88 |
outfile << line_prefix + head << std::endl; |
_buffer = _buffer + line_prefix + head + NEWLINE; |
89 |
|
|
90 |
if (head_length != tmp.length()) |
if (head_length != tmp.length()) |
91 |
{ |
{ |
108 |
{ |
{ |
109 |
if (value != 0) |
if (value != 0) |
110 |
{ |
{ |
111 |
outfile << name << " " << value->getRawValue() << std::endl; |
_buffer = _buffer + name + TAG_SEPARATOR + value->getRawValue() + NEWLINE; |
|
} |
|
|
return; |
|
|
} |
|
|
|
|
|
void GEDCOMParser::GEDCOMWriter::setFile(std::string const &filename) |
|
|
{ |
|
|
if (outfile.is_open()) |
|
|
{ |
|
|
outfile.close(); |
|
|
} |
|
|
_filename = filename; |
|
|
return; |
|
|
} |
|
|
|
|
|
void GEDCOMParser::GEDCOMWriter::OpenTransaction(void) |
|
|
{ |
|
|
if (_filename != "") |
|
|
{ |
|
|
outfile.open(_filename.c_str()); |
|
|
} |
|
|
else |
|
|
{ |
|
|
outfile.std::basic_ios<char>::rdbuf(std::cout.rdbuf()); |
|
|
|
|
112 |
} |
} |
113 |
return; |
return; |
114 |
} |
} |
115 |
|
|
|
void GEDCOMParser::GEDCOMWriter::CloseTransaction(void) |
|
|
{ |
|
|
outfile.close(); |
|
|
return; |
|
|
} |
|