void JTEStyler::UpdateStyles ( const JTextEditor* te, const JString& text, JRunArray<JTextEditor::Font>* styles, JIndexRange* recalcRange, JIndexRange* redrawRange, const JBoolean deletion, JArray<TokenData>* tokenStartList ) { if (!itsActiveFlag) { tokenStartList->RemoveAll(); return; } const JSize textLength = text.GetLength(); if (textLength == 0) { tokenStartList->RemoveAll(); return; } te->GetDefaultFont(&itsDefFontID, &itsFontSize, &itsDefFontStyle, &itsDefFontAlign); itsFontName = te->GetDefaultFontName(); TokenData tokenData; if (recalcRange->first == 1 && recalcRange->last >= text.GetLength()) { itsRedoAllFlag = kJTrue; itsCheckRange.Set(1, text.GetLength()); tokenStartList->RemoveAll(); tokenData = TokenData(1, GetFirstTokenExtraData()); tokenStartList->AppendElement(tokenData); styles->RemoveAll(); } else { itsRedoAllFlag = kJFalse; // calculate the range that needs to be checked JIndex firstIndex = recalcRange->first; JIndex lastIndex = recalcRange->last; if ((deletion && firstIndex > 1) || firstIndex > textLength) { // This fixes the case when the last character of the token is deleted. firstIndex--; // This fixes the case when the style run and the token both // end at the inserted text. (e.g. "x [ y ]" <- "x // y ]") lastIndex++; } if (lastIndex > textLength) { // We can't decrease recalcRange's end index, and we can't find // textLength+1 in *styles. lastIndex = textLength; } JIndex runIndex1, firstIndexInRun1; JBoolean ok = styles->FindRun(firstIndex, &runIndex1, &firstIndexInRun1); assert( ok ); JIndex runIndex2 = runIndex1; JIndex firstIndexInRun2 = firstIndexInRun1; ok = styles->FindRun(firstIndex, lastIndex, &runIndex2, &firstIndexInRun2); assert( ok ); run_assert(styles, lastIndex, runIndex2, firstIndexInRun2); itsCheckRange.Set(firstIndexInRun1, firstIndexInRun2 + styles->GetRunLength(runIndex2)-1); // let derived class expand the range JIndexRange savedRange = itsCheckRange; PreexpandCheckRange(text, *styles, *recalcRange, deletion, &itsCheckRange); assert( itsCheckRange.Contains(savedRange) && itsCheckRange.last <= styles->GetElementCount() ); // find nearest token in front of itsCheckRange if (tokenStartList->IsEmpty()) { tokenData = TokenData(1, GetFirstTokenExtraData()); tokenStartList->AppendElement(tokenData); } else { JBoolean foundTokenStart; TokenData target(itsCheckRange.first, TokenExtra()); JIndex tokenStartIndex = tokenStartList->SearchSorted1(target, JOrderedSetT::kAnyMatch, &foundTokenStart); if (!foundTokenStart) { tokenStartIndex--; // wants to insert -after- the value } tokenData = tokenStartList->GetElement(tokenStartIndex); // the rest of the token starts are invalid const JSize tokenStartCount = tokenStartList->GetElementCount(); if (tokenStartIndex < tokenStartCount) { tokenStartList->RemoveNextElements(tokenStartIndex+1, tokenStartCount - tokenStartIndex); } } // While typing in one place, it is much faster to back up from itsCheckRange // than to start from the top. itsTokenRunIndex = runIndex1; itsTokenFirstInRun = firstIndexInRun1; ok = styles->FindRun(firstIndex, tokenData.startIndex, &itsTokenRunIndex, &itsTokenFirstInRun); assert( ok ); run_assert(styles, tokenData.startIndex, itsTokenRunIndex, itsTokenFirstInRun); } // prepare to accumulate new token starts itsTokenStartList = tokenStartList; itsTokenStartCount = 0; itsTokenStart = tokenData.startIndex; // scan the text and adjust the styles std::istrstream input(text.GetCString(), text.GetLength()); JSeekg(input, itsTokenStart-1); itsTE = te; itsFontMgr = te->TEGetFontManager(); itsText = &text; itsStyles = styles; itsRecalcRange = recalcRange; itsRedrawRange = redrawRange; #if DEBUG_TIMING_INFO JStopWatch timer; timer.StartTimer(); #endif Scan(input, tokenData.data); #if DEBUG_TIMING_INFO timer.StopTimer(); cout << "JTEStyler: " << timer.PrintTimeInterval() << endl; #endif itsTE = NULL; itsFontMgr = NULL; itsText = NULL; itsStyles = NULL; itsRecalcRange = NULL; itsRedrawRange = NULL; itsTokenStartList = NULL; }
void GFGLink::ParseInterface ( GFGMemberFunction* fn, const JIndex line ) { std::ifstream is(itsCurrentFile); if (!is.good()) { return; } // skip to the function's line JString str; for (JIndex i = 1; i < line; i++) { str = JReadLine(is); } JSize p1 = JTellg(is); is >> std::ws; str = JReadUntilws(is); if (str != "virtual") { return; } is >> std::ws; // return type str = JReadUntilws(is); if (str == "const") { str += " " + JReadUntilws(is); } fn->SetReturnType(str); is >> std::ws; // this should be the function name str = JReadUntil(is, '('); str.TrimWhitespace(); if (str != fn->GetFnName()) { return; } // get arguments JCharacter delim = ','; while (delim == ',') { JBoolean ok = JReadUntil(is, 2, ",)", &str, &delim); if (!ok) { return; } JIndex findex; if (str.LocateSubstring("//", &findex)) { JIndex eindex; if (str.LocateSubstring("\n", &eindex) && eindex >= findex) { str.RemoveSubstring(findex, eindex); } } str.TrimWhitespace(); if (!str.IsEmpty()) { fn->AddArg(str); } } is >> std::ws; // is it const; str = JReadUntil(is, ';'); if (str.Contains("const")) { fn->ShouldBeConst(kJTrue); } JSize p2 = JTellg(is); JSeekg(is, p1); str = JRead(is, p2 - p1); fn->SetInterface(str); }
void GMMIMEParser::ParseMixed ( std::istream& input, const GMIMEHeader& header ) { JString boundary = "-" + header.GetBoundary(); JString endBoundary = boundary + "--"; // slurp the initial empty part JIndex bstart, bend; ReadUntilBoundary(input, boundary, &bstart, &bend); JIndex current = JTellg(input); JString data; data.Read(input, bend - current + 1); while (1) { GMIMEHeader child; ParseMIMEHeader(input, &child); // when the following function returns true, it has found the // last boundary data.Clear(); JBoolean end; if (child.GetEncoding() == kBase64Encoding) { JString filename = child.GetFileName(); if (filename.IsEmpty()) { JCreateTempFile(itsAttachDir, NULL, &filename); } else { filename = JCombinePathAndName(itsAttachDir, filename); } if (!filename.IsEmpty()) { AdjustAttachmentName(child, &filename); std::ofstream os(filename); JDecodeBase64(input, os); end = ReadUntilBoundary(input, boundary, &bstart, &bend); // JBoolean found; // JString line; // while (line.IsEmpty() && !input.fail()) // { // line = JReadLine(input, &found); // } // JString endBoundary = boundary + "--"; // if (line.Contains(endBoundary)) // { // end = kJTrue; // } } } else if ((child.GetType() != kMultipartType) && (!child.GetFileName().IsEmpty())) { JIndex startI = JTellg(input); JIndex findex = startI; if (itsData->LocateNextSubstring(boundary, &findex)) { const JCharacter* c = itsData->GetCString() + startI; JString filename = child.GetFileName(); if (filename.IsEmpty()) { JCreateTempFile(itsAttachDir, NULL, &filename); } else { filename = JCombinePathAndName(itsAttachDir, filename); } if (!filename.IsEmpty()) { AdjustAttachmentName(child, &filename); std::ofstream os(filename); JSeekg(input, findex - 1); if (child.GetEncoding() == kQPEncoding) { JString data = itsData->GetSubstring(startI, findex - 3); ParseQuotedPrintable(&data); data.Print(os); } else { os.write(c, findex - startI - 3); } JBoolean found; JString line = JReadLine(input, &found); if (line.BeginsWith(endBoundary)) { end = kJTrue; } } } } else { end = ReadUntilBoundary(input, boundary, &bstart, &bend); ParseByType(input, child, bstart - 1); current = JTellg(input); data.Read(input, bend - current + 1); } if (end) { break; } } if (itsTextInfo != NULL) { itsTextInfo->ForceUpdate(); } if (itsAttachInfo != NULL) { itsAttachInfo->ForceUpdate(); } }