1
// Copyright 2008 The RE2 Authors. All Rights Reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// String generator: generates all possible strings of up to
6
// maxlen letters using the set of letters in alpha.
7
// Fetch strings using a Java-like Next()/HasNext() interface.
9
#ifndef RE2_TESTING_STRING_GENERATOR_H__
10
#define RE2_TESTING_STRING_GENERATOR_H__
14
#include "util/util.h"
15
#include "util/random.h"
16
#include "re2/stringpiece.h"
20
class StringGenerator {
22
StringGenerator(int maxlen, const vector<string>& alphabet);
24
const StringPiece& Next();
25
bool HasNext() { return hasnext_; }
27
// Resets generator to start sequence over.
30
// Causes generator to emit random strings for next n calls to Next().
31
void Random(int32 seed, int n);
33
// Causes generator to emit a NULL as the next call.
37
bool IncrementDigits();
41
int maxlen_; // Maximum length string to generate.
42
vector<string> alphabet_; // Alphabet, one string per letter.
45
StringPiece sp_; // Last StringPiece returned by Next().
46
string s_; // String data in last StringPiece returned by Next().
47
bool hasnext_; // Whether Next() can be called again.
48
vector<int> digits_; // Alphabet indices for next string.
49
bool generate_null_; // Whether to generate a NULL StringPiece next.
50
bool random_; // Whether generated strings are random.
51
int nrandom_; // Number of random strings left to generate.
52
ACMRandom* acm_; // Random number generator
53
DISALLOW_EVIL_CONSTRUCTORS(StringGenerator);
58
#endif // RE2_TESTING_STRING_GENERATOR_H__