+2000-03-08 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * src/insets/insettext.C: added <algorithm>.
+
+2000-03-07 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * src/mathed/math_panel.C (delim_cb): case MM_OK use string stream
+ (matrix_cb): case MM_OK use string stream
+
+ * src/mathed/formula.C (LocalDispatch): case LFUN_SETXY use string
+ stream.
+
+ * src/mathed/math_macro.C (draw): use string stream
+ (Metrics): use string stream
+
+ * src/paragraph.C (TeXFootnote): for case LyXParagraph::FIG, write
+ directly to the ostream.
+
+ * src/vspace.C (asString): use string stream.
+ (asString): use string stream
+ (asLatexString): use string stream
+
+ * src/lyx_cb.C (UpdateLayoutDocument): use string stream for
+ setting Spacing::Other.
+
+ * src/LaTeXFeatures.C (getPackages): use string stream instead of
+ sprintf when creating the stretch vale.
+
+ * src/text2.C (alphaCounter): changed to return a string and to
+ not use a static variable internally. Also fixed a one-off bug.
+ (SetCounter): changed the drawing of the labels to use string
+ streams instead of sprintf.
+
+ * src/support/lyxmanip.h: rewrite the newlineanDepth ostream
+ manipulator to use a scheme that does not require library support.
+ This is also the way it is done in the new GNU libstdc++. Should
+ work with DEC cxx now.
+
2000-03-06 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/mathed/math_inset.h (Write(ostream & os): add a space at the
packages += "\\doublespacing\n";
break;
case Spacing::Other:
- char value[30];
- sprintf(value, "%.2f", params.spacing.getValue());
+ //char value[30];
+ //sprintf(value, "%.2f", params.spacing.getValue());
+#ifdef HAVE_SSTREAM
+ ostringstream value;
+#else
+ char val[30];
+ ostrstream value(val, 30);
+
+#endif
+ value << params.spacing.getValue(); // setw?
+#ifdef HAVE_SSTREAM
packages += string("\\setstretch{")
- + value + "}\n";
+ + value.str().c_str() + "}\n";
+#else
+ value << '\0';
+ packages += string("\\setstretch{")
+ + value.str() + "}\n";
+#endif
break;
}
#include <config.h>
#include <fstream>
+#include <algorithm>
using std::ifstream;
using std::min;
using std::max;
#include <config.h>
-#include <cctype>
-#include <unistd.h>
-#include <csignal>
-#include <cstring>
-#include <cstdlib>
-
#include <fstream>
using std::ifstream;
case Spacing::Other:
{
fl_set_choice(fd_form_document->choice_spacing, 4);
- char sval[20];
- sprintf(sval, "%g", params->spacing.getValue());
- fl_set_input(fd_form_document->input_spacing, sval);
+ //char sval[20];
+ //sprintf(sval, "%g", params->spacing.getValue());
+#ifdef HAVE_SSTREAM
+ ostringstream sval;
+ sval << params->spacing.getValue(); // setw?
+ fl_set_input(fd_form_document->input_spacing,
+ sval.str().c_str());
+#else
+ char tval[20];
+ ostrstream sval(tval, 20);
+ sval << params->spacing.getValue() << '\0'; // setw?
+ fl_set_input(fd_form_document->input_spacing, sval.str());
+#endif
break;
}
}
#include <config.h>
-#include <cctype>
-#include <cstdlib>
-
#ifdef __GNUG__
#pragma implementation "formula.h"
#endif
case LFUN_SETXY:
{
int x, y, x1, y1;
- sscanf(arg.c_str(), "%d %d", &x, &y);
+#ifdef HAVE_SSTREAM
+ istringstream ist(arg.c_str());
+#else
+ istrstream ist(arg.c_str());
+#endif
+ ist >> x >> y;
par->GetXY(x1, y1);
- mathcursor->SetPos(x1+x, y1+y);
+ mathcursor->SetPos(x1 + x, y1 + y);
}
break;
if (expnd_mode) {
MathParInset::draw(pain, x, baseline);
} else {
- unsigned char s[3];
- sprintf(reinterpret_cast<char*>(s), "#%d", number);
- drawStr(pain, LM_TC_TEX, size, x, baseline, &s[0], 2);
+#ifdef HAVE_SSTREAM
+ ostringstream ost;
+ ost << '#' << number;
+ drawStr(pain, LM_TC_TEX, size, x, baseline, ost.str().c_str(), 2);
+#else
+ char s[3];
+ ostrstream ost(s, 3);
+ ost << '#' << number << '\0';
+ drawStr(pain, LM_TC_TEX, size, x, baseline,
+ reinterpret_cast<unsigned char*>(ost.str()), 2);
+#endif
}
}
if (expnd_mode) {
MathParInset::Metrics();
} else {
- unsigned char s[3];
- sprintf(reinterpret_cast<char*>(s), "#%d", number);
- width = mathed_string_width(LM_TC_TEX, size, &s[0], 2);
- mathed_string_height(LM_TC_TEX, size, &s[0], 2, ascent, descent);
+#ifdef HAVE_SSTREAM
+ ostringstream ost;
+ ost << '#' << number;
+ width = mathed_string_width(LM_TC_TEX, size, ost.str().c_str(), 2);
+ mathed_string_height(LM_TC_TEX, size,
+ ost.str().c_str(), 2, ascent, descent);
+#else
+ char s[3];
+ ostrstream ost(s, 3);
+ ost << '#' << number << '\0';
+ width = mathed_string_width(LM_TC_TEX, size,
+ reinterpret_cast<unsigned char*>
+ (ost.str()), 2);
+ mathed_string_height(LM_TC_TEX, size,
+ reinterpret_cast<unsigned char*>(ost.str()),
+ 2, ascent, descent);
+#endif
}
}
#include <config.h>
#include FORMS_H_LOCATION
-#include <cstdlib>
#include "lyx_gui_misc.h"
#include "math_panel.h"
case MM_APPLY:
case MM_OK:
{
- char s[80];
- sprintf(s, "%d %d", delim_code[left], delim_code[right]);
- lyxfunc->Dispatch(LFUN_MATH_DELIM, s);
- if (data == MM_APPLY) break;
+#ifdef HAVE_SSTREAM
+ ostringstream ost;
+ ost << delim_code[left] << ' ' << delim_code[right];
+ lyxfunc->Dispatch(LFUN_MATH_DELIM, ost.str().c_str());
+#else
+ char s[80];
+ ostrstream ost(s, 80);
+ ost << delim_code[left] << ' ' << delim_code[right] << '\0';
+ lyxfunc->Dispatch(LFUN_MATH_DELIM, ost.str());
+#endif
+ if (data == MM_APPLY) break;
}
case MM_CLOSE: fl_hide_form(fd_delim->delim); break;
case 2:
case MM_APPLY:
case MM_OK:
{
- char s[80];
char c = v_align_c[fl_get_choice(fd_matrix->valign)-1];
char const * sh = fl_get_input(fd_matrix->halign);
int nx = int(fl_get_slider_value(fd_matrix->columns)+0.5);
int ny = int(fl_get_slider_value(fd_matrix->rows)+0.5);
- sprintf(s, "%d %d %c%s", nx, ny, c, sh);
if (data == MM_OK) fl_hide_form(fd_matrix->matrix);
- lyxfunc->Dispatch(LFUN_INSERT_MATRIX, s);
+#ifdef HAVE_SSTREAM
+ ostringstream ost;
+ ost << nx << ' ' << ny << ' ' << c << sh;
+ lyxfunc->Dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
+#else
+ char s[80];
+ ostrstream ost(s, 80);
+ ost << nx << ' ' << ny << ' ' << c << sh << '\0';
+ lyxfunc->Dispatch(LFUN_INSERT_MATRIX, ost.str());
+#endif
break;
}
case MM_CLOSE: fl_hide_form(fd_matrix->matrix); break;
if (pextra_type == PEXTRA_FLOATFLT
&& (!pextra_width.empty()
|| !pextra_widthp.empty())) {
- char bufr[80];
if (!pextra_width.empty())
- sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
- pextra_width.c_str());
+ os << "\\begin{floatingfigure}{"
+ << pextra_width << "}\n";
else
- sprintf(bufr,
- "\\begin{floatingfigure}{%f\\textwidth}\n",
- atoi(pextra_widthp.c_str())/100.0);
- os << bufr;
+ os << "\\begin{floatingfigure}{"
+ << atoi(pextra_widthp.c_str())/100.0
+ << "\\textwidth}\n";
} else {
os << "\\begin{figure}";
if (!params->float_placement.empty()) {
|| !pextra_widthp.empty())) {
char bufr[80];
if (!pextra_width.empty())
- sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
+ sprintf(bufr,
+ "\\begin{floatingfigure}{%s}\n",
pextra_width.c_str());
else
sprintf(bufr,
#ifndef LYX_MANIP_H
#define LYX_MANIP_H
-#include <iomanip>
+#include <iostream>
+
+///
+struct NewLineAndDepth_ {
+ int depth_;
+};
///
inline
-ostream & newlineAndDepth_helper(ostream & s, int n)
+NewLineAndDepth_ newlineAndDepth(int n)
{
- return s << '\n' << string(n, ' ');
+ NewLineAndDepth_ nlad_;
+ nlad_.depth_ = n;
+ return nlad_;
}
///
inline
-omanip<int> newlineAndDepth(int n)
+ostream & operator<<(ostream & os, NewLineAndDepth_ const & nlad_)
{
- return omanip<int>(newlineAndDepth_helper, n);
+ os << string(nlad_.depth_, ' ');
+ return os;
}
#endif
#define FIX_DOUBLE_SPACE 1
+// This is the comments that some of the warnings below refers to.
+// There are some issues in this file and I don't think they are
+// really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
+// this is a problem that has been here almost from day one and that a
+// larger userbase with differenct access patters triggers the bad
+// behaviour. (segfaults.) What I think happen is: In several places
+// we store the paragraph in the current cursor and then moves the
+// cursor. This movement of the cursor will delete paragraph at the
+// old position if it is now empty. This will make the temporary
+// pointer to the old cursor paragraph invalid and dangerous to use.
+// And is some cases this will trigger a segfault. I have marked some
+// of the cases where this happens with a warning, but I am sure there
+// are others in this file and in text2.C. There is also a note in
+// Delete() that you should read. In Delete I store the paragraph->id
+// instead of a pointer to the paragraph. I am pretty sure this faulty
+// use of temporary pointers to paragraphs that might have gotten
+// invalidated (through a cursor movement) before they are used, are
+// the cause of the strange crashes we get reported often.
+//
+// It is very tiresom to change this code, especially when it is as
+// hard to read as it is. Help to fix all the cases where this is done
+// would be greately appreciated.
+//
+// Lgb
+
int LyXText::SingleWidth(LyXParagraph * par,
LyXParagraph::size_type pos) const
{
}
}
- int align;
+ int align; // wrong type
if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
align = layout.align;
else
int LyXText::NumberOfSeparators(Row const * row) const
{
int last = RowLast(row);
- //int p = row->pos;
- //int main_body = BeginningOfMainBody(row->par);
- //if (p < main_body)
- // p = main_body;
- // I think this is equivalent to the above. (Lgb)
int p = max(row->pos, BeginningOfMainBody(row->par));
int n = 0;
for (; p < last; ++p) {
++first;
}
- //int main_body = BeginningOfMainBody(row->par);
- //if (first < main_body)
- // first = main_body;
- // I think this is equivalent to the above. (Lgb)
first = max(first, BeginningOfMainBody(row->par));
int n = 0;
for (int p = first; p <= last; ++p) { // last, because the end is ignored!
while(first < last && row->par->IsHfill(first))
++first;
}
- //LyXParagraph::size_type main_body =
- //BeginningOfMainBody(row->par);
- //if (last > main_body)
- //last = main_body;
- // I think this is eqvialent to the above. (Lgb)
+
last = min(last, BeginningOfMainBody(row->par));
int n = 0;
for (LyXParagraph::size_type p = first;
/* set the dimensions of the cursor row */
row->fill = Fill(row, paperwidth);
SetHeightOfRow(row);
+#warning See comment on top of text.C
tmppar = tmppar->Next();
while (tmppar != endpar) {
/* redraw only the row */
LyXCursor tmpcursor = cursor;
SetCursorIntern(par, pos);
+#warning See comment on top of text.C
refresh_y = y;
refresh_x = cursor.x;
refresh_row = row;
{
// treat floats, HFills and Insets as words
LyXCursor tmpcursor = cursor;
+#warning See comment on top of text.C
if (tmpcursor.pos == tmpcursor.par->Last()
&& tmpcursor.par->Next())
if (!cursor.par->Last())
CursorRight();
+#warning See comment on top of text.C
else {
/* -------> Skip initial non-word stuff. */
while ( cursor.pos < cursor.par->Last()
LyXCursor tmpcursor = cursor;
if (!cursor.par->Last())
CursorLeft();
+#warning See comment on top of text.C
else{
selection = true; // to avoid deletion
CursorLeftOneWord();
LyXCursor tmpcursor = cursor;
if (!cursor.par->Last())
CursorRight();
+#warning See comment on top of text.C
else {
CursorEnd();
sel_cursor = cursor;
// just move to the right
CursorRightIntern();
+#warning Look at the comment here.
// This check is not very good...
// The CursorRightIntern calls DeleteEmptyParagrapgMechanism
// and that can very well delete the par or par->previous in
tmppar = cursor.par;
tmprow = cursor.row;
CursorLeftIntern();
+#warning See comment on top of text.C
/* Pasting is not allowed, if the paragraphs have different
layout. I think it is a real bug of all other
word processors to allow it. It confuses the user.
#include <config.h>
-#include <cctype>
#include FORMS_H_LOCATION
sel_end_cursor = sel_cursor;
}
- selection = True;
+ selection = true;
// first the toggling area
if (cursor.y < last_sel_cursor.y ||
static
-char const * alphaCounter(int n) {
- static char result[2];
- result[1] = 0;
- if (n == 0)
- return "";
- else {
- result[0] = 'A' + n;
+string alphaCounter(int n) {
+ if (n != 0) {
if (n > 'Z')
return "??";
+ char result[2] = { 'A' + n - 1, 0 };
+ return result;
}
- return result;
+ return "";
}
if (i >= 0 && i<= parameters->secnumdepth) {
par->incCounter(i); // increment the counter
- char * s = new char[50];
-
// Is there a label? Useful for Chapter layout
if (!par->appendix){
if (!layout.labelstring().empty())
else
par->labelstring.clear();
}
-
- if (!par->appendix){
+
+#ifdef HAVE_SSTREAM
+ ostringstream s;
+#else
+ ostrstream s;
+#endif
+ if (!par->appendix) {
switch (2 * LABEL_FIRST_COUNTER -
textclass.maxcounter() + i) {
case LABEL_COUNTER_CHAPTER:
- sprintf(s, "%d",
- par->getCounter(i));
+ s << par->getCounter(i);
break;
case LABEL_COUNTER_SECTION:
- sprintf(s, "%d.%d",
- par->getCounter(i - 1),
- par->getCounter(i));
+ s << par->getCounter(i - 1) << '.'
+ << par->getCounter(i);
break;
case LABEL_COUNTER_SUBSECTION:
- sprintf(s, "%d.%d.%d",
- par->getCounter(i-2),
- par->getCounter(i-1),
- par->getCounter(i));
+ s << par->getCounter(i - 2) << '.'
+ << par->getCounter(i - 1) << '.'
+ << par->getCounter(i);
break;
case LABEL_COUNTER_SUBSUBSECTION:
- sprintf(s, "%d.%d.%d.%d",
- par->getCounter(i-3),
- par->getCounter(i-2),
- par->getCounter(i-1),
- par->getCounter(i));
+ s << par->getCounter(i - 3) << '.'
+ << par->getCounter(i - 2) << '.'
+ << par->getCounter(i - 1) << '.'
+ << par->getCounter(i);
+
break;
case LABEL_COUNTER_PARAGRAPH:
- sprintf(s, "%d.%d.%d.%d.%d",
- par->getCounter(i-4),
- par->getCounter(i-3),
- par->getCounter(i-2),
- par->getCounter(i-1),
- par->getCounter(i));
+ s << par->getCounter(i - 4) << '.'
+ << par->getCounter(i - 3) << '.'
+ << par->getCounter(i - 2) << '.'
+ << par->getCounter(i - 1) << '.'
+ << par->getCounter(i);
break;
case LABEL_COUNTER_SUBPARAGRAPH:
- sprintf(s, "%d.%d.%d.%d.%d.%d",
- par->getCounter(i-5),
- par->getCounter(i-4),
- par->getCounter(i-3),
- par->getCounter(i-2),
- par->getCounter(i-1),
- par->getCounter(i));
+ s << par->getCounter(i - 5) << '.'
+ << par->getCounter(i - 4) << '.'
+ << par->getCounter(i - 3) << '.'
+ << par->getCounter(i - 2) << '.'
+ << par->getCounter(i - 1) << '.'
+ << par->getCounter(i);
+
break;
default:
- sprintf(s, "%d.", par->getCounter(i));
+ s << par->getCounter(i) << '.';
break;
}
- } else {
+ } else { // appendix
switch (2 * LABEL_FIRST_COUNTER - textclass.maxcounter() + i) {
case LABEL_COUNTER_CHAPTER:
- sprintf(s, "%s",
- alphaCounter(par->getCounter(i)));
+ s << alphaCounter(par->getCounter(i));
break;
case LABEL_COUNTER_SECTION:
- sprintf(s, "%s.%d",
- alphaCounter(par->getCounter(i - 1)),
- par->getCounter(i));
+ s << alphaCounter(par->getCounter(i - 1)) << '.'
+ << par->getCounter(i);
+
break;
case LABEL_COUNTER_SUBSECTION:
- sprintf(s, "%s.%d.%d",
- alphaCounter(par->getCounter(i-2)),
- par->getCounter(i-1),
- par->getCounter(i));
+ s << alphaCounter(par->getCounter(i - 2)) << '.'
+ << par->getCounter(i-1) << '.'
+ << par->getCounter(i);
+
break;
case LABEL_COUNTER_SUBSUBSECTION:
- sprintf(s, "%s.%d.%d.%d",
- alphaCounter(par->getCounter(i-3)),
- par->getCounter(i-2),
- par->getCounter(i-1),
- par->getCounter(i));
+ s << alphaCounter(par->getCounter(i-3)) << '.'
+ << par->getCounter(i-2) << '.'
+ << par->getCounter(i-1) << '.'
+ << par->getCounter(i);
+
break;
case LABEL_COUNTER_PARAGRAPH:
- sprintf(s, "%s.%d.%d.%d.%d",
- alphaCounter(par->getCounter(i-4)),
- par->getCounter(i-3),
- par->getCounter(i-2),
- par->getCounter(i-1),
- par->getCounter(i));
+ s << alphaCounter(par->getCounter(i-4)) << '.'
+ << par->getCounter(i-3) << '.'
+ << par->getCounter(i-2) << '.'
+ << par->getCounter(i-1) << '.'
+ << par->getCounter(i);
+
break;
case LABEL_COUNTER_SUBPARAGRAPH:
- sprintf(s, "%s.%d.%d.%d.%d.%d",
- alphaCounter(par->getCounter(i-5)),
- par->getCounter(i-4),
- par->getCounter(i-3),
- par->getCounter(i-2),
- par->getCounter(i-1),
- par->getCounter(i));
+ s << alphaCounter(par->getCounter(i-5)) << '.'
+ << par->getCounter(i-4) << '.'
+ << par->getCounter(i-3) << '.'
+ << par->getCounter(i-2) << '.'
+ << par->getCounter(i-1) << '.'
+ << par->getCounter(i);
+
break;
default:
- sprintf(s, "%c.", par->getCounter(i));
+ // Can this ever be reached? And in the
+ // case it is, how can this be correct?
+ // (Lgb)
+ s << static_cast<unsigned char>(par->getCounter(i)) << '.';
+
break;
}
}
-
- par->labelstring += s;
- delete[] s;
-
+#ifdef HAVE_SSTREAM
+ par->labelstring += s.str().c_str();
+ // We really want to remove the c_str as soon as
+ // possible...
+#else
+ s << '\0';
+ char * tmps = s.str();
+ par->labelstring += tmps;
+ delete [] tmps;
+#endif
+
for (i++; i < 10; ++i) {
// reset the following counters
par->setCounter(i, 0);
}
} else if (layout.labeltype == LABEL_COUNTER_ENUMI) {
par->incCounter(i + par->enumdepth);
- char * s = new char[25];
int number = par->getCounter(i + par->enumdepth);
static const char *roman[20] = {
'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
'÷', 'ø', 'ù', 'ú'
};
-
+#ifdef HAVE_SSTREAM
+ ostringstream s;
+#else
+ ostrstream s;
+#endif
switch (par->enumdepth) {
case 1:
if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT)
- sprintf(s, "(%c)", ((number-1) % 26) + 'a');
+ s << '('
+ << static_cast<unsigned char>
+ (((number - 1) % 26) + 'a')
+ << ')';
+
else
- sprintf(s, "(%c)", hebrew[(number-1) % 22]);
+ s << '('
+ << static_cast<unsigned char>
+ (hebrew[(number - 1) % 22])
+ << ')';
break;
case 2:
if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT)
- sprintf(s, "%s.", roman[(number-1) % 20]);
+ s << roman[(number - 1) % 20] << '.';
else
- sprintf(s, ".%s", roman[(number-1) % 20]);
+ s << '.' << roman[(number - 1) % 20];
break;
case 3:
if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT)
- sprintf(s, "%c.", ((number-1) % 26) + 'A');
+ s << static_cast<unsigned char>
+ (((number - 1) % 26) + 'A')
+ << '.';
else
- sprintf(s, ".%c", ((number-1) % 26) + 'A');
+ s << '.'
+ << static_cast<unsigned char>
+ (((number - 1) % 26) + 'A');
break;
default:
if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT)
- sprintf(s, "%d.", number);
+ s << number << '.';
else
- sprintf(s, ".%d", number);
+ s << '.' << number;
break;
}
- par->labelstring = s;
- delete[] s;
+#ifdef HAVE_SSTREAM
+ par->labelstring = s.str().c_str();
+ // we really want to get rid of that c_str()
+#else
+ s << '\0';
+ char * tmps = s.str();
+ par->labelstring = tmps;
+ delete [] tmps;
+#endif
for (i += par->enumdepth + 1; i < 10; ++i)
par->setCounter(i, 0); /* reset the following counters */
*
* LyX, The Document Processor
*
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-1999 The LyX Team.
+ * Copyright 1995 Matthias Ettrich
+ * Copyright 1995-2000 The LyX Team.
*
* ====================================================== */
#include "vspace.h"
#include "lyxrc.h"
#include "lyxtext.h"
-#include <cstring>
#include "BufferView.h"
#include "support/lstrings.h"
//static int number_index, unit_index;
int number_index, unit_index;
+
static inline
void lyx_advance (string & data, unsigned int n)
{
data.erase(0, n);
}
+
static inline
bool isEndOfData (string const & data)
{
return frontStrip (data).empty();
}
+
static
char nextToken (string & data)
{
}
}
-static struct {
+
+struct LaTeXLength {
char const * pattern;
int plus_val_index, minus_val_index,
plus_uni_index, minus_uni_index;
-} table[] = { { "nu", 0, 0, 0, 0 },
- { "nu+nu", 2, 0, 2, 0 },
- { "nu+nu-nu", 2, 3, 2, 3 },
- { "nu+-nu", 2, 2, 2, 2 },
- { "nu-nu", 0, 2, 0, 2 },
- { "nu-nu+nu", 3, 2, 3, 2 },
- { "nu-+nu", 2, 2, 2, 2 },
- { "n+nu", 2, 0, 1, 0 },
- { "n+n-nu", 2, 3, 1, 1 },
- { "n+-nu", 2, 2, 1, 1 },
- { "n-nu", 0, 2, 0, 1 },
- { "n-n+nu", 3, 2, 1, 1 },
- { "n-+nu", 2, 2, 1, 1 },
- { "", 0, 0, 0, 0 } // sentinel, must be empty
};
+
+static
+LaTeXLength table[] = {
+ { "nu", 0, 0, 0, 0 },
+ { "nu+nu", 2, 0, 2, 0 },
+ { "nu+nu-nu", 2, 3, 2, 3 },
+ { "nu+-nu", 2, 2, 2, 2 },
+ { "nu-nu", 0, 2, 0, 2 },
+ { "nu-nu+nu", 3, 2, 3, 2 },
+ { "nu-+nu", 2, 2, 2, 2 },
+ { "n+nu", 2, 0, 1, 0 },
+ { "n+n-nu", 2, 3, 1, 1 },
+ { "n+-nu", 2, 2, 1, 1 },
+ { "n-nu", 0, 2, 0, 1 },
+ { "n-n+nu", 3, 2, 1, 1 },
+ { "n-+nu", 2, 2, 1, 1 },
+ { "", 0, 0, 0, 0 } // sentinel, must be empty
+};
+
+
bool isValidGlueLength (string const & data, LyXGlueLength * result)
{
// This parser is table-driven. First, it constructs a "pattern"
return true;
}
+
/// LyXLength class
LyXLength::LyXLength(string const & data)
}
}
+
bool LyXLength::operator== (LyXLength const & other) const
{
return (val == other.val &&
uni == other.uni);
}
+
string LyXLength::asString() const
{
- char buffer[20];
-
- sprintf (buffer, "%g%s", val, unit_name[uni]);
- return string (buffer);
+#ifdef HAVE_SSTREAM
+ ostringstream buffer;
+ buffer << val << unit_name[uni]; // setw?
+ return buffer.str().c_str();
+#else
+ char tbuf[20];
+ ostrstream buffer(tbuf, 20);
+ buffer << val << unit_name[uni] << '\0'; // setw?
+ return buffer.str();
+#endif
}
string LyXGlueLength::asString() const
{
- char buffer[20];
-
+#ifdef HAVE_SSTREAM
+ ostringstream buffer;
+#else
+ char tbuf[20];
+ ostrstream buffer(tbuf, 20);
+#endif
if (plus_val != 0.0)
if (minus_val != 0.0)
if ((uni == plus_uni) && (uni == minus_uni))
if (plus_val == minus_val)
- sprintf (buffer, "%g+-%g%s",
- val, plus_val, unit_name[uni]);
+ buffer << val << "+-"
+ << plus_val << unit_name[uni];
else
- sprintf (buffer, "%g+%g-%g%s",
- val, plus_val, minus_val,
- unit_name[uni]);
+ buffer << val
+ << '+' << plus_val
+ << '-' << minus_val
+ << unit_name[uni];
else
- if ((plus_uni == minus_uni) && (plus_val == minus_val))
- sprintf (buffer, "%g%s+-%g%s",
- val, unit_name[uni],
- plus_val, unit_name[plus_uni]);
+ if (plus_uni == minus_uni
+ && plus_val == minus_val)
+ buffer << val << unit_name[uni]
+ << "+-" << plus_val
+ << unit_name[plus_uni];
+
else
- sprintf (buffer, "%g%s+%g%s-%g%s",
- val, unit_name[uni],
- plus_val, unit_name[plus_uni],
- minus_val, unit_name[minus_uni]);
+ buffer << val << unit_name[uni]
+ << '+' << plus_val
+ << unit_name[plus_uni]
+ << '-' << minus_val
+ << unit_name[minus_uni];
else
if (uni == plus_uni)
- sprintf (buffer, "%g+%g%s",
- val, plus_val, unit_name[uni]);
+ buffer << val << '+' << plus_val
+ << unit_name[uni];
else
- sprintf (buffer, "%g%s+%g%s",
- val, unit_name[uni],
- plus_val, unit_name[plus_uni]);
+ buffer << val << unit_name[uni]
+ << '+' << plus_val
+ << unit_name[plus_uni];
+
else
if (minus_val != 0.0)
if (uni == minus_uni)
- sprintf (buffer, "%g-%g%s",
- val, minus_val, unit_name[uni]);
+ buffer << val << '-' << minus_val
+ << unit_name[uni];
+
else
- sprintf (buffer, "%g%s-%g%s",
- val, unit_name[uni],
- minus_val, unit_name[minus_uni]);
+ buffer << val << unit_name[uni]
+ << '-' << minus_val
+ << unit_name[minus_uni];
else
- sprintf (buffer, "%g%s", val, unit_name[uni]);
- return string (buffer);
+ buffer << val << unit_name[uni];
+#ifdef HAVE_SSTREAM
+ return buffer.str().c_str();
+#else
+ buffer << '\0';
+ return buffer.str();
+#endif
}
string LyXGlueLength::asLatexString() const
{
- char buffer[40];
+#ifdef HAVE_SSTREAM
+ ostringstream buffer;
+#else
+ char tbuf[40];
+ ostrstream buffer(tbuf, 40);
+#endif
if (plus_val != 0.0)
if (minus_val != 0.0)
- sprintf (buffer, "%g%s plus %g%s minus %g%s",
- val, unit_name[uni],
- plus_val, unit_name[plus_uni],
- minus_val, unit_name[minus_uni]);
+ buffer << val << unit_name[uni]
+ << " plus "
+ << plus_val << unit_name[plus_uni]
+ << " minus "
+ << minus_val << unit_name[minus_uni];
else
- sprintf (buffer, "%g%s plus %g%s",
- val, unit_name[uni],
- plus_val, unit_name[plus_uni]);
+ buffer << val << unit_name[uni]
+ << " plus "
+ << plus_val << unit_name[plus_uni];
else
if (minus_val != 0.0)
- sprintf (buffer, "%g%s minus %g%s",
- val, unit_name[uni],
- minus_val, unit_name[minus_uni]);
+ buffer << val << unit_name[uni]
+ << " minus "
+ << minus_val << unit_name[minus_uni];
else
- sprintf (buffer, "%g%s",
- val, unit_name[uni]);
- return string (buffer);
+ buffer << val << unit_name[uni];
+#ifdef HAVE_SSTREAM
+ return buffer.str().c_str();
+#else
+ buffer << '\0';
+ return buffer.str();
+#endif
}