dom/plugins/base/nsPluginManifestLineReader.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/base/nsPluginManifestLineReader.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsPluginManifestLineReader_h_
    1.10 +#define nsPluginManifestLineReader_h_
    1.11 +
    1.12 +#include "nspr.h"
    1.13 +#include "nsDebug.h"
    1.14 +
    1.15 +#ifdef XP_WIN
    1.16 +#define PLUGIN_REGISTRY_FIELD_DELIMITER '|'
    1.17 +#else
    1.18 +#define PLUGIN_REGISTRY_FIELD_DELIMITER ':'
    1.19 +#endif
    1.20 +
    1.21 +#define PLUGIN_REGISTRY_END_OF_LINE_MARKER '$'
    1.22 +
    1.23 +class nsPluginManifestLineReader
    1.24 +{
    1.25 +  public:
    1.26 +    nsPluginManifestLineReader() {mBase = mCur = mNext = mLimit = 0;} 
    1.27 +    ~nsPluginManifestLineReader() { if (mBase) delete[] mBase; mBase=0;}
    1.28 +    
    1.29 +    char* Init(uint32_t flen) 
    1.30 +    {
    1.31 +      mBase = mCur = mNext = new char[flen + 1];
    1.32 +      if (mBase) {
    1.33 +        mLimit = mBase + flen;
    1.34 +        *mLimit = 0;
    1.35 +      }
    1.36 +      mLength = 0;
    1.37 +      return mBase;
    1.38 +    }
    1.39 +    
    1.40 +    bool NextLine()
    1.41 +    {
    1.42 +      if (mNext >= mLimit)
    1.43 +        return false;
    1.44 +      
    1.45 +      mCur = mNext;
    1.46 +      mLength = 0;
    1.47 +      
    1.48 +      char *lastDelimiter = 0;
    1.49 +      while(mNext < mLimit) {
    1.50 +        if (IsEOL(*mNext)) {
    1.51 +          if (lastDelimiter) {
    1.52 +            if (lastDelimiter && *(mNext - 1) != PLUGIN_REGISTRY_END_OF_LINE_MARKER)
    1.53 +              return false;
    1.54 +            *lastDelimiter = '\0';
    1.55 +          } else {
    1.56 +            *mNext = '\0';
    1.57 +          }
    1.58 +
    1.59 +          for (++mNext; mNext < mLimit; ++mNext) {
    1.60 +            if (!IsEOL(*mNext))
    1.61 +              break;
    1.62 +          }
    1.63 +          return true;
    1.64 +        }
    1.65 +        if (*mNext == PLUGIN_REGISTRY_FIELD_DELIMITER)
    1.66 +          lastDelimiter = mNext;
    1.67 +        ++mNext;
    1.68 +        ++mLength;
    1.69 +      }
    1.70 +      return false;        
    1.71 +    }
    1.72 +
    1.73 +    int ParseLine(char** chunks, int maxChunks)
    1.74 +    {
    1.75 +      NS_ASSERTION(mCur && maxChunks && chunks, "bad call to ParseLine");
    1.76 +      int found = 0;
    1.77 +      chunks[found++] = mCur;
    1.78 +      
    1.79 +      if (found < maxChunks) {
    1.80 +        for (char* cur = mCur; *cur; cur++) {
    1.81 +          if (*cur == PLUGIN_REGISTRY_FIELD_DELIMITER) {
    1.82 +            *cur = 0;
    1.83 +            chunks[found++] = cur + 1;
    1.84 +            if (found == maxChunks)
    1.85 +              break;
    1.86 +          }
    1.87 +        }
    1.88 +      }
    1.89 +      return found;
    1.90 +    }
    1.91 +
    1.92 +    char*       LinePtr() { return mCur; }
    1.93 +    uint32_t    LineLength() { return mLength; }    
    1.94 +
    1.95 +    bool        IsEOL(char c) {return c == '\n' || c == '\r';}
    1.96 +
    1.97 +    char*       mBase;
    1.98 +  private:
    1.99 +    char*       mCur;
   1.100 +    uint32_t    mLength;
   1.101 +    char*       mNext;
   1.102 +    char*       mLimit;
   1.103 +};
   1.104 +
   1.105 +#endif

mercurial