Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

several improvements #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fmt_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class html_text {
{
text+=fmt.format(opt)+s;
}
void write_char(char ch)
{
text += fmt.format(opt);
text.push_back(ch);
}
std::string close() { return fmt.close(); }
// void write(char c) { write(std::string()+c); }
void clear() { text.clear(); fmt.clear(); }
Expand Down
6 changes: 6 additions & 0 deletions rtf2html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ int main(int argc, char **argv)
break;
}
}
else if (kw.is_symbol_8bit())
{
par_html.write_char(kw.symbol_8bit());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not .write()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, write_char is probably redundant

}
else //kw.is_control_char
{
if (bAsterisk)
Expand Down Expand Up @@ -577,6 +581,8 @@ int main(int argc, char **argv)
par_html.write(*buf_in++);
}
}
if (html.empty() && !par_html.str().empty())
html = par_html.str();
file_out<<"<html>\n<head>\n<STYLE type=\"text/css\">\nbody {padding-left:"
<<rint(iMarginLeft/20)<<"pt;width:"<<rint((iDocWidth/20))<<"pt}\n"
<<"p {margin-top:0pt;margin-bottom:0pt}\n"<<formatting_options::get_styles()<<"</STYLE>\n"
Expand Down
30 changes: 27 additions & 3 deletions rtf_keyword.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class rtf_keyword{
int param;
char ctrl_chr;
bool is_ctrl_chr;

char value_8bit;
bool is_8bit;

public:
// iter must point after the backslash starting the keyword. We don't check it.
// after construction, iter points at the char following the keyword
Expand All @@ -64,18 +68,38 @@ class rtf_keyword{
{ return param; }
char control_char() const
{ return ctrl_chr; }
bool is_symbol_8bit() const
{ return is_8bit; }
char symbol_8bit() const
{ return value_8bit; }
};

template <class InputIter>
rtf_keyword::rtf_keyword(InputIter &iter)
{
char curchar=*iter;
is_ctrl_chr=!isalpha(curchar);
is_8bit = false;

if (is_ctrl_chr)
{
ctrl_chr=curchar;
++iter;
if (curchar == '\'')
{
char buf[4] = {0, 0, 0, 0};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not 3? Just in case? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better alignment :)

value_8bit = 0;
is_ctrl_chr = false;
is_8bit = true;
curchar = *(++iter);
for (int i = 0; i < 2 && isxdigit(curchar); ++i, curchar = *(++iter))
buf[i] = curchar;

value_8bit = strtol(buf, NULL, 16);
}
else
{
ctrl_chr=curchar;
++iter;
}
}
else
{
Expand All @@ -92,7 +116,7 @@ rtf_keyword::rtf_keyword(InputIter &iter)
param=-1;
else
param=std::atoi(param_str.c_str());
if (curchar==' ')
if (isspace(curchar))
++iter;
keyword_map::iterator kw_pos=keymap.find(s_keyword);
if (kw_pos==keymap.end())
Expand Down
4 changes: 1 addition & 3 deletions rtf_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ std::string table::make()
// first, we'll determine all the rowspans and leftsides
for (row=begin(); row!=end(); ++row)
{
if ((*row)->CellDefs->size()!=(*row)->Cells.size())
throw std::logic_error("Number of Cells and number of CellDefs are unequal!");
for (cell_def=(*row)->CellDefs->begin(), cell=(*row)->Cells.begin();
cell!=(*row)->Cells.end();
cell!=(*row)->Cells.end() && cell_def!=(*row)->CellDefs->end();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you seen any cases when we had this error on a real rtf file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have. I converted RTF specifaction (from here: https://www.microsoft.com/en-us/download/details.aspx?id=10725) to RTF format using LibreOffice Writer 5.1.4.2. Then I tried to make an HTML file from it using rtf2html. And I got that error

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so which list was longer? And what was in its 'extra' elements?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to know before I pull this, as the situation itself looks very strange.

++cell, prev_cell_def=cell_def++
)
{
Expand Down