Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/codegen/coderepresentation.cpp
Show All 38 Lines | 36 | { | |||
---|---|---|---|---|---|
39 | //Easier for single line ranges which should happen most of the time | 39 | //Easier for single line ranges which should happen most of the time | ||
40 | if(range.onSingleLine()) | 40 | if(range.onSingleLine()) | ||
41 | return QString( line( range.start().line() ).mid( range.start().column(), range.columnWidth() ) ); | 41 | return QString( line( range.start().line() ).mid( range.start().column(), range.columnWidth() ) ); | ||
42 | 42 | | |||
43 | //Add up al the requested lines | 43 | //Add up al the requested lines | ||
44 | QString rangedText = line(range.start().line()).mid(range.start().column()); | 44 | QString rangedText = line(range.start().line()).mid(range.start().column()); | ||
45 | 45 | | |||
46 | for(int i = range.start().line() + 1; i <= range.end().line(); ++i) | 46 | for(int i = range.start().line() + 1; i <= range.end().line(); ++i) | ||
47 | rangedText += '\n' + ((i == range.end().line()) ? line(i).left(range.end().column()) : line(i)); | 47 | rangedText += QLatin1Char('\n') + ((i == range.end().line()) ? line(i).left(range.end().column()) : line(i)); | ||
48 | 48 | | |||
49 | return rangedText; | 49 | return rangedText; | ||
50 | } | 50 | } | ||
51 | 51 | | |||
52 | static void grepLine(const QString& identifier, const QString& lineText, int lineNumber, QVector<KTextEditor::Range>& ret, bool surroundedByBoundary) | 52 | static void grepLine(const QString& identifier, const QString& lineText, int lineNumber, QVector<KTextEditor::Range>& ret, bool surroundedByBoundary) | ||
53 | { | 53 | { | ||
54 | if (identifier.isEmpty()) | 54 | if (identifier.isEmpty()) | ||
55 | return; | 55 | return; | ||
56 | 56 | | |||
57 | int pos = 0; | 57 | int pos = 0; | ||
58 | while(true) | 58 | while(true) | ||
59 | { | 59 | { | ||
60 | pos = lineText.indexOf(identifier, pos); | 60 | pos = lineText.indexOf(identifier, pos); | ||
61 | if(pos == -1) | 61 | if(pos == -1) | ||
62 | break; | 62 | break; | ||
63 | int start = pos; | 63 | int start = pos; | ||
64 | pos += identifier.length(); | 64 | pos += identifier.length(); | ||
65 | int end = pos; | 65 | int end = pos; | ||
66 | 66 | | |||
67 | if(!surroundedByBoundary || ( (end == lineText.length() || !lineText[end].isLetterOrNumber() || lineText[end] != '_') | 67 | if (!surroundedByBoundary || ( (end == lineText.length() || !lineText[end].isLetterOrNumber() || lineText[end] != QLatin1Char('_')) | ||
68 | && (start-1 < 0 || !lineText[start-1].isLetterOrNumber() || lineText[start-1] != '_')) ) | 68 | && (start-1 < 0 || !lineText[start-1].isLetterOrNumber() || lineText[start-1] != QLatin1Char('_'))) ) | ||
69 | { | 69 | { | ||
70 | ret << KTextEditor::Range(lineNumber, start, lineNumber, end); | 70 | ret << KTextEditor::Range(lineNumber, start, lineNumber, end); | ||
71 | } | 71 | } | ||
72 | } | 72 | } | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | class EditorCodeRepresentation : public DynamicCodeRepresentation { | 75 | class EditorCodeRepresentation : public DynamicCodeRepresentation { | ||
76 | public: | 76 | public: | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | |||||
153 | class FileCodeRepresentation : public CodeRepresentation { | 153 | class FileCodeRepresentation : public CodeRepresentation { | ||
154 | public: | 154 | public: | ||
155 | explicit FileCodeRepresentation(const IndexedString& document) : m_document(document) { | 155 | explicit FileCodeRepresentation(const IndexedString& document) : m_document(document) { | ||
156 | QString localFile(document.toUrl().toLocalFile()); | 156 | QString localFile(document.toUrl().toLocalFile()); | ||
157 | 157 | | |||
158 | QFile file( localFile ); | 158 | QFile file( localFile ); | ||
159 | if ( file.open(QIODevice::ReadOnly) ) { | 159 | if ( file.open(QIODevice::ReadOnly) ) { | ||
160 | data = QString::fromLocal8Bit(file.readAll()); | 160 | data = QString::fromLocal8Bit(file.readAll()); | ||
161 | lineData = data.split('\n'); | 161 | lineData = data.split(QLatin1Char('\n')); | ||
162 | } | 162 | } | ||
163 | m_exists = file.exists(); | 163 | m_exists = file.exists(); | ||
164 | } | 164 | } | ||
165 | 165 | | |||
166 | QString line(int line) const override { | 166 | QString line(int line) const override { | ||
167 | if(line < 0 || line >= lineData.size()) | 167 | if(line < 0 || line >= lineData.size()) | ||
168 | return QString(); | 168 | return QString(); | ||
169 | 169 | | |||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
223 | 223 | | |||
224 | class ArtificialStringData : public QSharedData { | 224 | class ArtificialStringData : public QSharedData { | ||
225 | public: | 225 | public: | ||
226 | explicit ArtificialStringData(const QString& data) { | 226 | explicit ArtificialStringData(const QString& data) { | ||
227 | setData(data); | 227 | setData(data); | ||
228 | } | 228 | } | ||
229 | void setData(const QString& data) { | 229 | void setData(const QString& data) { | ||
230 | m_data = data; | 230 | m_data = data; | ||
231 | m_lineData = m_data.split('\n'); | 231 | m_lineData = m_data.split(QLatin1Char('\n')); | ||
232 | } | 232 | } | ||
233 | QString data() const { | 233 | QString data() const { | ||
234 | return m_data; | 234 | return m_data; | ||
235 | } | 235 | } | ||
236 | const QStringList& lines() const { | 236 | const QStringList& lines() const { | ||
237 | return m_lineData; | 237 | return m_lineData; | ||
238 | } | 238 | } | ||
239 | 239 | | |||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |