<commit_before>// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "google/fhir/testutil/generator.h"

#include <memory>
#include <string>
#include <vector>

#include "google/protobuf/any.pb.h"
#include "google/protobuf/descriptor.h"
#include "absl/random/distributions.h"
#include "absl/status/status.h"
#include "google/fhir/annotations.h"
#include "google/fhir/fhir_types.h"
#include "google/fhir/json_format_results.h"
#include "google/fhir/proto_util.h"
#include "google/fhir/references.h"
#include "google/fhir/util.h"

namespace google {
namespace fhir {
namespace testutil {

namespace {

// Characters to use in ids.
const absl::string_view kLegalIdCharacters =
    "abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";

// Characters to use in strings. Should be compatible
// with the FHIR string regex which is "[ \r\n\t\S]+"
const absl::string_view kLegalStringCharacters =
    u8"abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789"
    "!@#$%?^&*()-+=_{}[]|<>,.\\"
    " \n\r\t";

// Returns a randomly generated string consisting of legal_characters
// and of length between the given min and max string lengths, inclusive.
std::string RandomString(absl::string_view legal_characters,
                         int min_string_length, int max_string_length,
                         absl::BitGen& bitgen) {
  int length = absl::Uniform<int>(bitgen, min_string_length, max_string_length);
  std::string str;
  str.reserve(length);
  for (int i = 0; i < length; i++) {
    char c = kLegalStringCharacters[absl::Uniform<size_t>(
        bitgen, 0, legal_characters.length())];
    str += c;<commit_msg>Wrap u8-prefixed string literal in reinterpret_cast to make it compatible with C++20.<commit_after>// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "google/fhir/testutil/generator.h"

#include <memory>
#include <string>
#include <vector>

#include "google/protobuf/any.pb.h"
#include "google/protobuf/descriptor.h"
#include "absl/random/distributions.h"
#include "absl/status/status.h"
#include "google/fhir/annotations.h"
#include "google/fhir/fhir_types.h"
#include "google/fhir/json_format_results.h"
#include "google/fhir/proto_util.h"
#include "google/fhir/references.h"
#include "google/fhir/util.h"

namespace google {
namespace fhir {
namespace testutil {

namespace {

// Characters to use in ids.
const absl::string_view kLegalIdCharacters =
    "abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";

// Characters to use in strings. Should be compatible
// with the FHIR string regex which is "[ \r\n\t\S]+"
const absl::string_view kLegalStringCharacters = reinterpret_cast<const char*>(
    u8"abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789"
    "!@#$%?^&*()-+=_{}[]|<>,.\\"
    " \n\r\t");

// Returns a randomly generated string consisting of legal_characters
// and of length between the given min and max string lengths, inclusive.
std::string RandomString(absl::string_view legal_characters,
                         int min_string_length, int max_string_length,
                         absl::BitGen& bitgen) {
  int length = absl::Uniform<int>(bitgen, min_string_length, max_string_length);
  std::string str;
  str.reserve(length);
  for (int i = 0; i < length; i++) {
    char c = kLegalStringCharacters[absl::Uniform<size_t>(
        bitgen, 0, legal_characters.length())];
    str += c;
{'fraction_non_alphanumeric': 0.11958443854995579, 'fraction_numerical': 0.014367816091954023, 'mean_word_length': 3.8971861471861473, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1867355', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1439, 'n_words': 420}