1 /*************************************************************************
\r
3 * Licensed under the Apache License, Version 2.0 (the "License");
\r
4 * you may not use this file except in compliance with the License.
\r
5 * You may obtain a copy of the License at
\r
7 * http://www.apache.org/licenses/LICENSE-2.0
\r
9 * Unless required by applicable law or agreed to in writing, software
\r
10 * distributed under the License is distributed on an "AS IS" BASIS,
\r
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 * See the License for the specific language governing permissions and
\r
13 * limitations under the License.
\r
14 ***************************************************************************/
\r
20 #include "regxstring.h"
\r
22 using namespace std;
\r
24 static string trim(std::string str){
\r
25 size_t i = 0,e = str.length();
\r
26 for(;i < e && std::isspace(str[i]);++i);
\r
28 for(;j > i && std::isspace(str[j - 1]);--j);
\r
29 return (i < j ? str.substr(i,j - i) : "");
\r
32 static string pre_handle(const string & str)
\r
34 string ret = trim(str);
\r
37 ret.insert(ret.begin(),'^');
\r
40 if(ret[ret.size() - 1] != '$') {
\r
47 static void rand_init(void) {
\r
49 FILE* urandom = fopen("/dev/urandom", "r");
\r
50 size_t ret = fread(&seed, sizeof(int), 1, urandom);
\r
57 int main(int argc, const char ** argv)
\r
59 CRegxString regxstr;
\r
69 int pseudo_seed = 0;
\r
73 pseudo_seed += argv[1][i] - '0';
\r
77 srandom(pseudo_seed);
\r
82 regxstr.ParseRegx(pre_handle(regx).c_str());
\r
83 cout << regxstr.RandString() << endl;
\r