kopia lustrzana https://github.com/jamescoxon/dl-fldigi
Find chars fwd/back
* Add new method to Fl_Text_Buffer_1_3 to support finding word boundaries. Needed for correct identification of a callsign.pull/2/head
rodzic
0f87d8799d
commit
f1abc9ec35
|
@ -617,7 +617,10 @@ public:
|
|||
*/
|
||||
int search_backward(int startPos, const char* searchString, int* foundPos,
|
||||
int matchCase = 0) const;
|
||||
|
||||
|
||||
int findchars_forward(int startPos, const char* searchChars, int* foundPos);
|
||||
int findchars_backward(int startPos, const char* searchChars, int* foundPos);
|
||||
|
||||
/**
|
||||
Returns the primary selection.
|
||||
*/
|
||||
|
|
|
@ -408,10 +408,10 @@ char* FTextBase::get_word(int x, int y, const char* nwchars, bool ontext)
|
|||
return tbuf->selection_text();
|
||||
}
|
||||
|
||||
#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
|
||||
start = tbuf->word_start(p);
|
||||
end = tbuf->word_end(p);
|
||||
#else
|
||||
//#if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR == 3
|
||||
// start = tbuf->word_start(p);
|
||||
// end = tbuf->word_end(p);
|
||||
//#else
|
||||
string nonword = nwchars;
|
||||
nonword.append(" \t\n");
|
||||
if (!tbuf->findchars_backward(p, nonword.c_str(), &start))
|
||||
|
@ -420,7 +420,7 @@ char* FTextBase::get_word(int x, int y, const char* nwchars, bool ontext)
|
|||
start++;
|
||||
if (!tbuf->findchars_forward(p, nonword.c_str(), &end))
|
||||
end = tbuf->length();
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
if (ontext && (p < start || p >= end))
|
||||
return 0;
|
||||
|
|
|
@ -848,6 +848,35 @@ int Fl_Text_Buffer_mod::word_start(int pos) const {
|
|||
return pos;
|
||||
}
|
||||
|
||||
/*
|
||||
** Search backwards in buffer for characters in "searchChars", starting
|
||||
** with the character BEFORE "startPos", returning the result in "foundPos"
|
||||
** returns 1 if found, 0 if not.
|
||||
*/
|
||||
int Fl_Text_Buffer_mod::findchars_backward( int startPos, const char *searchChars,
|
||||
int *foundPos ) {
|
||||
int pos = startPos;
|
||||
const char *c;
|
||||
char ch = 0;
|
||||
|
||||
if ( startPos == 0 ) {
|
||||
*foundPos = 0;
|
||||
return 0;
|
||||
}
|
||||
while ( pos > 0 ) {
|
||||
ch = char_at(pos);
|
||||
for ( c = searchChars; *c != '\0'; c++ ) {
|
||||
if ( ch == *c ) {
|
||||
*foundPos = pos;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
pos = prev_char(pos);
|
||||
}
|
||||
*foundPos = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Find the end of a word.
|
||||
|
@ -862,6 +891,31 @@ int Fl_Text_Buffer_mod::word_end(int pos) const {
|
|||
return pos;
|
||||
}
|
||||
|
||||
/*
|
||||
** Search forwards in buffer for characters in "searchChars", starting
|
||||
** with the character "startPos", and returning the result in "foundPos"
|
||||
** returns 1 if found, 0 if not.
|
||||
*/
|
||||
int Fl_Text_Buffer_mod::findchars_forward( int startPos, const char *searchChars,
|
||||
int *foundPos ) {
|
||||
int pos = startPos;
|
||||
const char *c;
|
||||
char ch = 0;
|
||||
|
||||
while ( pos < length() ) {
|
||||
ch = char_at(pos);
|
||||
for ( c = searchChars; *c != '\0'; c++ ) {
|
||||
if ( ch == *c ) {
|
||||
*foundPos = pos;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
pos = next_char(pos);
|
||||
}
|
||||
*foundPos = length();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Count the number of characters between two positions.
|
||||
|
|
Ładowanie…
Reference in New Issue