From f7a3d05a2374043f8f1842051a377dd40c3c3464 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Mon, 15 Jan 2001 14:05:45 +0000 Subject: [PATCH] Use contains() instead of strchr(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1336 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 2 ++ src/support/lstrings.C | 8 ++++++++ src/support/lstrings.h | 3 +++ src/text.C | 12 ++++++++---- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8b6c37c931..4e8c6a39ac 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2001-01-15 Dekel Tsur + * text.C (InsertChar): Use contains instead of strchr. + * lyx_cb.C (MenuInsertLabel): Enable default value code. 2001-01-13 Dekel Tsur diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 6be5d94b12..1449e429ee 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -344,6 +344,14 @@ bool contains(string const & a, string const & b) } +bool contains(string const & a, char b) +{ + if (a.empty()) + return false; + return a.find(b) != string::npos; +} + + bool contains(char const * a, char const * b) { Assert(a && b); diff --git a/src/support/lstrings.h b/src/support/lstrings.h index bffbc0d865..3f47c4820b 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -125,6 +125,9 @@ bool contains(string const & a, char const * b); /// bool contains(string const & a, string const & b); +/// +bool contains(string const & a, char b); + /// bool contains(char const * a, char const * b); diff --git a/src/text.C b/src/text.C index 0f806c6cf4..9420e59534 100644 --- a/src/text.C +++ b/src/text.C @@ -1911,9 +1911,13 @@ void LyXText::InsertChar(BufferView * bview, char c) if (lyxrc.auto_number) { + static string const number_operators = "+-/*"; + static string const number_unary_operators = "+-"; + static string const number_seperators = ".,:"; + if (current_font.number() == LyXFont::ON) { - if (!isdigit(c) && !strchr("+-/*", c) && - !(strchr(".,:",c) && + if (!isdigit(c) && !contains(number_operators, c) && + !(contains(number_seperators, c) && cursor.pos() >= 1 && cursor.pos() < cursor.par()->size() && GetFont(bview->buffer(), @@ -1930,7 +1934,7 @@ void LyXText::InsertChar(BufferView * bview, char c) if (cursor.pos() > 0) { char const c = cursor.par()->GetChar(cursor.pos() - 1); - if (strchr("+-",c) && + if (contains(number_unary_operators, c) && (cursor.pos() == 1 || cursor.par()->IsSeparator(cursor.pos() - 2) || cursor.par()->IsNewline(cursor.pos() - 2) ) @@ -1939,7 +1943,7 @@ void LyXText::InsertChar(BufferView * bview, char c) cursor.par(), cursor.pos() - 1, current_font); - } else if (strchr(".,:", c) && + } else if (contains(number_seperators, c) && cursor.pos() >= 2 && GetFont(bview->buffer(), cursor.par(), -- 2.39.5