Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1736175

Browse files
committed
remove tab vs. space inconsistencies (whitespace only change)
1 parent 9dc0436 commit 1736175

File tree

5 files changed

+256
-256
lines changed

5 files changed

+256
-256
lines changed

example/generate_image.cpp

Lines changed: 147 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -35,175 +35,175 @@ using namespace ZXing;
3535

3636
static void PrintUsage(const char* exePath)
3737
{
38-
std::cout << "Usage: " << exePath << " [-size <width>x<height>] [-margin <margin>] [-encoding <encoding>] [-ecc <level>] <format> <text> <output>" << std::endl
39-
<< " -size Size of generated image" << std::endl
40-
<< " -margin Margin around barcode" << std::endl
41-
<< " -encoding Encoding used to encode input text" << std::endl
42-
<< " -ecc Error correction level, [0-8]"
43-
<< std::endl
44-
<< "Supported formats are:" << std::endl
45-
<< " AZTEC" << std::endl
46-
<< " CODABAR" << std::endl
47-
<< " CODE_39" << std::endl
48-
<< " CODE_93" << std::endl
49-
<< " CODE_128" << std::endl
50-
<< " DATA_MATRIX" << std::endl
51-
<< " EAN_8" << std::endl
52-
<< " EAN_13" << std::endl
53-
<< " ITF" << std::endl
54-
<< " PDF_417" << std::endl
55-
<< " QR_CODE" << std::endl
56-
<< " UPC_A" << std::endl
57-
<< " UPC_E" << std::endl
58-
<< "Formats can be lowercase letters, with or without underscore." << std::endl;
38+
std::cout << "Usage: " << exePath << " [-size <width>x<height>] [-margin <margin>] [-encoding <encoding>] [-ecc <level>] <format> <text> <output>" << std::endl
39+
<< " -size Size of generated image" << std::endl
40+
<< " -margin Margin around barcode" << std::endl
41+
<< " -encoding Encoding used to encode input text" << std::endl
42+
<< " -ecc Error correction level, [0-8]"
43+
<< std::endl
44+
<< "Supported formats are:" << std::endl
45+
<< " AZTEC" << std::endl
46+
<< " CODABAR" << std::endl
47+
<< " CODE_39" << std::endl
48+
<< " CODE_93" << std::endl
49+
<< " CODE_128" << std::endl
50+
<< " DATA_MATRIX" << std::endl
51+
<< " EAN_8" << std::endl
52+
<< " EAN_13" << std::endl
53+
<< " ITF" << std::endl
54+
<< " PDF_417" << std::endl
55+
<< " QR_CODE" << std::endl
56+
<< " UPC_A" << std::endl
57+
<< " UPC_E" << std::endl
58+
<< "Formats can be lowercase letters, with or without underscore." << std::endl;
5959
}
6060

6161
static std::string FormatClean(std::string str)
6262
{
63-
std::transform(str.begin(), str.end(), str.begin(), [](char c) { return (char)std::tolower(c); });
64-
str.erase(std::remove(str.begin(), str.end(), '_'), str.end());
65-
return str;
63+
std::transform(str.begin(), str.end(), str.begin(), [](char c) { return (char)std::tolower(c); });
64+
str.erase(std::remove(str.begin(), str.end(), '_'), str.end());
65+
return str;
6666
}
6767

6868
static std::string ParseFormat(std::string str)
6969
{
70-
str = FormatClean(str);
71-
for (int i = 0; i < (int)BarcodeFormat::FORMAT_COUNT; ++i) {
72-
auto standardForm = ToString((BarcodeFormat)i);
73-
if (str == FormatClean(standardForm))
74-
return standardForm;
75-
}
76-
return std::string();
70+
str = FormatClean(str);
71+
for (int i = 0; i < (int)BarcodeFormat::FORMAT_COUNT; ++i) {
72+
auto standardForm = ToString((BarcodeFormat)i);
73+
if (str == FormatClean(standardForm))
74+
return standardForm;
75+
}
76+
return std::string();
7777
}
7878

7979
static bool ParseSize(std::string str, int* width, int* height)
8080
{
81-
std::transform(str.begin(), str.end(), str.begin(), [](char c) { return (char)std::tolower(c); });
82-
auto xPos = str.find('x');
83-
if (xPos != std::string::npos) {
84-
*width = std::stoi(str.substr(0, xPos));
85-
*height = std::stoi(str.substr(xPos + 1));
86-
return true;
87-
}
88-
return false;
81+
std::transform(str.begin(), str.end(), str.begin(), [](char c) { return (char)std::tolower(c); });
82+
auto xPos = str.find('x');
83+
if (xPos != std::string::npos) {
84+
*width = std::stoi(str.substr(0, xPos));
85+
*height = std::stoi(str.substr(xPos + 1));
86+
return true;
87+
}
88+
return false;
8989
}
9090

9191
static bool ParseOptions(int argc, char* argv[], int* width, int* height, int* margin, int* eccLevel, std::string* format, std::string* text, std::string* filePath)
9292
{
93-
int nonOptArgCount = 0;
94-
for (int i = 1; i < argc; ++i) {
95-
if (strcmp(argv[i], "-size") == 0) {
96-
if (i + 1 < argc) {
97-
++i;
98-
if (!ParseSize(argv[i], width, height)) {
99-
std::cerr << "Invalid size specification: " << argv[i] << std::endl;
100-
return false;
101-
}
102-
}
103-
else {
104-
return false;
105-
}
106-
}
107-
else if (strcmp(argv[i], "-margin") == 0) {
108-
if (i + 1 < argc) {
109-
++i;
110-
*margin = std::stoi(argv[i]);
111-
}
112-
else {
113-
return false;
114-
}
115-
}
116-
else if (strcmp(argv[i], "-ecc") == 0) {
117-
if (i + 1 < argc) {
118-
++i;
119-
*eccLevel = std::stoi(argv[i]);
120-
}
121-
else {
122-
return false;
123-
}
124-
}
125-
else if (nonOptArgCount == 0) {
126-
*format = ParseFormat(argv[i]);
127-
if (format->empty()) {
128-
std::cerr << "Unreconigned format: " << argv[i] << std::endl;
129-
return false;
130-
}
131-
++nonOptArgCount;
132-
}
133-
else if (nonOptArgCount == 1) {
134-
*text = argv[i];
135-
++nonOptArgCount;
136-
}
137-
else if (nonOptArgCount == 2) {
138-
*filePath = argv[i];
139-
++nonOptArgCount;
140-
}
141-
else {
142-
return false;
143-
}
144-
}
145-
146-
return !format->empty() && !text->empty() && !filePath->empty();
93+
int nonOptArgCount = 0;
94+
for (int i = 1; i < argc; ++i) {
95+
if (strcmp(argv[i], "-size") == 0) {
96+
if (i + 1 < argc) {
97+
++i;
98+
if (!ParseSize(argv[i], width, height)) {
99+
std::cerr << "Invalid size specification: " << argv[i] << std::endl;
100+
return false;
101+
}
102+
}
103+
else {
104+
return false;
105+
}
106+
}
107+
else if (strcmp(argv[i], "-margin") == 0) {
108+
if (i + 1 < argc) {
109+
++i;
110+
*margin = std::stoi(argv[i]);
111+
}
112+
else {
113+
return false;
114+
}
115+
}
116+
else if (strcmp(argv[i], "-ecc") == 0) {
117+
if (i + 1 < argc) {
118+
++i;
119+
*eccLevel = std::stoi(argv[i]);
120+
}
121+
else {
122+
return false;
123+
}
124+
}
125+
else if (nonOptArgCount == 0) {
126+
*format = ParseFormat(argv[i]);
127+
if (format->empty()) {
128+
std::cerr << "Unreconigned format: " << argv[i] << std::endl;
129+
return false;
130+
}
131+
++nonOptArgCount;
132+
}
133+
else if (nonOptArgCount == 1) {
134+
*text = argv[i];
135+
++nonOptArgCount;
136+
}
137+
else if (nonOptArgCount == 2) {
138+
*filePath = argv[i];
139+
++nonOptArgCount;
140+
}
141+
else {
142+
return false;
143+
}
144+
}
145+
146+
return !format->empty() && !text->empty() && !filePath->empty();
147147
}
148148

149149
static std::string GetExtension(const std::string& path)
150150
{
151-
auto fileNameStart = path.find_last_of("/\\");
152-
auto fileName = fileNameStart == std::string::npos ? path : path.substr(fileNameStart + 1);
153-
auto extStart = fileName.find_last_of('.');
154-
auto ext = extStart == std::string::npos ? "" : fileName.substr(extStart + 1);
155-
std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c) { return std::tolower(c); });
156-
return ext;
151+
auto fileNameStart = path.find_last_of("/\\");
152+
auto fileName = fileNameStart == std::string::npos ? path : path.substr(fileNameStart + 1);
153+
auto extStart = fileName.find_last_of('.');
154+
auto ext = extStart == std::string::npos ? "" : fileName.substr(extStart + 1);
155+
std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c) { return std::tolower(c); });
156+
return ext;
157157
}
158158

159159
int main(int argc, char* argv[])
160160
{
161-
if (argc <= 2) {
162-
PrintUsage(argv[0]);
163-
return 0;
164-
}
165-
166-
int width = 100, height = 100;
167-
int margin = 10;
168-
int eccLevel = -1;
169-
std::string format, text, filePath;
170-
171-
if (!ParseOptions(argc, argv, &width, &height, &margin, &eccLevel, &format, &text, &filePath)) {
172-
PrintUsage(argv[0]);
173-
return -1;
174-
}
175-
176-
try {
177-
auto barcodeFormat = BarcodeFormatFromString(format);
178-
if (barcodeFormat == BarcodeFormat::FORMAT_COUNT)
179-
throw std::invalid_argument("Unsupported format: " + format);
180-
181-
MultiFormatWriter writer(barcodeFormat);
182-
if (margin >= 0)
183-
writer.setMargin(margin);
184-
if (eccLevel >= 0)
185-
writer.setEccLevel(eccLevel);
186-
187-
auto bitmap = writer.encode(TextUtfEncoding::FromUtf8(text), width, height).toByteMatrix();
188-
189-
auto ext = GetExtension(filePath);
190-
int success = 0;
191-
if (ext == "" || ext == "png") {
192-
success = stbi_write_png(filePath.c_str(), bitmap.width(), bitmap.height(), 1, bitmap.data(), 0);
193-
}
194-
else if (ext == "jpg" || ext == "jpeg") {
195-
success = stbi_write_jpg(filePath.c_str(), bitmap.width(), bitmap.height(), 1, bitmap.data(), 0);
196-
}
197-
198-
if (!success) {
199-
std::cerr << "Failed to write image: " << filePath << std::endl;
200-
return -1;
201-
}
202-
}
203-
catch (const std::exception& e) {
204-
std::cerr << e.what() << std::endl;
205-
return -1;
206-
}
207-
208-
return 0;
161+
if (argc <= 2) {
162+
PrintUsage(argv[0]);
163+
return 0;
164+
}
165+
166+
int width = 100, height = 100;
167+
int margin = 10;
168+
int eccLevel = -1;
169+
std::string format, text, filePath;
170+
171+
if (!ParseOptions(argc, argv, &width, &height, &margin, &eccLevel, &format, &text, &filePath)) {
172+
PrintUsage(argv[0]);
173+
return -1;
174+
}
175+
176+
try {
177+
auto barcodeFormat = BarcodeFormatFromString(format);
178+
if (barcodeFormat == BarcodeFormat::FORMAT_COUNT)
179+
throw std::invalid_argument("Unsupported format: " + format);
180+
181+
MultiFormatWriter writer(barcodeFormat);
182+
if (margin >= 0)
183+
writer.setMargin(margin);
184+
if (eccLevel >= 0)
185+
writer.setEccLevel(eccLevel);
186+
187+
auto bitmap = writer.encode(TextUtfEncoding::FromUtf8(text), width, height).toByteMatrix();
188+
189+
auto ext = GetExtension(filePath);
190+
int success = 0;
191+
if (ext == "" || ext == "png") {
192+
success = stbi_write_png(filePath.c_str(), bitmap.width(), bitmap.height(), 1, bitmap.data(), 0);
193+
}
194+
else if (ext == "jpg" || ext == "jpeg") {
195+
success = stbi_write_jpg(filePath.c_str(), bitmap.width(), bitmap.height(), 1, bitmap.data(), 0);
196+
}
197+
198+
if (!success) {
199+
std::cerr << "Failed to write image: " << filePath << std::endl;
200+
return -1;
201+
}
202+
}
203+
catch (const std::exception& e) {
204+
std::cerr << e.what() << std::endl;
205+
return -1;
206+
}
207+
208+
return 0;
209209
}

example/scan_image.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ using namespace ZXing;
3131
static void PrintUsage(const char* exePath)
3232
{
3333
std::cout << "Usage: " << exePath << " [-fast] [-rotate] [-format <FORMAT>] <png image path>\n"
34-
<< " -fast Do not try harder to detect, thus faster\n"
35-
<< " -rotate Try to rotate image of 90 degrees if it fails to detect barcode\n"
36-
<< " -format Try to read given format only. Supported formats are:\n";
34+
<< " -fast Do not try harder to detect, thus faster\n"
35+
<< " -rotate Try to rotate image of 90 degrees if it fails to detect barcode\n"
36+
<< " -format Try to read given format only. Supported formats are:\n";
3737
for (int i = 0; i < (int)BarcodeFormat::FORMAT_COUNT; ++i) {
3838
std::cout << " " << ToString((BarcodeFormat)i) << "\n";
3939
}
@@ -121,8 +121,8 @@ int main(int argc, char* argv[])
121121

122122
if (result.isValid()) {
123123
std::cout << "Text: " << TextUtfEncoding::ToUtf8(result.text()) << "\n"
124-
<< "Format: " << ToString(result.format()) << "\n"
125-
<< "Position: " << result.resultPoints() << "\n";
124+
<< "Format: " << ToString(result.format()) << "\n"
125+
<< "Position: " << result.resultPoints() << "\n";
126126
auto errLevel = result.metadata().getString(ResultMetadata::Key::ERROR_CORRECTION_LEVEL);
127127
if (!errLevel.empty()) {
128128
std::cout << "EC Level: " << TextUtfEncoding::ToUtf8(errLevel) << "\n";

test/blackbox/TestWriterMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ using namespace std::literals;
3030

3131
void savePng(const BitMatrix& matrix, BarcodeFormat format)
3232
{
33-
auto bitmap = matrix.toByteMatrix();
34-
stbi_write_png((ToString(format) + ".png"s).c_str(), bitmap.width(), bitmap.height(), 1, bitmap.data(), 0);
33+
auto bitmap = matrix.toByteMatrix();
34+
stbi_write_png((ToString(format) + ".png"s).c_str(), bitmap.width(), bitmap.height(), 1, bitmap.data(), 0);
3535
}
3636

3737
int main()

0 commit comments

Comments
 (0)