bool getIndentForCurrentBlock (CodeDocument::Position pos, const String& tab, String& blockIndent, String& lastLineIndent) { int braceCount = 0; bool indentFound = false; while (pos.getLineNumber() > 0) { pos = pos.movedByLines (-1); const String line (pos.getLineText()); const String trimmedLine (line.trimStart()); braceCount += getBraceCount (trimmedLine.getCharPointer()); if (braceCount > 0) { blockIndent = getLeadingWhitespace (line); if (! indentFound) lastLineIndent = blockIndent + tab; return true; } if ((! indentFound) && trimmedLine.isNotEmpty()) { indentFound = true; lastLineIndent = getLeadingWhitespace (line); } } return false; }
int StringArray::addLines (const String& sourceText) { int numLines = 0; String::CharPointerType text (sourceText.getCharPointer()); bool finished = text.isEmpty(); while (! finished) { for (String::CharPointerType startOfLine (text);;) { const String::CharPointerType endOfLine (text); switch (text.getAndAdvance()) { case 0: finished = true; break; case '\n': break; case '\r': if (*text == '\n') ++text; break; default: continue; } strings.add (String (startOfLine, endOfLine)); ++numLines; break; } } return numLines; }
const Result CtrlrWindows::sendKeyPressEvent (const KeyPress &event, const String &targetWindowName) { HWND firstwindow = FindWindowEx(NULL, NULL, NULL, NULL); HWND window = firstwindow; TCHAR windowtext[MAX_PATH]; // INPUT input; if (targetWindowName != String::empty) { while(1) { GetWindowText(window, windowtext, MAX_PATH); if (strstr(windowtext, targetWindowName.getCharPointer()) != NULL) break; window = FindWindowEx(NULL, window, NULL, NULL); if (window == NULL || window == firstwindow) return (Result::fail("Can't find target window: " + targetWindowName)); } } SetForegroundWindow(window); sendKey(event); return (Result::ok()); }
String stringLiteral (const String& text, int maxLineLength) { if (text.isEmpty()) return "String::empty"; StringArray lines; { String::CharPointerType t (text.getCharPointer()); bool finished = t.isEmpty(); while (! finished) { for (String::CharPointerType startOfLine (t);;) { switch (t.getAndAdvance()) { case 0: finished = true; break; case '\n': break; case '\r': if (*t == '\n') ++t; break; default: continue; } lines.add (String (startOfLine, t)); break; } } } if (maxLineLength > 0) { for (int i = 0; i < lines.size(); ++i) { String& line = lines.getReference (i); if (line.length() > maxLineLength) { const String start (line.substring (0, maxLineLength)); const String end (line.substring (maxLineLength)); line = start; lines.insert (i + 1, end); } } } for (int i = 0; i < lines.size(); ++i) lines.getReference(i) = CppTokeniserFunctions::addEscapeChars (lines.getReference(i)); lines.removeEmptyStrings(); for (int i = 0; i < lines.size(); ++i) lines.getReference(i) = "\"" + lines.getReference(i) + "\""; String result (lines.joinIntoString (newLine)); if (! CharPointer_ASCII::isValidString (text.toUTF8(), std::numeric_limits<int>::max())) result = "CharPointer_UTF8 (" + result + ")"; return result; }
//============================================================================== void SystemClipboard::copyTextToClipboard (const String& text) { if (OpenClipboard (0) != 0) { if (EmptyClipboard() != 0) { const int bytesNeeded = CharPointer_UTF16::getBytesRequiredFor (text.getCharPointer()) + 4; if (bytesNeeded > 0) { HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT, bytesNeeded + sizeof (WCHAR)); if (bufH != 0) { WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH)); text.copyToUTF16 (data, bytesNeeded); GlobalUnlock (bufH); SetClipboardData (CF_UNICODETEXT, bufH); } } } CloseClipboard(); } }
RelativePoint::RelativePoint (const String& s) { String::CharPointerType text (s.getCharPointer()); x = RelativeCoordinate (Expression::parse (text)); RelativePointHelpers::skipComma (text); y = RelativeCoordinate (Expression::parse (text)); }
void LivePropertyEditorBase::findOriginalValueInCode() { CodeDocument::Position pos (document, value.sourceLine, 0); String line (pos.getLineText()); String::CharPointerType p (line.getCharPointer()); p = CharacterFunctions::find (p, CharPointer_ASCII ("JUCE_LIVE_CONSTANT")); if (p.isEmpty()) { // Not sure how this would happen - some kind of mix-up between source code and line numbers.. jassertfalse; return; } p += (int) (sizeof ("JUCE_LIVE_CONSTANT") - 1); p = p.findEndOfWhitespace(); if (! CharacterFunctions::find (p, CharPointer_ASCII ("JUCE_LIVE_CONSTANT")).isEmpty()) { // Aargh! You've added two JUCE_LIVE_CONSTANT macros on the same line! // They're identified by their line number, so you must make sure each // one goes on a separate line! jassertfalse; } if (p.getAndAdvance() == '(') { String::CharPointerType start (p), end (p); int depth = 1; while (! end.isEmpty()) { const juce_wchar c = end.getAndAdvance(); if (c == '(') ++depth; if (c == ')') --depth; if (depth == 0) { --end; break; } } if (end > start) { valueStart = CodeDocument::Position (document, value.sourceLine, (int) (start - line.getCharPointer())); valueEnd = CodeDocument::Position (document, value.sourceLine, (int) (end - line.getCharPointer())); valueStart.setPositionMaintained (true); valueEnd.setPositionMaintained (true); wasHex = String (start, end).containsIgnoreCase ("0x"); } } }
void OutputStream::writeText (const String& text, const bool asUTF16, const bool writeUTF16ByteOrderMark) { if (asUTF16) { if (writeUTF16ByteOrderMark) write ("\x0ff\x0fe", 2); String::CharPointerType src (text.getCharPointer()); bool lastCharWasReturn = false; for (;;) { const juce_wchar c = src.getAndAdvance(); if (c == 0) break; if (c == '\n' && ! lastCharWasReturn) writeShort ((short) '\r'); lastCharWasReturn = (c == L'\r'); writeShort ((short) c); } } else { const char* src = text.toUTF8(); const char* t = src; for (;;) { if (*t == '\n') { if (t > src) write (src, (int) (t - src)); write ("\r\n", 2); src = t + 1; } else if (*t == '\r') { if (t[1] == '\n') ++t; } else if (*t == 0) { if (t > src) write (src, (int) (t - src)); break; } ++t; } } }
bool RHD2000Thread::openBoard(String pathToLibrary) { int return_code = evalBoard->open(pathToLibrary.getCharPointer()); if (return_code == 1) { deviceFound = true; } else if (return_code == -1) // dynamic library not found { bool response = AlertWindow::showOkCancelBox (AlertWindow::NoIcon, "Opal Kelly library not found.", "The Opal Kelly library file was not found in the directory of the executable. Would you like to browse for it?", "Yes", "No", 0, 0); if (response) { // browse for file FileChooser fc("Select the library file...", File::getCurrentWorkingDirectory(), okLIB_EXTENSION, true); if (fc.browseForFileToOpen()) { File currentFile = fc.getResult(); libraryFilePath = currentFile.getFullPathName(); openBoard(libraryFilePath); // call recursively } else { //sendActionMessage("No configuration selected."); deviceFound = false; } } else { deviceFound = false; } } else if (return_code == -2) // board could not be opened { bool response = AlertWindow::showOkCancelBox (AlertWindow::NoIcon, "Acquisition board not found.", "An acquisition board could not be found. Please connect one now.", "OK", "Cancel", 0, 0); if (response) { openBoard(libraryFilePath.getCharPointer()); // call recursively } else { deviceFound = false; } } return deviceFound; }
String simplifyPath (const String& path) { #if JUCE_WINDOWS if (path.contains ("\\..\\") || path.contains ("/../")) #else if (path.contains ("/../")) #endif return simplifyPath (path.getCharPointer()); return path; }
RelativeRectangle::RelativeRectangle (const String& s) { String::CharPointerType text (s.getCharPointer()); left = RelativeCoordinate (Expression::parse (text)); RelativeRectangleHelpers::skipComma (text); top = RelativeCoordinate (Expression::parse (text)); RelativeRectangleHelpers::skipComma (text); right = RelativeCoordinate (Expression::parse (text)); RelativeRectangleHelpers::skipComma (text); bottom = RelativeCoordinate (Expression::parse (text)); }
static void createLines (Array <CodeDocumentLine*>& newLines, const String& text) { String::CharPointerType t (text.getCharPointer()); int charNumInFile = 0; bool finished = false; while (! (finished || t.isEmpty())) { String::CharPointerType startOfLine (t); int startOfLineInFile = charNumInFile; int lineLength = 0; int numNewLineChars = 0; for (;;) { const juce_wchar c = t.getAndAdvance(); if (c == 0) { finished = true; break; } ++charNumInFile; ++lineLength; if (c == '\r') { ++numNewLineChars; if (*t == '\n') { ++t; ++charNumInFile; ++lineLength; ++numNewLineChars; } break; } if (c == '\n') { ++numNewLineChars; break; } } newLines.add (new CodeDocumentLine (startOfLine, lineLength, numNewLineChars, startOfLineInFile)); } jassert (charNumInFile == text.length()); }
void SimpleTypeLayout::appendText (const AttributedString& text, const Range<int>& stringRange, const Font& font, const Colour& colour) { String stringText = text.getText().substring(stringRange.getStart(), stringRange.getEnd()); String::CharPointerType t (stringText.getCharPointer()); String currentString; int lastCharType = 0; for (;;) { const juce_wchar c = t.getAndAdvance(); if (c == 0) break; int charType; if (c == '\r' || c == '\n') { charType = 0; } else if (CharacterFunctions::isWhitespace (c)) { charType = 2; } else { charType = 1; } if (charType == 0 || charType != lastCharType) { if (currentString.isNotEmpty()) { tokens.add (new Token (currentString, font, colour, lastCharType == 2 || lastCharType == 0)); } currentString = String::charToString (c); if (c == '\r' && *t == '\n') currentString += t.getAndAdvance(); } else { currentString += c; } lastCharType = charType; } if (currentString.isNotEmpty()) tokens.add (new Token (currentString, font, colour, lastCharType == 2)); }
//============================================================================== String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const { const int last = (numberToJoin < 0) ? size() : jmin (size(), start + numberToJoin); if (start < 0) start = 0; if (start >= last) return String::empty; if (start == last - 1) return strings.getReference (start); const size_t separatorBytes = separator.getCharPointer().sizeInBytes() - sizeof (String::CharPointerType::CharType); size_t bytesNeeded = separatorBytes * (last - start - 1); for (int i = start; i < last; ++i) bytesNeeded += strings.getReference(i).getCharPointer().sizeInBytes() - sizeof (String::CharPointerType::CharType); String result; result.preallocateBytes (bytesNeeded); String::CharPointerType dest (result.getCharPointer()); while (start < last) { const String& s = strings.getReference (start); if (! s.isEmpty()) dest.writeAll (s.getCharPointer()); if (++start < last && separatorBytes > 0) dest.writeAll (separator.getCharPointer()); } dest.writeNull(); return result; }
int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters) { int num = 0; String::CharPointerType t (text.getCharPointer()); if (! t.isEmpty()) { for (;;) { String::CharPointerType tokenEnd (CharacterFunctions::findEndOfToken (t, breakCharacters.getCharPointer(), quoteCharacters.getCharPointer())); add (String (t, tokenEnd)); ++num; if (tokenEnd.isEmpty()) break; t = ++tokenEnd; } } return num; }
String getDriveFromPath (String path) { if (path.isNotEmpty() && path[1] == ':' && path[2] == 0) path << '\\'; const size_t numBytes = CharPointer_UTF16::getBytesRequiredFor (path.getCharPointer()) + 4; HeapBlock<WCHAR> pathCopy; pathCopy.calloc (numBytes, 1); path.copyToUTF16 (pathCopy, numBytes); if (PathStripToRoot (pathCopy)) path = static_cast <const WCHAR*> (pathCopy); return path; }
XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement) { String textToParse (originalText); if (textToParse.isEmpty() && inputSource != nullptr) { ScopedPointer <InputStream> in (inputSource->createInputStream()); if (in != nullptr) { MemoryOutputStream data; data.writeFromInputStream (*in, onlyReadOuterDocumentElement ? 8192 : -1); textToParse = data.toString(); if (! onlyReadOuterDocumentElement) originalText = textToParse; } } input = textToParse.getCharPointer(); lastError = String::empty; errorOccurred = false; outOfData = false; needToLoadDTD = true; if (textToParse.isEmpty()) { lastError = "not enough input"; } else { skipHeader(); if (input.getAddress() != nullptr) { ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement)); if (! errorOccurred) return result.release(); } else { lastError = "incorrect xml header"; } } return nullptr; }
static int compareStrings (const StartEndString& string1, const String& string2) noexcept { String::CharPointerType s1 (string1.start), s2 (string2.getCharPointer()); for (;;) { const int c1 = s1 < string1.end ? (int) s1.getAndAdvance() : 0; const int c2 = (int) s2.getAndAdvance(); const int diff = c1 - c2; if (diff != 0) return diff < 0 ? -1 : 1; if (c1 == 0) break; } return 0; }
//------------------------------------------------------------------------------- void GuidoViewer::setFile (String file) { if (file.length()) { GuidoErrCode err = setGMNFile(file.getCharPointer()); if (err == guidoNoErr) fWindow->setName (file); else { String msg = GuidoGetErrorString (err); if (err == guidoErrParse) { msg += " line "; msg += GuidoGetParseErrorLine(); } AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Error", msg, "OK", this); } } }
MD5::MD5 (const String& text) { ProcessContext context; String::CharPointerType t (text.getCharPointer()); while (! t.isEmpty()) { // force the string into integer-sized unicode characters, to try to make it // get the same results on all platforms + compilers. uint32 unicodeChar = ByteOrder::swapIfBigEndian ((uint32) t.getAndAdvance()); context.processBlock (&unicodeChar, sizeof (unicodeChar)); } context.finish (result); }
int findFirstNonWhitespaceChar (const String& line) noexcept { String::CharPointerType t (line.getCharPointer()); int i = 0; while (! t.isEmpty()) { if (! t.isWhitespace()) return i; ++t; ++i; } return 0; }
int indexToColumn (int index, const String& line, int spacesPerTab) const noexcept { jassert (index <= line.length()); String::CharPointerType t (line.getCharPointer()); int col = 0; for (int i = 0; i < index; ++i) { if (t.getAndAdvance() != '\t') ++col; else col += spacesPerTab - (col % spacesPerTab); } return col; }
//============================================================================== StringPairArray parsePreprocessorDefs (const String& text) { StringPairArray result; String::CharPointerType s (text.getCharPointer()); while (! s.isEmpty()) { String token, value; s = s.findEndOfWhitespace(); while ((! s.isEmpty()) && *s != '=' && ! s.isWhitespace()) token << s.getAndAdvance(); s = s.findEndOfWhitespace(); if (*s == '=') { ++s; while ((! s.isEmpty()) && *s == ' ') ++s; while ((! s.isEmpty()) && ! s.isWhitespace()) { if (*s == ',') { ++s; break; } if (*s == '\\' && (s[1] == ' ' || s[1] == ',')) ++s; value << s.getAndAdvance(); } } if (token.isNotEmpty()) result.set (token, value); } return result; }
void GlyphArrangement::addCurtailedLineOfText (const Font& font, const String& text, const float xOffset, const float yOffset, const float maxWidthPixels, const bool useEllipsis) { if (text.isNotEmpty()) { Array <int> newGlyphs; Array <float> xOffsets; font.getGlyphPositions (text, newGlyphs, xOffsets); const int textLen = newGlyphs.size(); glyphs.ensureStorageAllocated (glyphs.size() + textLen); String::CharPointerType t (text.getCharPointer()); for (int i = 0; i < textLen; ++i) { const float thisX = xOffsets.getUnchecked (i); const float nextX = xOffsets.getUnchecked (i + 1); if (nextX > maxWidthPixels + 1.0f) { // curtail the string if it's too wide.. if (useEllipsis && textLen > 3 && glyphs.size() >= 3) insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size()); break; } else { const bool isWhitespace = t.isWhitespace(); glyphs.add (new PositionedGlyph (font, t.getAndAdvance(), newGlyphs.getUnchecked(i), xOffset + thisX, yOffset, nextX - thisX, isWhitespace)); } } } }
int StringArray::addLines (const String& sourceText) { int numLines = 0; String::CharPointerType text (sourceText.getCharPointer()); bool finished = text.isEmpty(); while (! finished) { String::CharPointerType startOfLine (text); size_t numChars = 0; for (;;) { const juce_wchar c = text.getAndAdvance(); if (c == 0) { finished = true; break; } if (c == '\n') break; if (c == '\r') { if (*text == '\n') ++text; break; } ++numChars; } add (String (startOfLine, numChars)); ++numLines; } return numLines; }
void getGlyphPositions (const String& text, Array<int>& glyphs, Array<float>& xOffsets) override { JNIEnv* env = getEnv(); const int numChars = text.length(); jfloatArray widths = env->NewFloatArray (numChars); const int numDone = paint.callIntMethod (Paint.getTextWidths, javaString (text).get(), widths); HeapBlock<jfloat> localWidths (numDone); env->GetFloatArrayRegion (widths, 0, numDone, localWidths); env->DeleteLocalRef (widths); String::CharPointerType s (text.getCharPointer()); xOffsets.add (0); float x = 0; for (int i = 0; i < numDone; ++i) { glyphs.add ((int) s.getAndAdvance()); x += localWidths[i]; xOffsets.add (x * referenceFontToUnits); } }
//============================================================================== void parsePathString (Path& path, const String& pathString) const { String::CharPointerType d (pathString.getCharPointer().findEndOfWhitespace()); Point<float> subpathStart, last, last2, p1, p2, p3; juce_wchar lastCommandChar = 0; bool isRelative = true; bool carryOn = true; const CharPointer_ASCII validCommandChars ("MmLlHhVvCcSsQqTtAaZz"); while (! d.isEmpty()) { if (validCommandChars.indexOf (*d) >= 0) { lastCommandChar = d.getAndAdvance(); isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z'); } switch (lastCommandChar) { case 'M': case 'm': case 'L': case 'l': if (parseCoordsOrSkip (d, p1, false)) { if (isRelative) p1 += last; if (lastCommandChar == 'M' || lastCommandChar == 'm') { subpathStart = p1; path.startNewSubPath (p1); lastCommandChar = 'l'; } else path.lineTo (p1); last2 = last; last = p1; } break; case 'H': case 'h': if (parseCoord (d, p1.x, false, true)) { if (isRelative) p1.x += last.x; path.lineTo (p1.x, last.y); last2.x = last.x; last.x = p1.x; } else { ++d; } break; case 'V': case 'v': if (parseCoord (d, p1.y, false, false)) { if (isRelative) p1.y += last.y; path.lineTo (last.x, p1.y); last2.y = last.y; last.y = p1.y; } else { ++d; } break; case 'C': case 'c': if (parseCoordsOrSkip (d, p1, false) && parseCoordsOrSkip (d, p2, false) && parseCoordsOrSkip (d, p3, false)) { if (isRelative) { p1 += last; p2 += last; p3 += last; } path.cubicTo (p1, p2, p3); last2 = p2; last = p3; } break; case 'S': case 's': if (parseCoordsOrSkip (d, p1, false) && parseCoordsOrSkip (d, p3, false)) { if (isRelative) { p1 += last; p3 += last; } p2 = last + (last - last2); path.cubicTo (p2, p1, p3); last2 = p1; last = p3; } break; case 'Q': case 'q': if (parseCoordsOrSkip (d, p1, false) && parseCoordsOrSkip (d, p2, false)) { if (isRelative) { p1 += last; p2 += last; } path.quadraticTo (p1, p2); last2 = p1; last = p2; } break; case 'T': case 't': if (parseCoordsOrSkip (d, p1, false)) { if (isRelative) p1 += last; p2 = last + (last - last2); path.quadraticTo (p2, p1); last2 = p2; last = p1; } break; case 'A': case 'a': if (parseCoordsOrSkip (d, p1, false)) { String num; if (parseNextNumber (d, num, false)) { const float angle = num.getFloatValue() * (180.0f / float_Pi); if (parseNextNumber (d, num, false)) { const bool largeArc = num.getIntValue() != 0; if (parseNextNumber (d, num, false)) { const bool sweep = num.getIntValue() != 0; if (parseCoordsOrSkip (d, p2, false)) { if (isRelative) p2 += last; if (last != p2) { double centreX, centreY, startAngle, deltaAngle; double rx = p1.x, ry = p1.y; endpointToCentreParameters (last.x, last.y, p2.x, p2.y, angle, largeArc, sweep, rx, ry, centreX, centreY, startAngle, deltaAngle); path.addCentredArc ((float) centreX, (float) centreY, (float) rx, (float) ry, angle, (float) startAngle, (float) (startAngle + deltaAngle), false); path.lineTo (p2); } last2 = last; last = p2; } } } } } break; case 'Z': case 'z': path.closeSubPath(); last = last2 = subpathStart; d = d.findEndOfWhitespace(); lastCommandChar = 'M'; break; default: carryOn = false; break; } if (! carryOn) break; } // paths that finish back at their start position often seem to be // left without a 'z', so need to be closed explicitly.. if (path.getCurrentPosition() == subpathStart) path.closeSubPath(); }
StringRegion (const String& s) noexcept : text (s.getCharPointer()), start (0), length (s.length()) {}
//============================================================================== Drawable* parseSVGElement (const XmlPath& xml) { if (! xml->hasTagNameIgnoringNamespace ("svg")) return nullptr; DrawableComposite* const drawable = new DrawableComposite(); setDrawableID (*drawable, xml); SVGState newState (*this); if (xml->hasAttribute ("transform")) newState.addTransform (xml); newState.elementX = getCoordLength (xml->getStringAttribute ("x", String (newState.elementX)), viewBoxW); newState.elementY = getCoordLength (xml->getStringAttribute ("y", String (newState.elementY)), viewBoxH); newState.width = getCoordLength (xml->getStringAttribute ("width", String (newState.width)), viewBoxW); newState.height = getCoordLength (xml->getStringAttribute ("height", String (newState.height)), viewBoxH); if (newState.width <= 0) newState.width = 100; if (newState.height <= 0) newState.height = 100; Point<float> viewboxXY; if (xml->hasAttribute ("viewBox")) { const String viewBoxAtt (xml->getStringAttribute ("viewBox")); String::CharPointerType viewParams (viewBoxAtt.getCharPointer()); Point<float> vwh; if (parseCoords (viewParams, viewboxXY, true) && parseCoords (viewParams, vwh, true) && vwh.x > 0 && vwh.y > 0) { newState.viewBoxW = vwh.x; newState.viewBoxH = vwh.y; int placementFlags = 0; const String aspect (xml->getStringAttribute ("preserveAspectRatio")); if (aspect.containsIgnoreCase ("none")) { placementFlags = RectanglePlacement::stretchToFit; } else { if (aspect.containsIgnoreCase ("slice")) placementFlags |= RectanglePlacement::fillDestination; if (aspect.containsIgnoreCase ("xMin")) placementFlags |= RectanglePlacement::xLeft; else if (aspect.containsIgnoreCase ("xMax")) placementFlags |= RectanglePlacement::xRight; else placementFlags |= RectanglePlacement::xMid; if (aspect.containsIgnoreCase ("yMin")) placementFlags |= RectanglePlacement::yTop; else if (aspect.containsIgnoreCase ("yMax")) placementFlags |= RectanglePlacement::yBottom; else placementFlags |= RectanglePlacement::yMid; } newState.transform = RectanglePlacement (placementFlags) .getTransformToFit (Rectangle<float> (viewboxXY.x, viewboxXY.y, vwh.x, vwh.y), Rectangle<float> (newState.width, newState.height)) .followedBy (newState.transform); } } else { if (viewBoxW == 0) newState.viewBoxW = newState.width; if (viewBoxH == 0) newState.viewBoxH = newState.height; } newState.parseSubElements (xml, *drawable); drawable->setContentArea (RelativeRectangle (RelativeCoordinate (viewboxXY.x), RelativeCoordinate (viewboxXY.x + newState.viewBoxW), RelativeCoordinate (viewboxXY.y), RelativeCoordinate (viewboxXY.y + newState.viewBoxH))); drawable->resetBoundingBoxToContentArea(); return drawable; }
void BinaryResources::loadFromCpp (const File& cppFileLocation, const String& cppFile) { StringArray cpp; cpp.addLines (cppFile); clear(); for (int i = 0; i < cpp.size(); ++i) { if (cpp[i].contains ("JUCER_RESOURCE:")) { StringArray tokens; tokens.addTokens (cpp[i].fromFirstOccurrenceOf (":", false, false), ",", "\"'"); tokens.trim(); tokens.removeEmptyStrings(); const String resourceName (tokens[0]); const int resourceSize = tokens[1].getIntValue(); const String originalFileName (cppFileLocation.getSiblingFile (tokens[2].unquoted()).getFullPathName()); jassert (resourceName.isNotEmpty() && resourceSize > 0); if (resourceName.isNotEmpty() && resourceSize > 0) { const int firstLine = i; while (i < cpp.size()) if (cpp [i++].contains ("}")) break; const String dataString (cpp.joinIntoString (" ", firstLine, i - firstLine) .fromFirstOccurrenceOf ("{", false, false)); MemoryOutputStream out; String::CharPointerType t (dataString.getCharPointer()); int n = 0; while (! t.isEmpty()) { const juce_wchar c = t.getAndAdvance(); if (c >= '0' && c <= '9') n = n * 10 + (c - '0'); else if (c == ',') { out.writeByte ((char) n); n = 0; } else if (c == '}') break; } jassert (resourceSize < (int) out.getDataSize() && resourceSize > (int) out.getDataSize() - 2); MemoryBlock mb (out.getData(), out.getDataSize()); mb.setSize ((size_t) resourceSize); add (resourceName, originalFileName, mb); } } } }