dom/plugins/base/nsPluginManifestLineReader.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsPluginManifestLineReader_h_
     7 #define nsPluginManifestLineReader_h_
     9 #include "nspr.h"
    10 #include "nsDebug.h"
    12 #ifdef XP_WIN
    13 #define PLUGIN_REGISTRY_FIELD_DELIMITER '|'
    14 #else
    15 #define PLUGIN_REGISTRY_FIELD_DELIMITER ':'
    16 #endif
    18 #define PLUGIN_REGISTRY_END_OF_LINE_MARKER '$'
    20 class nsPluginManifestLineReader
    21 {
    22   public:
    23     nsPluginManifestLineReader() {mBase = mCur = mNext = mLimit = 0;} 
    24     ~nsPluginManifestLineReader() { if (mBase) delete[] mBase; mBase=0;}
    26     char* Init(uint32_t flen) 
    27     {
    28       mBase = mCur = mNext = new char[flen + 1];
    29       if (mBase) {
    30         mLimit = mBase + flen;
    31         *mLimit = 0;
    32       }
    33       mLength = 0;
    34       return mBase;
    35     }
    37     bool NextLine()
    38     {
    39       if (mNext >= mLimit)
    40         return false;
    42       mCur = mNext;
    43       mLength = 0;
    45       char *lastDelimiter = 0;
    46       while(mNext < mLimit) {
    47         if (IsEOL(*mNext)) {
    48           if (lastDelimiter) {
    49             if (lastDelimiter && *(mNext - 1) != PLUGIN_REGISTRY_END_OF_LINE_MARKER)
    50               return false;
    51             *lastDelimiter = '\0';
    52           } else {
    53             *mNext = '\0';
    54           }
    56           for (++mNext; mNext < mLimit; ++mNext) {
    57             if (!IsEOL(*mNext))
    58               break;
    59           }
    60           return true;
    61         }
    62         if (*mNext == PLUGIN_REGISTRY_FIELD_DELIMITER)
    63           lastDelimiter = mNext;
    64         ++mNext;
    65         ++mLength;
    66       }
    67       return false;        
    68     }
    70     int ParseLine(char** chunks, int maxChunks)
    71     {
    72       NS_ASSERTION(mCur && maxChunks && chunks, "bad call to ParseLine");
    73       int found = 0;
    74       chunks[found++] = mCur;
    76       if (found < maxChunks) {
    77         for (char* cur = mCur; *cur; cur++) {
    78           if (*cur == PLUGIN_REGISTRY_FIELD_DELIMITER) {
    79             *cur = 0;
    80             chunks[found++] = cur + 1;
    81             if (found == maxChunks)
    82               break;
    83           }
    84         }
    85       }
    86       return found;
    87     }
    89     char*       LinePtr() { return mCur; }
    90     uint32_t    LineLength() { return mLength; }    
    92     bool        IsEOL(char c) {return c == '\n' || c == '\r';}
    94     char*       mBase;
    95   private:
    96     char*       mCur;
    97     uint32_t    mLength;
    98     char*       mNext;
    99     char*       mLimit;
   100 };
   102 #endif

mercurial