gfx/angle/src/compiler/preprocessor/Input.cpp

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 //
michael@0 2 // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
michael@0 3 // Use of this source code is governed by a BSD-style license that can be
michael@0 4 // found in the LICENSE file.
michael@0 5 //
michael@0 6
michael@0 7 #include "Input.h"
michael@0 8
michael@0 9 #include <algorithm>
michael@0 10 #include <cassert>
michael@0 11 #include <cstring>
michael@0 12
michael@0 13 namespace pp
michael@0 14 {
michael@0 15
michael@0 16 Input::Input() : mCount(0), mString(0)
michael@0 17 {
michael@0 18 }
michael@0 19
michael@0 20 Input::Input(size_t count, const char* const string[], const int length[]) :
michael@0 21 mCount(count),
michael@0 22 mString(string)
michael@0 23 {
michael@0 24 mLength.reserve(mCount);
michael@0 25 for (size_t i = 0; i < mCount; ++i)
michael@0 26 {
michael@0 27 int len = length ? length[i] : -1;
michael@0 28 mLength.push_back(len < 0 ? std::strlen(mString[i]) : len);
michael@0 29 }
michael@0 30 }
michael@0 31
michael@0 32 size_t Input::read(char* buf, size_t maxSize)
michael@0 33 {
michael@0 34 size_t nRead = 0;
michael@0 35 while ((nRead < maxSize) && (mReadLoc.sIndex < mCount))
michael@0 36 {
michael@0 37 size_t size = mLength[mReadLoc.sIndex] - mReadLoc.cIndex;
michael@0 38 size = std::min(size, maxSize);
michael@0 39 std::memcpy(buf + nRead, mString[mReadLoc.sIndex] + mReadLoc.cIndex, size);
michael@0 40 nRead += size;
michael@0 41 mReadLoc.cIndex += size;
michael@0 42
michael@0 43 // Advance string if we reached the end of current string.
michael@0 44 if (mReadLoc.cIndex == mLength[mReadLoc.sIndex])
michael@0 45 {
michael@0 46 ++mReadLoc.sIndex;
michael@0 47 mReadLoc.cIndex = 0;
michael@0 48 }
michael@0 49 }
michael@0 50 return nRead;
michael@0 51 }
michael@0 52
michael@0 53 } // namespace pp
michael@0 54

mercurial