OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 |
| 3 #ifndef THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_ |
| 4 #define THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_ |
| 5 |
| 6 #include <assert.h> |
| 7 #include <random> |
| 8 #include "base/at_exit.h" |
| 9 #include "base/i18n/icu_util.h" |
| 10 #include "third_party/icu/source/common/unicode/locid.h" |
| 11 |
| 12 struct IcuEnvironment { |
| 13 IcuEnvironment() { |
| 14 base::i18n::InitializeICU(); |
| 15 } |
| 16 }; |
| 17 |
| 18 // Create RNG and seed it from data. |
| 19 std::mt19937_64 CreateRng(const uint8_t* data, size_t size) { |
| 20 std::mt19937_64 rng; |
| 21 std::string str = std::string(reinterpret_cast<const char*>(data), size); |
| 22 std::size_t data_hash = std::hash<std::string>()(str); |
| 23 rng.seed(data_hash); |
| 24 return rng; |
| 25 } |
| 26 |
| 27 const icu::Locale& GetRandomLocale(std::mt19937_64* rng) { |
| 28 int32_t num_locales; |
| 29 assert(num_locales > 0); |
| 30 const icu::Locale* locales = icu::Locale::getAvailableLocales(num_locales); |
| 31 return locales[(*rng)() % num_locales]; |
| 32 } |
| 33 |
| 34 #endif // THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_ |
OLD | NEW |