| 199 | } |
| 200 | |
| 201 | std::streambuf::pos_type |
| 202 | BundleResourceBuffer::seekoff(std::streambuf::off_type off, |
| 203 | std::ios_base::seekdir way, |
| 204 | std::ios_base::openmode /*which*/) |
| 205 | { |
| 206 | #ifdef DATA_NEEDS_NEWLINE_CONVERSION |
| 207 | std::streambuf::off_type step = 1; |
| 208 | if (way == std::ios_base::beg) |
| 209 | { |
| 210 | d->current = d->begin; |
| 211 | } |
| 212 | else if (way == std::ios_base::end) |
| 213 | { |
| 214 | d->current = d->end; |
| 215 | step = -1; |
| 216 | } |
| 217 | |
| 218 | if (!(d->mode & std::ios_base::binary)) |
| 219 | { |
| 220 | if (way == std::ios_base::beg) |
| 221 | { |
| 222 | d->pos = 0; |
| 223 | } |
| 224 | else if (way == std::ios_base::end) |
| 225 | { |
| 226 | d->current -= 1; |
| 227 | } |
| 228 | |
| 229 | std::streambuf::off_type i = 0; |
| 230 | // scan through off amount of characters excluding '\r' |
| 231 | while (i != off) |
| 232 | { |
| 233 | if (*d->current != '\r') |
| 234 | { |
| 235 | i += step; |
| 236 | d->pos += step; |
| 237 | } |
| 238 | d->current += step; |
| 239 | } |
| 240 | |
| 241 | // adjust the position in case of a "backwards" seek |
| 242 | if (way == std::ios_base::end) |
| 243 | { |
| 244 | // fix pointer from previous while loop |
| 245 | d->current += 1; |
| 246 | d->pos = 0; |
| 247 | i = 0; |
| 248 | const std::streampos currInternalPos = d->current - d->begin; |
| 249 | while (i != currInternalPos) |
| 250 | { |
| 251 | if (d->begin[i] != '\r') |
| 252 | { |
| 253 | d->pos += 1; |
| 254 | } |
| 255 | ++i; |
| 256 | } |
| 257 | } |
| 258 | } |