diff options
Diffstat (limited to 'scintilla/src/Document.cxx')
-rw-r--r-- | scintilla/src/Document.cxx | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index c45b582..ee621bf 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -662,7 +662,8 @@ bool SCI_METHOD Document::IsDBCSLeadByte(char ch) const { case 932:
// Shift_jis
return ((uch >= 0x81) && (uch <= 0x9F)) ||
- ((uch >= 0xE0) && (uch <= 0xEF));
+ ((uch >= 0xE0) && (uch <= 0xFC));
+ // Lead bytes F0 to FC may be a Microsoft addition.
case 936:
// GBK
return (uch >= 0x81) && (uch <= 0xFE);
@@ -1112,17 +1113,17 @@ void Document::Indent(bool forwards, int lineBottom, int lineTop) { // Convert line endings for a piece of text to a particular mode.
// Stop at len or when a NUL is found.
// Caller must delete the returned pointer.
-char *Document::TransformLineEnds(int *pLenOut, const char *s, size_t len, int eolMode) {
+char *Document::TransformLineEnds(int *pLenOut, const char *s, size_t len, int eolModeWanted) {
char *dest = new char[2 * len + 1];
const char *sptr = s;
char *dptr = dest;
for (size_t i = 0; (i < len) && (*sptr != '\0'); i++) {
if (*sptr == '\n' || *sptr == '\r') {
- if (eolMode == SC_EOL_CR) {
+ if (eolModeWanted == SC_EOL_CR) {
*dptr++ = '\r';
- } else if (eolMode == SC_EOL_LF) {
+ } else if (eolModeWanted == SC_EOL_LF) {
*dptr++ = '\n';
- } else { // eolMode == SC_EOL_CRLF
+ } else { // eolModeWanted == SC_EOL_CRLF
*dptr++ = '\r';
*dptr++ = '\n';
}
@@ -1427,7 +1428,6 @@ long Document::FindText(int minPos, int maxPos, const char *search, // Compute actual search ranges needed
const int lengthFind = (*length == -1) ? static_cast<int>(strlen(search)) : *length;
- const int endSearch = (startPos <= endPos) ? endPos - lengthFind + 1 : endPos;
//Platform::DebugPrintf("Find %d %d %s %d\n", startPos, endPos, ft->lpstrText, lengthFind);
const int limitPos = Platform::Maximum(startPos, endPos);
@@ -1437,6 +1437,7 @@ long Document::FindText(int minPos, int maxPos, const char *search, pos = NextPosition(pos, increment);
}
if (caseSensitive) {
+ const int endSearch = (startPos <= endPos) ? endPos - lengthFind + 1 : endPos;
while (forward ? (pos < endSearch) : (pos >= endSearch)) {
bool found = (pos + lengthFind) <= limitPos;
for (int indexSearch = 0; (indexSearch < lengthFind) && found; indexSearch++) {
@@ -1454,7 +1455,7 @@ long Document::FindText(int minPos, int maxPos, const char *search, std::vector<char> searchThing(lengthFind * maxBytesCharacter * maxFoldingExpansion + 1);
const int lenSearch = static_cast<int>(
pcf->Fold(&searchThing[0], searchThing.size(), search, lengthFind));
- while (forward ? (pos < endSearch) : (pos >= endSearch)) {
+ while (forward ? (pos < endPos) : (pos >= endPos)) {
int widthFirstCharacter = 0;
int indexDocument = 0;
int indexSearch = 0;
@@ -1467,6 +1468,8 @@ long Document::FindText(int minPos, int maxPos, const char *search, const int widthChar = static_cast<int>(ExtractChar(pos + indexDocument, bytes));
if (!widthFirstCharacter)
widthFirstCharacter = widthChar;
+ if ((pos + indexDocument + widthChar) > limitPos)
+ break;
char folded[maxBytesCharacter * maxFoldingExpansion + 1];
const int lenFlat = static_cast<int>(pcf->Fold(folded, sizeof(folded), bytes, widthChar));
folded[lenFlat] = 0;
@@ -1494,7 +1497,7 @@ long Document::FindText(int minPos, int maxPos, const char *search, std::vector<char> searchThing(lengthFind * maxBytesCharacter * maxFoldingExpansion + 1);
const int lenSearch = static_cast<int>(
pcf->Fold(&searchThing[0], searchThing.size(), search, lengthFind));
- while (forward ? (pos < endSearch) : (pos >= endSearch)) {
+ while (forward ? (pos < endPos) : (pos >= endPos)) {
int indexDocument = 0;
int indexSearch = 0;
bool characterMatches = true;
@@ -1506,6 +1509,8 @@ long Document::FindText(int minPos, int maxPos, const char *search, const int widthChar = IsDBCSLeadByte(bytes[0]) ? 2 : 1;
if (widthChar == 2)
bytes[1] = cb.CharAt(pos + indexDocument + 1);
+ if ((pos + indexDocument + widthChar) > limitPos)
+ break;
char folded[maxBytesCharacter * maxFoldingExpansion + 1];
const int lenFlat = static_cast<int>(pcf->Fold(folded, sizeof(folded), bytes, widthChar));
folded[lenFlat] = 0;
@@ -1524,7 +1529,7 @@ long Document::FindText(int minPos, int maxPos, const char *search, break;
}
} else {
- CaseFolderTable caseFolder;
+ const int endSearch = (startPos <= endPos) ? endPos - lengthFind + 1 : endPos;
std::vector<char> searchThing(lengthFind + 1);
pcf->Fold(&searchThing[0], searchThing.size(), search, lengthFind);
while (forward ? (pos < endSearch) : (pos >= endSearch)) {
|