OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkString.h" | 10 #include "SkString.h" |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 | 582 |
583 this->prepend(buffer, strlen(buffer)); | 583 this->prepend(buffer, strlen(buffer)); |
584 } | 584 } |
585 | 585 |
586 /////////////////////////////////////////////////////////////////////////////// | 586 /////////////////////////////////////////////////////////////////////////////// |
587 | 587 |
588 void SkString::remove(size_t offset, size_t length) { | 588 void SkString::remove(size_t offset, size_t length) { |
589 size_t size = this->size(); | 589 size_t size = this->size(); |
590 | 590 |
591 if (offset < size) { | 591 if (offset < size) { |
592 if (offset + length > size) { | 592 if (length > size - offset) { |
593 length = size - offset; | 593 length = size - offset; |
594 } | 594 } |
| 595 SkASSERT(length <= size); |
| 596 SkASSERT(offset <= size - length); |
595 if (length > 0) { | 597 if (length > 0) { |
596 SkASSERT(size > length); | |
597 SkString tmp(size - length); | 598 SkString tmp(size - length); |
598 char* dst = tmp.writable_str(); | 599 char* dst = tmp.writable_str(); |
599 const char* src = this->c_str(); | 600 const char* src = this->c_str(); |
600 | 601 |
601 if (offset) { | 602 if (offset) { |
602 SkASSERT(offset <= tmp.size()); | |
603 memcpy(dst, src, offset); | 603 memcpy(dst, src, offset); |
604 } | 604 } |
605 size_t tail = size - offset - length; | 605 size_t tail = size - (offset + length); |
606 SkASSERT((int32_t)tail >= 0); | |
607 if (tail) { | 606 if (tail) { |
608 // SkASSERT(offset + length <= tmp.size()); | 607 memcpy(dst + offset, src + (offset + length), tail); |
609 memcpy(dst + offset, src + offset + length, tail); | |
610 } | 608 } |
611 SkASSERT(dst[tmp.size()] == 0); | 609 SkASSERT(dst[tmp.size()] == 0); |
612 this->swap(tmp); | 610 this->swap(tmp); |
613 } | 611 } |
614 } | 612 } |
615 } | 613 } |
616 | 614 |
617 void SkString::swap(SkString& other) { | 615 void SkString::swap(SkString& other) { |
618 this->validate(); | 616 this->validate(); |
619 other.validate(); | 617 other.validate(); |
(...skipping 21 matching lines...) Expand all Loading... |
641 const size_t len = strcspn(str, delimiters); | 639 const size_t len = strcspn(str, delimiters); |
642 out->push_back().set(str, len); | 640 out->push_back().set(str, len); |
643 str += len; | 641 str += len; |
644 // Skip any delimiters. | 642 // Skip any delimiters. |
645 str += strspn(str, delimiters); | 643 str += strspn(str, delimiters); |
646 } | 644 } |
647 } | 645 } |
648 | 646 |
649 #undef VSNPRINTF | 647 #undef VSNPRINTF |
650 #undef SNPRINTF | 648 #undef SNPRINTF |
OLD | NEW |