Use contains() instead of strchr().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1336 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Dekel Tsur 2001-01-15 14:05:45 +00:00
parent a52d9b4f78
commit f7a3d05a23
4 changed files with 21 additions and 4 deletions

View 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>

View 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);

View 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);

View 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(),