void JucerDocument::extractCustomPaintSnippetsFromCppFile (const String& cppContent) { StringArray customPaintSnippets; auto lines = StringArray::fromLines (cppContent); int last = 0; while (last >= 0) { const int start = indexOfLineStartingWith (lines, "//[UserPaintCustomArguments]", last); if (start < 0) break; const int end = indexOfLineStartingWith (lines, "//[/UserPaintCustomArguments]", start); if (end < 0) break; last = end + 1; String result; for (int i = start + 1; i < end; ++i) result << lines [i] << newLine; customPaintSnippets.add (CodeHelpers::unindent (result, 4)); } applyCustomPaintSnippets (customPaintSnippets); }
//============================================================================== static bool getUserSection (const StringArray& lines, const String& tag, StringArray& resultLines) { const int start = indexOfLineStartingWith (lines, "//[" + tag + "]", 0); if (start < 0) return false; const int end = indexOfLineStartingWith (lines, "//[/" + tag + "]", start + 1); for (int i = start + 1; i < end; ++i) resultLines.add (lines [i]); return true; }
XmlElement* JucerDocument::pullMetaDataFromCppFile (const String& cpp) { auto lines = StringArray::fromLines (cpp); const int startLine = indexOfLineStartingWith (lines, "BEGIN_JUCER_METADATA", 0); if (startLine > 0) { const int endLine = indexOfLineStartingWith (lines, "END_JUCER_METADATA", startLine); if (endLine > startLine) return XmlDocument::parse (lines.joinIntoString ("\n", startLine + 1, endLine - startLine - 1)); } return nullptr; }
static void copyAcrossUserSections (String& dest, const String& src) { StringArray srcLines, dstLines; srcLines.addLines (src); dstLines.addLines (dest); for (int i = 0; i < dstLines.size(); ++i) { if (dstLines[i].trimStart().startsWith (T("//["))) { String tag (dstLines[i].trimStart().substring (3)); tag = tag.upToFirstOccurrenceOf (T("]"), false, false); jassert (! tag.startsWithChar (T('/'))); if (! tag.startsWithChar (T('/'))) { const int endLine = indexOfLineStartingWith (dstLines, T("//[/") + tag + T("]"), i + 1); if (endLine > i) { StringArray sourceLines; if (getUserSection (srcLines, tag, sourceLines)) { int j; for (j = endLine - i; --j > 0;) dstLines.remove (i + 1); for (j = 0; j < sourceLines.size(); ++j) dstLines.insert (++i, sourceLines [j].trimEnd()); ++i; } else { i = endLine; } } } } dstLines.set (i, dstLines[i].trimEnd()); } dest = dstLines.joinIntoString (T("\n")) + T("\n"); }