| 600 | /// Options). Returns a StringView which uses `buf` as the underlying buffer. |
| 601 | template <typename T> |
| 602 | StringView randString( |
| 603 | FuzzerGenerator& rng, |
| 604 | const VectorFuzzer::Options& opts, |
| 605 | std::string& buf, |
| 606 | const bool doStringIncrementalGeneration, |
| 607 | T& reusablePartBuffer, |
| 608 | const size_t reusablePartLength) { |
| 609 | buf.clear(); |
| 610 | |
| 611 | std::u32string wbuf; |
| 612 | const size_t stringLength = opts.stringVariableLength |
| 613 | ? rand<uint32_t>(rng) % opts.stringLength |
| 614 | : opts.stringLength; |
| 615 | wbuf.resize(stringLength); |
| 616 | |
| 617 | if (doStringIncrementalGeneration && reusablePartLength != 0) { |
| 618 | for (size_t i = 0; i < stringLength;) { |
| 619 | if (rand<bool>(rng)) { |
| 620 | // Reuse the reusable part. |
| 621 | size_t j; |
| 622 | for (j = 0; j < reusablePartLength && i + j < stringLength; ++j) { |
| 623 | wbuf[i + j] = reusablePartBuffer[j]; |
| 624 | } |
| 625 | i += j; |
| 626 | } else { |
| 627 | // Randomly generate a character at the current index. |
| 628 | fillBuffer(wbuf, i, 1, rng, opts); |
| 629 | ++i; |
| 630 | } |
| 631 | } |
| 632 | } else { |
| 633 | // Randomly generate the entire string. |
| 634 | fillBuffer(wbuf, 0, stringLength, rng, opts); |
| 635 | } |
| 636 | buf.append(utf32ToUtf8(wbuf)); |
| 637 | return StringView(buf); |
| 638 | } |
| 639 | |
| 640 | template <TypeKind kind> |
| 641 | VectorPtr fuzzConstantPrimitiveImpl( |
no test coverage detected