]> git.lyx.org Git - lyx.git/commitdiff
Use contains() instead of strchr().
authorDekel Tsur <dekelts@tau.ac.il>
Mon, 15 Jan 2001 14:05:45 +0000 (14:05 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Mon, 15 Jan 2001 14:05:45 +0000 (14:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1336 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/support/lstrings.C
src/support/lstrings.h
src/text.C

index 8b6c37c9319293bdb6df9a79adf3a69fdef43843..4e8c6a39ac94eaa4472e188c7a27514371eaeb5d 100644 (file)
@@ -1,5 +1,7 @@
 2001-01-15  Dekel Tsur  <dekelts@tau.ac.il>
 
+       * text.C (InsertChar): Use contains instead of strchr.
+
        * lyx_cb.C (MenuInsertLabel): Enable default value code.
 
 2001-01-13  Dekel Tsur  <dekelts@tau.ac.il>
index 6be5d94b1265038b22649bc1b421b44f840f82c1..1449e429eed491a8969be64b595d4eed44fbffd1 100644 (file)
@@ -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);
index bffbc0d865ccd4514300d36ce2bd18752605bc7f..3f47c4820b4cb8b06ba8ed4739bfef0506382d09 100644 (file)
@@ -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);
 
index 0f806c6cf4ba7b93b266cd2a9ca6c6c9bcb9f37f..9420e5953457cda65c384e4ac1995591959ef04c 100644 (file)
@@ -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(),