michael@0: // michael@0: // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #include "Input.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: namespace pp michael@0: { michael@0: michael@0: Input::Input() : mCount(0), mString(0) michael@0: { michael@0: } michael@0: michael@0: Input::Input(size_t count, const char* const string[], const int length[]) : michael@0: mCount(count), michael@0: mString(string) michael@0: { michael@0: mLength.reserve(mCount); michael@0: for (size_t i = 0; i < mCount; ++i) michael@0: { michael@0: int len = length ? length[i] : -1; michael@0: mLength.push_back(len < 0 ? std::strlen(mString[i]) : len); michael@0: } michael@0: } michael@0: michael@0: size_t Input::read(char* buf, size_t maxSize) michael@0: { michael@0: size_t nRead = 0; michael@0: while ((nRead < maxSize) && (mReadLoc.sIndex < mCount)) michael@0: { michael@0: size_t size = mLength[mReadLoc.sIndex] - mReadLoc.cIndex; michael@0: size = std::min(size, maxSize); michael@0: std::memcpy(buf + nRead, mString[mReadLoc.sIndex] + mReadLoc.cIndex, size); michael@0: nRead += size; michael@0: mReadLoc.cIndex += size; michael@0: michael@0: // Advance string if we reached the end of current string. michael@0: if (mReadLoc.cIndex == mLength[mReadLoc.sIndex]) michael@0: { michael@0: ++mReadLoc.sIndex; michael@0: mReadLoc.cIndex = 0; michael@0: } michael@0: } michael@0: return nRead; michael@0: } michael@0: michael@0: } // namespace pp michael@0: