~ubuntu-branches/ubuntu/karmic/rkward/karmic

« back to all changes in this revision

Viewing changes to rkward/misc/rkcommonfunctions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Friedrichsmeier
  • Date: 2006-11-06 16:30:00 UTC
  • mfrom: (1.2.1 upstream) (3.1.1 feisty)
  • Revision ID: james.westby@ubuntu.com-20061106163000-qi8ju75eqecrfay7
* new upstream release
* depend on either php4-cli or php5-cli

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include <qstringlist.h>
20
20
#include <qdom.h>
 
21
#include <qregexp.h>
21
22
 
22
23
#include <kxmlguiclient.h>
23
24
 
96
97
                }
97
98
        }
98
99
 
 
100
        QString getCurrentSymbol (const QString &context_line, int cursor_pos, bool strict) {
 
101
                if (context_line.isEmpty ()) return (QString ());
 
102
 
 
103
                int current_word_start;
 
104
                int current_word_end;
 
105
                getCurrentSymbolOffset (context_line, cursor_pos, strict, &current_word_start, &current_word_end);
 
106
        
 
107
                // if both return the same position, we're on a non-word.
 
108
                if (current_word_start == current_word_end) return (QString ());
 
109
 
 
110
                return (context_line.mid (current_word_start, current_word_end - current_word_start));
 
111
        }
 
112
 
 
113
        void getCurrentSymbolOffset (const QString &context_line, int cursor_pos, bool strict, int *start, int *end) {
 
114
                if (context_line.isEmpty ()) {
 
115
                        *start = 0;
 
116
                        *end = 0;
 
117
                        return;
 
118
                }
 
119
 
 
120
                // step 1: find out word under cursor
 
121
                // We want to match any valid R name, that is, everything composed of letters, 0-9, '.'s and '_'s..
 
122
                QRegExp rx_no_word;
 
123
                if (strict) {
 
124
                        rx_no_word = QRegExp ("[^A-Za-z0-9\\._]");
 
125
                } else {
 
126
                        rx_no_word = QRegExp ("[^A-Za-z0-9\\._\\$\\:\\[\"\\]]");
 
127
                }
 
128
 
 
129
                // find out the next non-word stuff left and right of the current cursor position
 
130
                *start = context_line.findRev (rx_no_word, cursor_pos-1) + 1;
 
131
                *end = context_line.find (rx_no_word, cursor_pos);
 
132
                if (*end < 0) *end = context_line.length ();
 
133
        }
 
134
 
99
135
}       // namespace