MCPcopy Create free account
hub / github.com/OGRECave/ogre-next / readLine

Method readLine

OgreMain/src/OgreDataStream.cpp:91–146  ·  view source on GitHub ↗

-----------------------------------------------------------------------

Source from the content-addressed store, hash-verified

89 }
90 //-----------------------------------------------------------------------
91 size_t DataStream::readLine( char *buf, size_t maxCount, const String &delim )
92 {
93 // Deal with both Unix & Windows LFs
94 bool trimCR = false;
95 if( delim.find_first_of( '\n' ) != String::npos )
96 {
97 trimCR = true;
98 }
99
100 char tmpBuf[OGRE_STREAM_TEMP_SIZE];
101 size_t chunkSize = std::min( maxCount, (size_t)OGRE_STREAM_TEMP_SIZE - 1 );
102 size_t totalCount = 0;
103 size_t readCount;
104 while( chunkSize && ( readCount = read( tmpBuf, chunkSize ) ) != 0 )
105 {
106 // Terminate
107 tmpBuf[readCount] = '\0';
108
109 // Find first delimiter
110 size_t pos = strcspn( tmpBuf, delim.c_str() );
111
112 if( pos < readCount )
113 {
114 // Found terminator, reposition backwards
115 skip( (long)( pos + 1 - readCount ) );
116 }
117
118 // Are we genuinely copying?
119 if( buf )
120 {
121 memcpy( buf + totalCount, tmpBuf, pos );
122 }
123 totalCount += pos;
124
125 if( pos < readCount )
126 {
127 // Trim off trailing CR if this was a CR/LF entry
128 if( trimCR && totalCount && buf && buf[totalCount - 1] == '\r' )
129 {
130 --totalCount;
131 }
132
133 // Found terminator, break out
134 break;
135 }
136
137 // Adjust chunkSize for next time
138 chunkSize = std::min( maxCount - totalCount, (size_t)OGRE_STREAM_TEMP_SIZE - 1 );
139 }
140
141 // Terminate
142 if( buf )
143 buf[totalCount] = '\0';
144
145 return totalCount;
146 }
147 //-----------------------------------------------------------------------
148 size_t DataStream::skipLine( const String &delim )

Callers 1

parseScriptMethod · 0.80

Calls 11

skipFunction · 0.85
find_first_ofMethod · 0.80
atMethod · 0.80
readFunction · 0.70
c_strMethod · 0.45
findMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
logMessageMethod · 0.45
eofMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected