JIndexRange JCovering ( const JIndexRange& r1, const JIndexRange& r2 ) { const JBoolean n1 = r1.IsNothing(); const JBoolean n2 = r2.IsNothing(); if (n1 && n2) { return JIndexRange(); } else if (n1) { return r2; } else if (n2) { return r1; } else { return JIndexRange( JMin(r1.first, r2.first), JMax((r1.IsEmpty() ? r1.first-1 : r1.last), (r2.IsEmpty() ? r2.first-1 : r2.last)) ); } }
void CBCommandPathInput::AdjustStylesBeforeRecalc ( const JString& buffer, JRunArray<JFont>* styles, JIndexRange* recalcRange, JIndexRange* redrawRange, const JBoolean deletion ) { if (!buffer.IsEmpty() && buffer.GetFirstCharacter() == '@') { const JColormap* colormap = GetColormap(); const JSize totalLength = buffer.GetLength(); JFont f = styles->GetFirstElement(); styles->RemoveAll(); f.SetColor(colormap->GetBlackColor()); styles->AppendElements(f, totalLength); *redrawRange += JIndexRange(1, totalLength); } else { return JXPathInput::AdjustStylesBeforeRecalc(buffer, styles, recalcRange, redrawRange, deletion); } }
void JFSBinding::CalcLiteralPrefix() { const JCharacter* s = itsPattern.GetCString(); JIndex i = 1; // skip leading ^ while (s[i] != '\0' && s[i] != '\\' && !JRegex::NeedsBackslashToBeLiteral(s[i])) { i++; } if (s[i] == '?') { i--; } itsLiteralPrefix = itsPattern.GetSubstring(JIndexRange(2, i)); }
void JXPathInput::AdjustStylesBeforeRecalc ( const JString& buffer, JRunArray<Font>* styles, JIndexRange* recalcRange, JIndexRange* redrawRange, const JBoolean deletion ) { const JColormap* colormap = GetColormap(); const JSize totalLength = buffer.GetLength(); JString fullPath = buffer; if ((JIsRelativePath(buffer) && !HasBasePath()) || !JExpandHomeDirShortcut(buffer, &fullPath)) { fullPath.Clear(); } // Last clause because if JConvertToAbsolutePath() succeeds, we don't // want to further modify fullName. else if (JIsRelativePath(buffer) && !JConvertToAbsolutePath(buffer, itsBasePath, &fullPath)) { if (HasBasePath()) { fullPath = JCombinePathAndName(itsBasePath, buffer); } else { fullPath.Clear(); } } JSize errLength; if (fullPath.IsEmpty()) { errLength = totalLength; } else { const JString closestDir = JGetClosestDirectory(fullPath, itsRequireWriteFlag); if (fullPath.BeginsWith(closestDir)) { errLength = fullPath.GetLength() - closestDir.GetLength(); } else { errLength = totalLength; } } if (errLength > 0 && buffer.EndsWith(kThisDirSuffix)) { errLength++; // trailing . is trimmed } Font f = styles->GetFirstElement(); styles->RemoveAll(); if (errLength >= totalLength) { f.style.color = colormap->GetRedColor(); styles->AppendElements(f, totalLength); } else { f.style.color = colormap->GetBlackColor(); styles->AppendElements(f, totalLength - errLength); if (errLength > 0) { f.style.color = colormap->GetRedColor(); styles->AppendElements(f, errLength); } } *redrawRange += JIndexRange(1, totalLength); }
void GDBGetCompletions::HandleSuccess ( const JString& data ) { JPtrArray<JString> lines(JPtrArrayT::kDeleteAll); lines.SetSortOrder(JOrderedSetT::kSortAscending); lines.SetCompareFunction(JCompareStringsCaseSensitive); // loop through each line and add each one to our list JIndex i = 1, j = 1; while (data.LocateNextSubstring("\n", &j)) { if (j > i) { JString* s = new JString(data, JIndexRange(i, j-1)); assert( s != NULL ); s->TrimWhitespace(); if (s->IsEmpty() || !lines.InsertSorted(s, kJFalse)) { delete s; } } i = j+1; j = i; } if (i <= data.GetLength()) { JString* s = new JString(data, JIndexRange(i, data.GetLength())); assert( s != NULL ); s->TrimWhitespace(); if (s->IsEmpty() || !lines.InsertSorted(s, kJFalse)) { delete s; } } if (lines.IsEmpty()) { (itsInput->GetDisplay())->Beep(); return; } // Check if we're done. If we find our test prefix in the array, and // the array has only one element, we're done. Otherwise, our test // prefix is the 'start' of several possible commands. const JSize stringCount = lines.GetElementCount(); JBoolean found; JIndex startIndex = lines.SearchSorted1(&itsPrefix, JOrderedSetT::kAnyMatch, &found); if (found) { if (stringCount == 1) { // The input text is already complete. We just need to add a // space at the end to show that it is a complete word. itsPrefix += " "; } else { // We can't add anything to what the user has types, so we show // all possible completions. itsHistory->PlaceCursorAtEnd(); itsHistory->Paste("\n"); itsHistory->Paste(data); } itsInput->SetText(itsPrefix); itsInput->SetCaretLocation(itsInput->GetTextLength() + 1); return; } JString maxPrefix; maxPrefix = *(lines.NthElement(startIndex)); if (stringCount == 1) { // There's only one completion, which must be what we meant so we // fill in the input with this word. maxPrefix += " "; itsInput->SetText(maxPrefix); itsInput->SetCaretLocation(itsInput->GetTextLength() + 1); return; } for (JIndex i=startIndex+1; i<=stringCount; i++) { const JString* s = lines.NthElement(i); const JSize matchLength = JCalcMatchLength(maxPrefix, *s); const JSize prefixLength = maxPrefix.GetLength(); if (matchLength < prefixLength) { maxPrefix.RemoveSubstring(matchLength+1, prefixLength); } } if (maxPrefix == itsPrefix) { // The input text is all that the words have in common so we can't // add anything to the input. We therefore need to dump everything // to the history window. itsHistory->PlaceCursorAtEnd(); itsHistory->Paste("\n"); itsHistory->Paste(data); } else { itsInput->SetText(maxPrefix); itsInput->SetCaretLocation(itsInput->GetTextLength() + 1); } }