-----------------------------------------------------------------------
| 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 ) |
no test coverage detected