author | erik <erik> | 2007-01-24 19:54:07 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 19:54:07 (UTC) |
commit | 89e81059e832ff77c2f0ac8b9db12f80eafa03fc (patch) (unidiff) | |
tree | 99a130fc643d2aeefdecab452f644e7b61a5f50e /noncore/apps/tinykate/libkate | |
parent | 035bbc5bf689839c8d8e7be37f347b0dd900fccf (diff) | |
download | opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.zip opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.gz opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.bz2 |
Each file in this commit has an instance where a pointer is checked at
one point in the code and then not checked in another point in the code.
If it needed to be checked once, it needs to be checked the other time. If not
the application could segfault.
Diffstat (limited to 'noncore/apps/tinykate/libkate') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 123 |
1 files changed, 62 insertions, 61 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index b82a86a..692fd46 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -1970,370 +1970,371 @@ void KateDocument::slotBufferChanged() { | |||
1970 | //updateLines();//JW | 1970 | //updateLines();//JW |
1971 | updateViews(); | 1971 | updateViews(); |
1972 | } | 1972 | } |
1973 | 1973 | ||
1974 | void KateDocument::slotBufferHighlight(long start,long stop) { | 1974 | void KateDocument::slotBufferHighlight(long start,long stop) { |
1975 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; | 1975 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; |
1976 | updateLines(start,stop); | 1976 | updateLines(start,stop); |
1977 | // buffer->startLoadTimer(); | 1977 | // buffer->startLoadTimer(); |
1978 | } | 1978 | } |
1979 | 1979 | ||
1980 | void KateDocument::updateViews(KateView *exclude) { | 1980 | void KateDocument::updateViews(KateView *exclude) { |
1981 | KateView *view; | 1981 | KateView *view; |
1982 | int flags; | 1982 | int flags; |
1983 | bool markState = hasMarkedText(); | 1983 | bool markState = hasMarkedText(); |
1984 | 1984 | ||
1985 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; | 1985 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; |
1986 | for (view = views.first(); view != 0L; view = views.next() ) { | 1986 | for (view = views.first(); view != 0L; view = views.next() ) { |
1987 | if (view != exclude) view->updateView(flags); | 1987 | if (view != exclude) view->updateView(flags); |
1988 | 1988 | ||
1989 | // notify every view about the changed mark state.... | 1989 | // notify every view about the changed mark state.... |
1990 | if (oldMarkState != markState) emit view->newMarkStatus(); | 1990 | if (oldMarkState != markState) emit view->newMarkStatus(); |
1991 | } | 1991 | } |
1992 | oldMarkState = markState; | 1992 | oldMarkState = markState; |
1993 | newDocGeometry = false; | 1993 | newDocGeometry = false; |
1994 | } | 1994 | } |
1995 | 1995 | ||
1996 | QColor &KateDocument::cursorCol(int x, int y) { | 1996 | QColor &KateDocument::cursorCol(int x, int y) { |
1997 | int attr; | 1997 | int attr; |
1998 | Attribute *a; | 1998 | Attribute *a; |
1999 | 1999 | ||
2000 | TextLine::Ptr textLine = getTextLine(y); | 2000 | TextLine::Ptr textLine = getTextLine(y); |
2001 | attr = textLine->getRawAttr(x); | 2001 | attr = textLine->getRawAttr(x); |
2002 | a = &m_attribs[attr & taAttrMask]; | 2002 | a = &m_attribs[attr & taAttrMask]; |
2003 | if (attr & taSelected) return a->selCol; else return a->col; | 2003 | if (attr & taSelected) return a->selCol; else return a->col; |
2004 | } | 2004 | } |
2005 | 2005 | ||
2006 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) | 2006 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) |
2007 | { | 2007 | { |
2008 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); | 2008 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); |
2009 | } | 2009 | } |
2010 | 2010 | ||
2011 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) | 2011 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) |
2012 | { | 2012 | { |
2013 | TextLine::Ptr textLine; | 2013 | TextLine::Ptr textLine; |
2014 | int len; | 2014 | int len; |
2015 | const QChar *s; | 2015 | const QChar *s; |
2016 | int z, x; | 2016 | int z, x; |
2017 | QChar ch; | 2017 | QChar ch; |
2018 | Attribute *a = 0L; | 2018 | Attribute *attrptr = 0L; |
2019 | int attr, nextAttr; | 2019 | int attr, nextAttr; |
2020 | int xs; | 2020 | int xs; |
2021 | int xc, zc; | 2021 | int xc, zc; |
2022 | 2022 | ||
2023 | if (line > lastLine()) { | 2023 | if (line > lastLine()) { |
2024 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); | 2024 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); |
2025 | return; | 2025 | return; |
2026 | } | 2026 | } |
2027 | 2027 | ||
2028 | textLine = getTextLine(line); | 2028 | textLine = getTextLine(line); |
2029 | len = textLine->length(); | 2029 | len = textLine->length(); |
2030 | s = textLine->getText(); | 2030 | s = textLine->getText(); |
2031 | 2031 | ||
2032 | // skip to first visible character | 2032 | // skip to first visible character |
2033 | x = 0; | 2033 | x = 0; |
2034 | z = 0; | 2034 | z = 0; |
2035 | do { | 2035 | do { |
2036 | xc = x; | 2036 | xc = x; |
2037 | zc = z; | 2037 | zc = z; |
2038 | if (z == len) break; | 2038 | if (z == len) break; |
2039 | ch = s[z];//textLine->getChar(z); | 2039 | ch = s[z];//textLine->getChar(z); |
2040 | if (ch == '\t') { | 2040 | if (ch == '\t') { |
2041 | x += m_tabWidth - (x % m_tabWidth); | 2041 | x += m_tabWidth - (x % m_tabWidth); |
2042 | } else { | 2042 | } else { |
2043 | a = &m_attribs[textLine->getAttr(z)]; | 2043 | attrptr = &m_attribs[textLine->getAttr(z)]; |
2044 | 2044 | ||
2045 | if (a->bold && a->italic) | 2045 | if (attrptr->bold && attrptr->italic) |
2046 | x += myFontMetricsBI.width(ch); | 2046 | x += myFontMetricsBI.width(ch); |
2047 | else if (a->bold) | 2047 | else if (attrptr->bold) |
2048 | x += myFontMetricsBold.width(ch); | 2048 | x += myFontMetricsBold.width(ch); |
2049 | else if (a->italic) | 2049 | else if (attrptr->italic) |
2050 | x += myFontMetricsItalic.width(ch); | 2050 | x += myFontMetricsItalic.width(ch); |
2051 | else | 2051 | else |
2052 | x += myFontMetrics.width(ch); | 2052 | x += myFontMetrics.width(ch); |
2053 | } | 2053 | } |
2054 | z++; | 2054 | z++; |
2055 | } while (x <= xStart); | 2055 | } while (x <= xStart); |
2056 | 2056 | ||
2057 | // draw background | 2057 | // draw background |
2058 | xs = xStart; | 2058 | xs = xStart; |
2059 | attr = textLine->getRawAttr(zc); | 2059 | attr = textLine->getRawAttr(zc); |
2060 | while (x < xEnd) | 2060 | while (x < xEnd) |
2061 | { | 2061 | { |
2062 | nextAttr = textLine->getRawAttr(z); | 2062 | nextAttr = textLine->getRawAttr(z); |
2063 | if ((nextAttr ^ attr) & taSelected) | 2063 | if ((nextAttr ^ attr) & taSelected) |
2064 | { | 2064 | { |
2065 | if (attr & taSelected) | 2065 | if (attr & taSelected) |
2066 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); | 2066 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); |
2067 | else | 2067 | else |
2068 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); | 2068 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); |
2069 | 2069 | ||
2070 | xs = x; | 2070 | xs = x; |
2071 | attr = nextAttr; | 2071 | attr = nextAttr; |
2072 | } | 2072 | } |
2073 | 2073 | ||
2074 | if (z == len) break; | 2074 | if (z == len) break; |
2075 | 2075 | ||
2076 | ch = s[z];//textLine->getChar(z); | 2076 | ch = s[z];//textLine->getChar(z); |
2077 | 2077 | ||
2078 | if (ch == '\t') | 2078 | if (ch == '\t') |
2079 | x += m_tabWidth - (x % m_tabWidth); | 2079 | x += m_tabWidth - (x % m_tabWidth); |
2080 | else | 2080 | else |
2081 | { | 2081 | { |
2082 | a = &m_attribs[textLine->getAttr(z)]; | 2082 | attrptr = &m_attribs[textLine->getAttr(z)]; |
2083 | 2083 | ||
2084 | if (a->bold && a->italic) | 2084 | if (attrptr->bold && attrptr->italic) |
2085 | x += myFontMetricsBI.width(ch); | 2085 | x += myFontMetricsBI.width(ch); |
2086 | else if (a->bold) | 2086 | else if (attrptr->bold) |
2087 | x += myFontMetricsBold.width(ch); | 2087 | x += myFontMetricsBold.width(ch); |
2088 | else if (a->italic) | 2088 | else if (attrptr->italic) |
2089 | x += myFontMetricsItalic.width(ch); | 2089 | x += myFontMetricsItalic.width(ch); |
2090 | else | 2090 | else |
2091 | x += myFontMetrics.width(ch); | 2091 | x += myFontMetrics.width(ch); |
2092 | } | 2092 | } |
2093 | z++; | 2093 | z++; |
2094 | } | 2094 | } |
2095 | 2095 | ||
2096 | if (attr & taSelected) | 2096 | if (attr & taSelected) |
2097 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); | 2097 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); |
2098 | else | 2098 | else |
2099 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); | 2099 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); |
2100 | 2100 | ||
2101 | len = z; //reduce length to visible length | 2101 | len = z; //reduce length to visible length |
2102 | 2102 | ||
2103 | // draw text | 2103 | // draw text |
2104 | x = xc; | 2104 | x = xc; |
2105 | z = zc; | 2105 | z = zc; |
2106 | y += fontAscent;// -1; | 2106 | y += fontAscent;// -1; |
2107 | attr = -1; | 2107 | attr = -1; |
2108 | while (z < len) { | 2108 | while (z < len) { |
2109 | ch = s[z];//textLine->getChar(z); | 2109 | ch = s[z];//textLine->getChar(z); |
2110 | if (ch == '\t') { | 2110 | if (ch == '\t') { |
2111 | if (z > zc) { | 2111 | if (z > zc) { |
2112 | //this should cause no copy at all | 2112 | //this should cause no copy at all |
2113 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2113 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2114 | QString s = str.string(); | 2114 | QString s = str.string(); |
2115 | paint.drawText(x - xStart, y, s); | 2115 | paint.drawText(x - xStart, y, s); |
2116 | 2116 | ||
2117 | if (a->bold && a->italic) | 2117 | if (attrptr && attrptr->bold && attrptr->italic) |
2118 | x += myFontMetricsBI.width(s); | 2118 | x += myFontMetricsBI.width(s); |
2119 | else if (a->bold) | 2119 | else if (attrptr && attrptr->bold) |
2120 | x += myFontMetricsBold.width(s); | 2120 | x += myFontMetricsBold.width(s); |
2121 | else if (a->italic) | 2121 | else if (attrptr && attrptr->italic) |
2122 | x += myFontMetricsItalic.width(s); | 2122 | x += myFontMetricsItalic.width(s); |
2123 | else | 2123 | else |
2124 | x += myFontMetrics.width(s); | 2124 | x += myFontMetrics.width(s); |
2125 | } | 2125 | } |
2126 | zc = z +1; | 2126 | zc = z +1; |
2127 | 2127 | ||
2128 | if (showTabs) { | 2128 | if (showTabs) { |
2129 | nextAttr = textLine->getRawAttr(z); | 2129 | nextAttr = textLine->getRawAttr(z); |
2130 | if (nextAttr != attr) { | 2130 | if (nextAttr != attr) { |
2131 | attr = nextAttr; | 2131 | attr = nextAttr; |
2132 | a = &m_attribs[attr & taAttrMask]; | 2132 | attrptr = &m_attribs[attr & taAttrMask]; |
2133 | 2133 | ||
2134 | if (attr & taSelected) paint.setPen(a->selCol); | 2134 | if (attr & taSelected) paint.setPen(attrptr->selCol); |
2135 | else paint.setPen(a->col); | 2135 | else paint.setPen(attrptr->col); |
2136 | 2136 | ||
2137 | if (a->bold && a->italic) | 2137 | if (attrptr->bold && attrptr->italic) |
2138 | paint.setFont(myFontBI); | 2138 | paint.setFont(myFontBI); |
2139 | else if (a->bold) | 2139 | else if (attrptr->bold) |
2140 | paint.setFont(myFontBold); | 2140 | paint.setFont(myFontBold); |
2141 | else if (a->italic) | 2141 | else if (attrptr->italic) |
2142 | paint.setFont(myFontItalic); | 2142 | paint.setFont(myFontItalic); |
2143 | else | 2143 | else |
2144 | paint.setFont(myFont); | 2144 | paint.setFont(myFont); |
2145 | } | 2145 | } |
2146 | 2146 | ||
2147 | // paint.drawLine(x - xStart, y -2, x - xStart, y); | ||
2148 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); | ||
2149 | paint.drawPoint(x - xStart, y); | 2147 | paint.drawPoint(x - xStart, y); |
2150 | paint.drawPoint(x - xStart +1, y); | 2148 | paint.drawPoint(x - xStart +1, y); |
2151 | paint.drawPoint(x - xStart, y -1); | 2149 | paint.drawPoint(x - xStart, y -1); |
2152 | } | 2150 | } |
2153 | x += m_tabWidth - (x % m_tabWidth); | 2151 | x += m_tabWidth - (x % m_tabWidth); |
2154 | } else { | 2152 | } else { |
2155 | nextAttr = textLine->getRawAttr(z); | 2153 | nextAttr = textLine->getRawAttr(z); |
2156 | if (nextAttr != attr) { | 2154 | if (nextAttr != attr) { |
2157 | if (z > zc) { | 2155 | if (z > zc) { |
2158 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2156 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2159 | QString s = str.string(); | 2157 | QString s = str.string(); |
2160 | paint.drawText(x - xStart, y, s); | 2158 | paint.drawText(x - xStart, y, s); |
2161 | 2159 | ||
2162 | if (a->bold && a->italic) | 2160 | if (attrptr->bold && attrptr->italic) |
2163 | x += myFontMetricsBI.width(s); | 2161 | x += myFontMetricsBI.width(s); |
2164 | else if (a->bold) | 2162 | else if (attrptr->bold) |
2165 | x += myFontMetricsBold.width(s); | 2163 | x += myFontMetricsBold.width(s); |
2166 | else if (a->italic) | 2164 | else if (attrptr->italic) |
2167 | x += myFontMetricsItalic.width(s); | 2165 | x += myFontMetricsItalic.width(s); |
2168 | else | 2166 | else |
2169 | x += myFontMetrics.width(s); | 2167 | x += myFontMetrics.width(s); |
2170 | zc = z; | 2168 | zc = z; |
2171 | } | 2169 | } |
2172 | attr = nextAttr; | 2170 | attr = nextAttr; |
2173 | a = &m_attribs[attr & taAttrMask]; | 2171 | attrptr = &m_attribs[attr & taAttrMask]; |
2174 | 2172 | ||
2175 | if (attr & taSelected) paint.setPen(a->selCol); | 2173 | if (attr & taSelected) paint.setPen(attrptr->selCol); |
2176 | else paint.setPen(a->col); | 2174 | else paint.setPen(attrptr->col); |
2177 | 2175 | ||
2178 | if (a->bold && a->italic) | 2176 | if (attrptr->bold && attrptr->italic) |
2179 | paint.setFont(myFontBI); | 2177 | paint.setFont(myFontBI); |
2180 | else if (a->bold) | 2178 | else if (attrptr->bold) |
2181 | paint.setFont(myFontBold); | 2179 | paint.setFont(myFontBold); |
2182 | else if (a->italic) | 2180 | else if (attrptr->italic) |
2183 | paint.setFont(myFontItalic); | 2181 | paint.setFont(myFontItalic); |
2184 | else | 2182 | else |
2185 | paint.setFont(myFont); | 2183 | paint.setFont(myFont); |
2186 | } | 2184 | } |
2187 | } | 2185 | } |
2188 | z++; | 2186 | z++; |
2189 | } | 2187 | } |
2190 | if (z > zc) { | 2188 | if (z > zc) { |
2191 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2189 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2192 | paint.drawText(x - xStart, y, str.string()); | 2190 | paint.drawText(x - xStart, y, str.string()); |
2193 | } | 2191 | } |
2194 | } | 2192 | } |
2195 | 2193 | ||
2196 | // Applies the search context, and returns whether a match was found. If one is, | 2194 | // Applies the search context, and returns whether a match was found. If one is, |
2197 | // the length of the string matched is also returned. | 2195 | // the length of the string matched is also returned. |
2198 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { | 2196 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { |
2199 | int line, col; | 2197 | int line, col; |
2200 | int searchEnd; | 2198 | int searchEnd; |
2201 | int bufLen, tlen; | 2199 | int bufLen, tlen; |
2202 | QChar *t; | 2200 | QChar *t; |
2203 | TextLine::Ptr textLine; | 2201 | TextLine::Ptr textLine; |
2204 | int pos, newPos; | 2202 | int pos, newPos; |
2205 | 2203 | ||
2206 | if (searchFor.isEmpty()) return false; | 2204 | if (searchFor.isEmpty()) return false; |
2207 | 2205 | ||
2208 | bufLen = 0; | 2206 | bufLen = 0; |
2209 | t = 0L; | 2207 | t = 0L; |
2210 | 2208 | ||
2211 | line = sc.cursor.y; | 2209 | line = sc.cursor.y; |
2212 | col = sc.cursor.x; | 2210 | col = sc.cursor.x; |
2213 | if (!(sc.flags & KateView::sfBackward)) { | 2211 | if (!(sc.flags & KateView::sfBackward)) { |
2214 | //forward search | 2212 | //forward search |
2215 | if (sc.flags & KateView::sfSelected) { | 2213 | if (sc.flags & KateView::sfSelected) { |
2216 | if (line < selectStart) { | 2214 | if (line < selectStart) { |
2217 | line = selectStart; | 2215 | line = selectStart; |
2218 | col = 0; | 2216 | col = 0; |
2219 | } | 2217 | } |
2220 | searchEnd = selectEnd; | 2218 | searchEnd = selectEnd; |
2221 | } else searchEnd = lastLine(); | 2219 | } else searchEnd = lastLine(); |
2222 | 2220 | ||
2223 | while (line <= searchEnd) { | 2221 | while (line <= searchEnd) { |
2224 | textLine = getTextLine(line); | 2222 | textLine = getTextLine(line); |
2225 | tlen = textLine->length(); | 2223 | tlen = textLine->length(); |
2226 | if (tlen > bufLen) { | 2224 | if (tlen > bufLen) { |
2227 | delete [] t; | 2225 | delete [] t; |
2228 | bufLen = (tlen + 255) & (~255); | 2226 | bufLen = (tlen + 255) & (~255); |
2229 | t = new QChar[bufLen]; | 2227 | t = new QChar[bufLen]; |
2230 | } | 2228 | } else if (!t) |
2229 | t = new QChar[bufLen]; | ||
2230 | |||
2231 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2231 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2232 | if (sc.flags & KateView::sfSelected) { | 2232 | if (sc.flags & KateView::sfSelected) { |
2233 | pos = 0; | 2233 | pos = 0; |
2234 | do { | 2234 | do { |
2235 | pos = textLine->findSelected(pos); | 2235 | pos = textLine->findSelected(pos); |
2236 | newPos = textLine->findUnselected(pos); | 2236 | newPos = textLine->findUnselected(pos); |
2237 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2237 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2238 | pos = newPos; | 2238 | pos = newPos; |
2239 | } while (pos < tlen); | 2239 | } while (pos < tlen); |
2240 | } | 2240 | } |
2241 | 2241 | ||
2242 | QString text(t, tlen); | 2242 | QString text(t, tlen); |
2243 | if (sc.flags & KateView::sfWholeWords) { | 2243 | if (sc.flags & KateView::sfWholeWords) { |
2244 | // Until the end of the line... | 2244 | // Until the end of the line... |
2245 | while (col < tlen) { | 2245 | while (col < tlen) { |
2246 | // ...find the next match. | 2246 | // ...find the next match. |
2247 | col = sc.search(text, col); | 2247 | col = sc.search(text, col); |
2248 | if (col != -1) { | 2248 | if (col != -1) { |
2249 | // Is the match delimited correctly? | 2249 | // Is the match delimited correctly? |
2250 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2250 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2251 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2251 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2252 | goto found; | 2252 | goto found; |
2253 | } | 2253 | } |
2254 | else { | 2254 | else { |
2255 | // Start again from the next character. | 2255 | // Start again from the next character. |
2256 | col++; | 2256 | col++; |
2257 | } | 2257 | } |
2258 | } | 2258 | } |
2259 | else { | 2259 | else { |
2260 | // No match. | 2260 | // No match. |
2261 | break; | 2261 | break; |
2262 | } | 2262 | } |
2263 | } | 2263 | } |
2264 | } | 2264 | } |
2265 | else { | 2265 | else { |
2266 | // Non-whole-word search. | 2266 | // Non-whole-word search. |
2267 | col = sc.search(text, col); | 2267 | col = sc.search(text, col); |
2268 | if (col != -1) | 2268 | if (col != -1) |
2269 | goto found; | 2269 | goto found; |
2270 | } | 2270 | } |
2271 | col = 0; | 2271 | col = 0; |
2272 | line++; | 2272 | line++; |
2273 | } | 2273 | } |
2274 | } else { | 2274 | } else { |
2275 | // backward search | 2275 | // backward search |
2276 | if (sc.flags & KateView::sfSelected) { | 2276 | if (sc.flags & KateView::sfSelected) { |
2277 | if (line > selectEnd) { | 2277 | if (line > selectEnd) { |
2278 | line = selectEnd; | 2278 | line = selectEnd; |
2279 | col = -1; | 2279 | col = -1; |
2280 | } | 2280 | } |
2281 | searchEnd = selectStart; | 2281 | searchEnd = selectStart; |
2282 | } else searchEnd = 0; | 2282 | } else searchEnd = 0; |
2283 | 2283 | ||
2284 | while (line >= searchEnd) { | 2284 | while (line >= searchEnd) { |
2285 | textLine = getTextLine(line); | 2285 | textLine = getTextLine(line); |
2286 | tlen = textLine->length(); | 2286 | tlen = textLine->length(); |
2287 | if (tlen > bufLen) { | 2287 | if (tlen > bufLen) { |
2288 | delete [] t; | 2288 | delete [] t; |
2289 | bufLen = (tlen + 255) & (~255); | 2289 | bufLen = (tlen + 255) & (~255); |
2290 | t = new QChar[bufLen]; | 2290 | t = new QChar[bufLen]; |
2291 | } | 2291 | } else if (!t) |
2292 | t = new QChar[bufLen]; | ||
2292 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2293 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2293 | if (sc.flags & KateView::sfSelected) { | 2294 | if (sc.flags & KateView::sfSelected) { |
2294 | pos = 0; | 2295 | pos = 0; |
2295 | do { | 2296 | do { |
2296 | pos = textLine->findSelected(pos); | 2297 | pos = textLine->findSelected(pos); |
2297 | newPos = textLine->findUnselected(pos); | 2298 | newPos = textLine->findUnselected(pos); |
2298 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2299 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2299 | pos = newPos; | 2300 | pos = newPos; |
2300 | } while (pos < tlen); | 2301 | } while (pos < tlen); |
2301 | } | 2302 | } |
2302 | 2303 | ||
2303 | if (col < 0 || col > tlen) col = tlen; | 2304 | if (col < 0 || col > tlen) col = tlen; |
2304 | 2305 | ||
2305 | QString text(t, tlen); | 2306 | QString text(t, tlen); |
2306 | if (sc.flags & KateView::sfWholeWords) { | 2307 | if (sc.flags & KateView::sfWholeWords) { |
2307 | // Until the beginning of the line... | 2308 | // Until the beginning of the line... |
2308 | while (col >= 0) { | 2309 | while (col >= 0) { |
2309 | // ...find the next match. | 2310 | // ...find the next match. |
2310 | col = sc.search(text, col); | 2311 | col = sc.search(text, col); |
2311 | if (col != -1) { | 2312 | if (col != -1) { |
2312 | // Is the match delimited correctly? | 2313 | // Is the match delimited correctly? |
2313 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2314 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2314 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2315 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2315 | goto found; | 2316 | goto found; |
2316 | } | 2317 | } |
2317 | else { | 2318 | else { |
2318 | // Start again from the previous character. | 2319 | // Start again from the previous character. |
2319 | col--; | 2320 | col--; |
2320 | } | 2321 | } |
2321 | } | 2322 | } |
2322 | else { | 2323 | else { |
2323 | // No match. | 2324 | // No match. |
2324 | break; | 2325 | break; |
2325 | } | 2326 | } |
2326 | } | 2327 | } |
2327 | } | 2328 | } |
2328 | else { | 2329 | else { |
2329 | // Non-whole-word search. | 2330 | // Non-whole-word search. |
2330 | col = sc.search(text, col); | 2331 | col = sc.search(text, col); |
2331 | if (col != -1) | 2332 | if (col != -1) |
2332 | goto found; | 2333 | goto found; |
2333 | } | 2334 | } |
2334 | col = -1; | 2335 | col = -1; |
2335 | line--; | 2336 | line--; |
2336 | } | 2337 | } |
2337 | } | 2338 | } |
2338 | sc.flags |= KateView::sfWrapped; | 2339 | sc.flags |= KateView::sfWrapped; |
2339 | return false; | 2340 | return false; |