Example #1
0
    static int getNumpadKeyCode (const String& desc)
    {
        if (desc.containsIgnoreCase (numberPadPrefix()))
        {
            auto lastChar = desc.trimEnd().getLastCharacter();

            switch (lastChar)
            {
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
                    return (int) (KeyPress::numberPad0 + (int) lastChar - '0');

                case '+':   return KeyPress::numberPadAdd;
                case '-':   return KeyPress::numberPadSubtract;
                case '*':   return KeyPress::numberPadMultiply;
                case '/':   return KeyPress::numberPadDivide;
                case '.':   return KeyPress::numberPadDecimalPoint;
                case '=':   return KeyPress::numberPadEquals;

                default:    break;
            }

            if (desc.endsWith ("separator"))  return KeyPress::numberPadSeparator;
            if (desc.endsWith ("delete"))     return KeyPress::numberPadDelete;
        }

        return 0;
    }
Example #2
0
void URL::createHeadersAndPostData (String& headers, MemoryBlock& postDataToWrite) const
{
    MemoryOutputStream data (postDataToWrite, false);

    if (filesToUpload.size() > 0)
    {
        // (this doesn't currently support mixing custom post-data with uploads..)
        jassert (postData.getSize() == 0);

        auto boundary = String::toHexString (Random::getSystemRandom().nextInt64());

        headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";

        data << "--" << boundary;

        for (int i = 0; i < parameterNames.size(); ++i)
        {
            data << "\r\nContent-Disposition: form-data; name=\"" << parameterNames[i]
                 << "\"\r\n\r\n" << parameterValues[i]
                 << "\r\n--" << boundary;
        }

        for (auto* f : filesToUpload)
        {
            data << "\r\nContent-Disposition: form-data; name=\"" << f->parameterName
                 << "\"; filename=\"" << f->filename << "\"\r\n";

            if (f->mimeType.isNotEmpty())
                data << "Content-Type: " << f->mimeType << "\r\n";

            data << "Content-Transfer-Encoding: binary\r\n\r\n";

            if (f->data != nullptr)
                data << *f->data;
            else
                data << f->file;

            data << "\r\n--" << boundary;
        }

        data << "--\r\n";
    }
    else
    {
        data << URLHelpers::getMangledParameters (*this)
             << postData;

        // if the user-supplied headers didn't contain a content-type, add one now..
        if (! headers.containsIgnoreCase ("Content-Type"))
            headers << "Content-Type: application/x-www-form-urlencoded\r\n";

        headers << "Content-length: " << (int) data.getDataSize() << "\r\n";
    }
}
Example #3
0
void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const
{
    const File header (getModuleHeaderFile (moduleInfo.getFolder()));
    jassert (header.exists());

    StringArray lines;
    header.readLines (lines);

    for (int i = 0; i < lines.size(); ++i)
    {
        String line (lines[i].trim());

        if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
        {
            ScopedPointer <Project::ConfigFlag> config (new Project::ConfigFlag());
            config->sourceModuleID = getID();
            config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();

            if (config->symbol.length() > 2)
            {
                ++i;

                while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
                {
                    if (lines[i].trim().isNotEmpty())
                        config->description = config->description.trim() + " " + lines[i].trim();

                    ++i;
                }

                config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
                config->value.referTo (project.getConfigFlag (config->symbol));
                flags.add (config.release());
            }
        }
    }
}
    //==============================================================================
    Drawable* parseSVGElement (const XmlElement& xml)
    {
        if (! xml.hasTagNameIgnoringNamespace ("svg"))
            return nullptr;

        DrawableComposite* const drawable = new DrawableComposite();

        drawable->setName (xml.getStringAttribute ("id"));

        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;

        if (xml.hasAttribute ("viewBox"))
        {
            const String viewBoxAtt (xml.getStringAttribute ("viewBox"));
            String::CharPointerType viewParams (viewBoxAtt.getCharPointer());
            Point<float> vxy, vwh;

            if (parseCoords (viewParams, vxy, 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> (vxy.x, vxy.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 (Rectangle<float> (newState.viewBoxW, newState.viewBoxH)));
        drawable->resetBoundingBoxToContentArea();

        return drawable;
    }
Example #5
0
  bool parseFile (const File& rootFolder,
    const File& newTargetFile,
    OutputStream& dest,
    const File& file,
    StringArray& alreadyIncludedFiles,
    const StringArray& includesToIgnore,
    const StringArray& wildcards,
    int level,
    bool stripCommentBlocks)
  {
    // Make sure the file exists

    if (! file.exists())
    {
      std::cout << "  !! ERROR - file doesn't exist!";
      return false;
    }

    // Load the entire file as an array of individual lines.

    StringArray lines;
    lines.addLines (file.loadFileAsString());

    // Make sure there is something in the file.

    if (lines.size() == 0)
    {
      std::cout << "  !! ERROR - input file was empty: " << file.getFullPathName();
      return false;
    }

    // Produce some descriptive progress.

    if (m_verbose)
    {
      if (level == 0)
        std::cout << "  Processing \"" << file.getFileName () << "\"\n";
      else
        std::cout << "  Inlining " << String::repeatedString (" ", level - 1)
                  << "\"" << file.getFileName () << "\"\n";
    }

    bool lastLineWasBlank = true;

    for (int i = 0; i < lines.size(); ++i)
    {
      String line (lines[i]);
      String trimmed (line.trimStart());

      if ((level != 0) && trimmed.startsWith ("//================================================================"))
        line = String::empty;

      std::string s (line.toUTF8 ());

      if (m_remapTable.processLine (s))
      {
        line = String::empty;
      }
      else
      {
        ParsedInclude parsedInclude = parseInclude (line, trimmed);

        if (parsedInclude.isIncludeLine)
        {
          const File targetFile = findInclude (file, parsedInclude.filename);

          if (targetFile.exists())
          {
            if (matchesWildcard (parsedInclude.filename.replaceCharacter ('\\', '/'))
              && ! includesToIgnore.contains (targetFile.getFileName()))
            {
              String fileNamePart = File (parsedInclude.filename).getFileName ();
              RemapTable::iterator remapTo = m_remapTable.find (std::string (fileNamePart.toUTF8 ()));
              if (level != 0 && remapTo != m_remapTable.end ())
              {
                line = "#include \"";
                line << String(remapTo->second.c_str ()) << "\"" << newLine;

                findAllFilesIncludedIn (targetFile, alreadyIncludedFiles);
              }
              else if (line.containsIgnoreCase("SKIP_AMALGAMATOR_INCLUDE"))
              {
              }
              else if (line.containsIgnoreCase ("FORCE_AMALGAMATOR_INCLUDE")
                || ! alreadyIncludedFiles.contains (targetFile.getFullPathName()))
              {
                if (parsedInclude.preventReinclude)
                {
                  alreadyIncludedFiles.add (targetFile.getFullPathName());
                }
                else if (parsedInclude.forceReinclude)
                {
                }
                else if (! canFileBeReincluded (targetFile))
                {
                  alreadyIncludedFiles.add (targetFile.getFullPathName());
                }

                dest << newLine << "/*** Start of inlined file: " << targetFile.getFileName() << " ***/" << newLine;

                if (! parseFile (rootFolder, newTargetFile,
                  dest, targetFile, alreadyIncludedFiles, includesToIgnore,
                  wildcards, level + 1, stripCommentBlocks))
                {
                  return false;
                }

                dest << "/*** End of inlined file: " << targetFile.getFileName() << " ***/" << newLine << newLine;

                line = parsedInclude.lineAfterInclude;
              }
              else
              {
                line = String::empty;
              }
            }
            else
            {
              line = parsedInclude.lineUpToEndOfInclude.upToFirstOccurrenceOf ("\"", true, false)
                + targetFile.getRelativePathFrom (newTargetFile.getParentDirectory())
                .replaceCharacter ('\\', '/')
                + "\""
                + parsedInclude.lineAfterInclude;
            }
          }
        }
      }

      if ((stripCommentBlocks || i == 0) && trimmed.startsWith ("/*") && (i > 10 || level != 0))
      {
        int originalI = i;
        String originalLine = line;

        for (;;)
        {
          int end = line.indexOf ("*/");

          if (end >= 0)
          {
            line = line.substring (end + 2);

            // If our comment appeared just before an assertion, leave it in, as it
            // might be useful..
            if (lines [i + 1].contains ("assert")
              || lines [i + 2].contains ("assert"))
            {
              i = originalI;
              line = originalLine;
            }

            break;
          }

          line = lines [++i];

          if (i >= lines.size())
            break;
        }

        line = line.trimEnd();
        if (line.isEmpty())
          continue;
      }

      line = line.trimEnd();

      {
        // Turn initial spaces into tabs..
        int numIntialSpaces = 0;
        int len = line.length();
        while (numIntialSpaces < len && line [numIntialSpaces] == ' ')
          ++numIntialSpaces;

        if (numIntialSpaces > 0)
        {
          int tabSize = 4;
          int numTabs = numIntialSpaces / tabSize;
          line = String::repeatedString ("\t", numTabs) + line.substring (numTabs * tabSize);
        }

  #if 0
        if (! line.containsChar ('"'))
        {
          // turn large areas of spaces into tabs - this will mess up alignment a bit, but
          // it's only the amalgamated file, so doesn't matter...
          line = line.replace ("        ", "\t", false);
          line = line.replace ("    ", "\t", false);
        }
  #endif
      }

      if (line.isNotEmpty() || ! lastLineWasBlank)
        dest << line << newLine;

      lastLineWasBlank = line.isEmpty();
    }

    return true;
  }