1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/preprocessor/Input.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +// 1.5 +// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +#include "Input.h" 1.11 + 1.12 +#include <algorithm> 1.13 +#include <cassert> 1.14 +#include <cstring> 1.15 + 1.16 +namespace pp 1.17 +{ 1.18 + 1.19 +Input::Input() : mCount(0), mString(0) 1.20 +{ 1.21 +} 1.22 + 1.23 +Input::Input(size_t count, const char* const string[], const int length[]) : 1.24 + mCount(count), 1.25 + mString(string) 1.26 +{ 1.27 + mLength.reserve(mCount); 1.28 + for (size_t i = 0; i < mCount; ++i) 1.29 + { 1.30 + int len = length ? length[i] : -1; 1.31 + mLength.push_back(len < 0 ? std::strlen(mString[i]) : len); 1.32 + } 1.33 +} 1.34 + 1.35 +size_t Input::read(char* buf, size_t maxSize) 1.36 +{ 1.37 + size_t nRead = 0; 1.38 + while ((nRead < maxSize) && (mReadLoc.sIndex < mCount)) 1.39 + { 1.40 + size_t size = mLength[mReadLoc.sIndex] - mReadLoc.cIndex; 1.41 + size = std::min(size, maxSize); 1.42 + std::memcpy(buf + nRead, mString[mReadLoc.sIndex] + mReadLoc.cIndex, size); 1.43 + nRead += size; 1.44 + mReadLoc.cIndex += size; 1.45 + 1.46 + // Advance string if we reached the end of current string. 1.47 + if (mReadLoc.cIndex == mLength[mReadLoc.sIndex]) 1.48 + { 1.49 + ++mReadLoc.sIndex; 1.50 + mReadLoc.cIndex = 0; 1.51 + } 1.52 + } 1.53 + return nRead; 1.54 +} 1.55 + 1.56 +} // namespace pp 1.57 +