]> git.lyx.org Git - features.git/commit
Fix bug 3293 by Bernhard Roider:
authorAbdelrazak Younes <younes@lyx.org>
Mon, 26 Mar 2007 13:43:49 +0000 (13:43 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 26 Mar 2007 13:43:49 +0000 (13:43 +0000)
commit4d5ae916ad815521adf2f4b2ed2fdc91fcf6a713
treeb157a8995922b365a3c6b503fc9506e66a1e82b7
parent4d2732b1e70418bca78ce9d3b1106758fb80c8fa
Fix bug 3293 by Bernhard Roider:

This changes the semantics of isOK() and operator(), comments from Bernhard below:

With the old version of lyxlex it was _impossible_ to check whether reading an integer, float, ... succeeded or not. The current solution to check for is.bad() in some cases and in other cases use is.good() does not give the desired information. Moreover the result of is.bad() depends on the stl implementation and behaves different for linux and windows.

the bug was introduced by the patch that fixed the bug that crashed lyx when "inset-insert ert" was executed from the command buffer.
The lexer has the method isOK() which reflects the status of the stream is.
The operators void* and ! are not really well defined (they depend on the value of is.bad()). What is missing is a test if the last reading operation was successful and thus the returned value is valid.
That's what i implemented in this patch.

The new rule for using the lexer:

if you want to know if the lexer still has data to read (either from the stream or from the pushed token) then use "lex.isOK()".
If you want to test if the last reading operation was successful then use eg. "if (lex) {...}" or unsuccessful then use eg. "if (!lex) {...}"

an example:

int readParam(LyxLex &lex) {

    int param = 1; // default value
    if (lex.isOK()) { // the lexer has data to read
        int p;    // temporary variable
        lex >> p;
        if (lex) param = p; // only use the input if the reading operation was successful
    }
    return param;
}

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17569 a592a061-630c-0410-9148-cb99ea01b6c8
14 files changed:
src/ToolbarBackend.C
src/buffer.C
src/dociterator.C
src/frontends/controllers/ControlLog.C
src/frontends/controllers/ControlParagraph.C
src/insets/insetbox.C
src/insets/insetert.C
src/insets/insetnote.C
src/insets/insettabular.C
src/insets/insetvspace.C
src/lyxlex.C
src/lyxlex.h
src/lyxlex_pimpl.C
src/lyxlex_pimpl.h