void CBTCLStyler::StyleEmbeddedVariables ( const Token& token ) { emptyVariablePattern.SetSingleLine(); variablePattern.SetSingleLine(); const JString& text = GetText(); JFontStyle varStyle = GetTypeStyle(token.type - kWhitespace); varStyle.underlineCount++; if (varStyle == GetTypeStyle(kVariable - kWhitespace)) { varStyle.underlineCount++; } JFontStyle errStyle = GetTypeStyle(kError - kWhitespace); errStyle.underlineCount++; if (errStyle == GetTypeStyle(kVariable - kWhitespace)) { errStyle.underlineCount++; } JIndexRange r = token.range, r1, r2; while (!r.IsEmpty()) { const JCharacter c = text.GetCharacter(r.first); if (c == '\\') { r.first++; } else if (c == '$') { r1 = r - (r.first-1); if (emptyVariablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; AdjustStyle(r2, errStyle); r.first = r2.last; } else if (variablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; AdjustStyle(r2, varStyle); r.first = r2.last; } } r.first++; } }
JFontStyle CBHTMLStyler::GetTagStyle ( const JIndexRange& tokenRange, const JIndex typeIndex ) { const JString& text = GetText(); JFontStyle style; JArray<JIndexRange> matchList; if (tagNamePattern.MatchWithin(text, tokenRange, &matchList)) { itsLatestTagName = text.GetSubstring(matchList.GetElement(2)); itsLatestTagName.ToLower(); JString openTag; if (itsLatestTagName.GetFirstCharacter() == '/' && itsLatestTagName.GetLength() > 1) { openTag = itsLatestTagName.GetSubstring(2, itsLatestTagName.GetLength()); } JBoolean found = GetWordStyle(itsLatestTagName, &style); if (!found && !openTag.IsEmpty()) { found = GetWordStyle(openTag, &style); } if (!found) { found = GetXMLStyle(itsLatestTagName, &style); } if (!found && !openTag.IsEmpty()) { found = GetXMLStyle(openTag, &style); } if (!found) { style = GetTypeStyle(typeIndex); } } else if (text.GetCharacter(tokenRange.first) == '<') { itsLatestTagName.Clear(); style = GetTypeStyle(typeIndex); } else { style = GetStyle(typeIndex, itsLatestTagName); } return style; }
JBoolean CBHTMLScanner::IsScript ( JString* language ) const { scriptTagPattern1.SetCaseSensitive(kJFalse); scriptTagPattern2.SetCaseSensitive(kJFalse); scriptTagPattern3.SetCaseSensitive(kJFalse); language->Clear(); const JString& text = GetScannedText(); const JCharacter* s = text.GetCString() + itsCurrentRange.first - 1; JIndexRange r = itsCurrentRange - (itsCurrentRange.first - 1); JArray<JIndexRange> matchList; if (scriptTagPattern1.MatchWithin(s, r, &matchList)) { *language = text.GetSubstring(matchList.GetElement(2) + (itsCurrentRange.first - 1)); return kJTrue; } else if (scriptTagPattern2.MatchWithin(s, r, &matchList)) { *language = text.GetSubstring(matchList.GetElement(2) + (itsCurrentRange.first - 1)); return kJTrue; } else if (scriptTagPattern3.MatchWithin(s, r)) { *language = "JavaScript"; return kJTrue; } else { return kJFalse; } }
void CBHTMLStyler::StyleEmbeddedVariables ( const Token& token ) { emptyVariablePattern.SetSingleLine(); variablePattern.SetSingleLine(); const JString& text = GetText(); JFontStyle varStyle = GetTypeStyle(token.type - kWhitespace); varStyle.underlineCount++; if (varStyle == GetTypeStyle(kPHPVariable - kWhitespace)) { varStyle.underlineCount++; } JFontStyle errStyle = GetTypeStyle(kError - kWhitespace); errStyle.underlineCount++; if (errStyle == GetTypeStyle(kPHPVariable - kWhitespace)) { errStyle.underlineCount++; } JIndexRange r = token.range, r1, r2; while (!r.IsEmpty()) { const JCharacter c = text.GetCharacter(r.first); if (c == '\\') { r.first++; } else if (c == '$') { r1 = r - (r.first-1); if (emptyVariablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; const JCharacter c1 = text.GetCharacter(r2.last); if (c1 != '}' && c1 != ']') { r2.last--; } AdjustStyle(r2, errStyle); r.first = r2.last; } else if (variablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; if (r2.first > 1 && text.GetCharacter(r2.first-1) == '{') { r2.first--; } AdjustStyle(r2, varStyle); r.first = r2.last; } } else if (c == '{' && r.first < r.last - 1 && text.GetCharacter(r.first+1) == '$' && text.GetCharacter(r.first+2) == '}') { r1.SetFirstAndLength(r.first, 3); AdjustStyle(r1, errStyle); r.first = r1.last; } r.first++; } }
JBoolean JGetCurrentSVNRevision ( const JCharacter* fullName, JString* rev ) { JString path, name, entriesFileName, data, pattern; JSplitPathAndName(fullName, &path, &name); entriesFileName = JCombinePathAndName(path, kSubversionDirName); entriesFileName = JCombinePathAndName(entriesFileName, kSubversionFileName); JReadFile(entriesFileName, &data); if (data.BeginsWith("<?xml")) { pattern = "<entry[^>]+name=\"" + JRegex::BackslashForLiteral(name) + "\"(.|\n)*?>"; JRegex r(pattern); JIndexRange range; JArray<JIndexRange> matchList; if (r.Match(data, &range) && svn4RevisionPattern.MatchWithin(data, range, &matchList)) { *rev = data.GetSubstring(matchList.GetElement(2)); return kJTrue; } } else { std::istrstream input(data, data.GetLength()); const JString version = JReadLine(input); if (version == "8" || version == "9" || version == "10") { pattern = "\n\f\n" + name + "\n"; JBoolean found; JIgnoreUntil(input, pattern, &found); if (found) { const JString data2 = JReadUntil(input, '\f'); std::istrstream input2(data2, data2.GetLength()); JIgnoreLine(input2); // file JIgnoreLine(input2); // ??? JIgnoreLine(input2); // ??? JIgnoreLine(input2); // ??? JIgnoreLine(input2); // ??? JIgnoreLine(input2); // timestamp JIgnoreLine(input2); // hash JIgnoreLine(input2); // timestamp *rev = JReadLine(input2); if (input2.good()) { return kJTrue; } } } } rev->Clear(); return kJFalse; }
JBoolean JGetVCSRepositoryPath ( const JCharacter* origPath, JString* repoPath ) { JString path = origPath, name; if (JFileExists(origPath) || !JDirectoryExists(origPath)) // broken link { JSplitPathAndName(origPath, &path, &name); } const JVCSType type = JGetVCSType(path); JBoolean found = kJFalse; if (type == kJCVSType) { const JString cvsPath = JCombinePathAndName(path, kCVSDirName); JString fullName = JCombinePathAndName(cvsPath, "Root"); JReadFile(fullName, repoPath); fullName = JCombinePathAndName(cvsPath, "Repository"); JString repo; JReadFile(fullName, &repo); if (!repoPath->IsEmpty() && !repo.IsEmpty()) { *repoPath = JCombinePathAndName(*repoPath, repo); found = kJTrue; } } else if (type == kJSVNType) { JString entriesFileName, data; entriesFileName = JCombinePathAndName(path, kSubversionDirName); entriesFileName = JCombinePathAndName(entriesFileName, kSubversionFileName); JReadFile(entriesFileName, &data); if (data.BeginsWith("<?xml")) { JIndexRange range; JArray<JIndexRange> matchList; if (svn4RepositoryPattern1.Match(data, &range) && svn4RepositoryPattern2.MatchWithin(data, range, &matchList)) { *repoPath = data.GetSubstring(matchList.GetElement(2)); found = kJTrue; } } else { std::istrstream input(data, data.GetLength()); const JString version = JReadLine(input); if (version == "8" || version == "9" || version == "10") { JIgnoreLine(input); // ??? JIgnoreLine(input); // dir JIgnoreLine(input); // latest update version *repoPath = JReadLine(input); found = JI2B(input.good()); } } } if (found) { if (!name.IsEmpty()) { *repoPath = JCombinePathAndName(*repoPath, name); } return kJTrue; } else { repoPath->Clear(); return kJFalse; } }