| 375 | } |
| 376 | |
| 377 | ByteString ByteString::Substring(size_t pos, size_t npos) const { |
| 378 | ABSL_DCHECK_LE(npos, size()); |
| 379 | ABSL_DCHECK_LE(pos, npos); |
| 380 | |
| 381 | switch (GetKind()) { |
| 382 | case ByteStringKind::kSmall: { |
| 383 | ByteString result; |
| 384 | result.rep_.header.kind = ByteStringKind::kSmall; |
| 385 | result.rep_.small.size = npos - pos; |
| 386 | std::memcpy(result.rep_.small.data, rep_.small.data + pos, |
| 387 | result.rep_.small.size); |
| 388 | result.rep_.small.arena = GetSmallArena(); |
| 389 | return result; |
| 390 | } |
| 391 | case ByteStringKind::kMedium: { |
| 392 | ByteString result(*this); |
| 393 | result.rep_.medium.data += pos; |
| 394 | result.rep_.medium.size = npos - pos; |
| 395 | return result; |
| 396 | } |
| 397 | case ByteStringKind::kLarge: |
| 398 | return ByteString(GetLarge().Subcord(pos, npos - pos)); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | void ByteString::RemovePrefix(size_t n) { |
| 403 | ABSL_DCHECK_LE(n, size()); |