Skip to content

Commit 15082f1

Browse files
Three stamps for renerating plain text
These three stamps generate plain text. First stamp just gives a sequence of character with no structure at all Second stamp adds spaces in such sequence now and then Third stamp generate sequence of random words taken from dictionary
1 parent 385f6fa commit 15082f1

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

blobstamper/stamp_dict.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,10 @@ class StampDict: public StampBaseStr
4747
int maxSize() override {return stamp_size;}
4848
};
4949

50+
class StampDictLCAlphaSmall : public StampDict
51+
{
52+
public:
53+
StampDictLCAlphaSmall (): StampDict(std::make_shared<DictLCAlphaSmall>()) {};
54+
};
55+
5056
#endif /* STAMP_DICT_H */

blobstamper/stamp_text.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/******************************************************************************
2+
*
3+
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
******************************************************************************/
18+
19+
#include"stamp_text.h"
20+
21+
std::string
22+
StampTextPulp::ExtractStr(Blob &blob)
23+
{
24+
25+
std::vector<char> data = blob.ChopBlank(*this);
26+
27+
std::vector<char>::iterator the_iterator;
28+
29+
the_iterator = data.begin();
30+
std:: string res;
31+
while (the_iterator != data.end())
32+
{
33+
if (*the_iterator == '\0') { *the_iterator = ' '; }
34+
res.push_back(*the_iterator++);
35+
}
36+
37+
return res;
38+
}
39+
40+
std::string StampTextPulpWords::ExtractStr(Blob &blob)
41+
{
42+
std::vector<std::string> data = ExtractStrVector(blob);
43+
std::string res = "";
44+
45+
for(std::string s : data)
46+
{
47+
if (!res.empty())
48+
{
49+
res+=" ";
50+
}
51+
res+= s;
52+
}
53+
return res;
54+
}
55+
56+
std::string StampTextDictWords::ExtractStr(Blob &blob)
57+
{
58+
std::vector<std::string> data = ExtractStrVector(blob);
59+
std::string res = "";
60+
61+
for(std::string s : data)
62+
{
63+
if (!res.empty())
64+
{
65+
res+=" ";
66+
}
67+
res+= s;
68+
}
69+
return res;
70+
}
71+

blobstamper/stamp_text.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/******************************************************************************
2+
*
3+
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
******************************************************************************/
18+
19+
#ifndef STAMP_TEXT_H
20+
#define STAMP_TEXT_H
21+
22+
23+
#include "galley.h"
24+
25+
#include "stamp_dict.h"
26+
27+
class StampTextPulp: public StampBaseStr
28+
{
29+
public:
30+
virtual int minSize() override {return 1;}
31+
virtual int maxSize() override {return -1;}
32+
std::string ExtractStr(Blob &blob) override;
33+
};
34+
35+
class StampTextPulpWords: public GalleyVectorStrStampBase<StampTextPulp>
36+
{
37+
public:
38+
virtual std::string ExtractStr(Blob &blob) override;
39+
};
40+
41+
class StampTextDictWords: public GalleyVectorStrStampBase<StampDictLCAlphaSmall>
42+
{
43+
public:
44+
virtual std::string ExtractStr(Blob &blob) override;
45+
};
46+
47+
#endif /* STAMP_TEXT_H */

t/150-stamp_text.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/******************************************************************************
2+
*
3+
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
******************************************************************************/
18+
19+
#include <string.h>
20+
21+
#include <exception>
22+
#include <string>
23+
#include <cstdlib>
24+
#define WANT_TEST_EXTRAS
25+
#include <tap++/tap++.h>
26+
27+
#include "blobstamper/stamp_text.h"
28+
29+
using namespace TAP;
30+
31+
int
32+
main()
33+
{
34+
TEST_START(3);
35+
{ /* 1..1 */
36+
char data[] = "папа\0мама\0бабушка\0дедушка\0братик\0сестричка";
37+
Blob blob(data, (sizeof data)-1);
38+
StampTextPulp stamp;
39+
std::string s = stamp.ExtractStr(blob);
40+
is(s, "папа мама бабушка дедушка братик сестричка", "StampTextSimple");
41+
42+
}
43+
{ /* 2..2 */
44+
char data[] = "dad\0mam\0granddad\0grandmam\0brother\0sister";
45+
Blob blob(data, (sizeof data)-1);
46+
StampTextPulpWords stamp;
47+
std::string s = stamp.ExtractStr(blob);
48+
is(s, "d dad gra n dmam broth er siste", "GalleyTextSimple");
49+
50+
}
51+
{ /* 3..3 */
52+
char data[] = "abcdef" "abcdef" "ABCDEF" "012345";
53+
Blob blob(data, (sizeof data)-1);
54+
StampTextDictWords stamp;
55+
std::string s = stamp.ExtractStr(blob);
56+
is(s, "gleam godfather graffiti greened grouping gunshots gleam godfather graffiti greened grouping gunshots dismally dissented divested doorstep dread drunks convertors corpulent counterparts cranking crippled crusades", "GalleyLCAlphaSmall");
57+
58+
}
59+
TEST_END;
60+
}

0 commit comments

Comments
 (0)