mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
Ramfile::readline()
This commit is contained in:
parent
045f29ee3a
commit
eff0d77e07
@ -33,4 +33,5 @@ get_length(void) const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE Ramfile::
|
INLINE Ramfile::
|
||||||
Ramfile(void) {
|
Ramfile(void) {
|
||||||
|
_pos = 0;
|
||||||
}
|
}
|
||||||
|
@ -41,3 +41,32 @@ Buffer::
|
|||||||
~Buffer() {
|
~Buffer() {
|
||||||
delete _buffer;
|
delete _buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Ramfile::readline
|
||||||
|
// Access: Published
|
||||||
|
// Description: Assumes the stream represents a text file, and
|
||||||
|
// extracts one line up to and including the trailing
|
||||||
|
// newline character. Returns empty string when the end
|
||||||
|
// of file is reached.
|
||||||
|
//
|
||||||
|
// The interface here is intentionally designed to be
|
||||||
|
// similar to that for Python's File.readline()
|
||||||
|
// function.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
string Ramfile::
|
||||||
|
readline() {
|
||||||
|
size_t start = _pos;
|
||||||
|
while (_pos < _data.length() && _data[_pos] != '\n') {
|
||||||
|
++_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_pos < _data.length() && _data[_pos] == '\n') {
|
||||||
|
// Include the newline character also.
|
||||||
|
++_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _data.substr(start, _pos - start);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -52,9 +52,12 @@ private:
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_PANDAEXPRESS Ramfile {
|
class EXPCL_PANDAEXPRESS Ramfile {
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
INLINE Ramfile(void);
|
INLINE Ramfile();
|
||||||
|
|
||||||
|
string readline();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
size_t _pos;
|
||||||
string _data;
|
string _data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user