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

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

mercurial