Skip to content

Commit ae62881

Browse files
committed
Created macros for each attribute separators (properties, file extensions, inverse, class, exists, pattern)
1 parent cc064f7 commit ae62881

File tree

3 files changed

+100
-52
lines changed

3 files changed

+100
-52
lines changed

include/shellanything/Validator.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@
3030
#include <string>
3131
#include <vector>
3232

33+
#define SA_DEFAULT_ATTRIBUTE_SEPARATOR_CHAR ';'
34+
#define SA_DEFAULT_ATTRIBUTE_SEPARATOR_STR ";"
35+
#define SA_PROPERTIES_ATTR_SEPARATOR_CHAR SA_DEFAULT_ATTRIBUTE_SEPARATOR_CHAR
36+
#define SA_PROPERTIES_ATTR_SEPARATOR_STR SA_DEFAULT_ATTRIBUTE_SEPARATOR_STR
37+
#define SA_FILEEXTENSION_ATTR_SEPARATOR_CHAR SA_DEFAULT_ATTRIBUTE_SEPARATOR_CHAR
38+
#define SA_FILEEXTENSION_ATTR_SEPARATOR_STR SA_DEFAULT_ATTRIBUTE_SEPARATOR_STR
39+
#define SA_INVERSE_ATTR_SEPARATOR_CHAR SA_DEFAULT_ATTRIBUTE_SEPARATOR_CHAR
40+
#define SA_INVERSE_ATTR_SEPARATOR_STR SA_DEFAULT_ATTRIBUTE_SEPARATOR_STR
41+
#define SA_CLASS_ATTR_SEPARATOR_CHAR SA_DEFAULT_ATTRIBUTE_SEPARATOR_CHAR
42+
#define SA_CLASS_ATTR_SEPARATOR_STR SA_DEFAULT_ATTRIBUTE_SEPARATOR_STR
43+
#define SA_EXISTS_ATTR_SEPARATOR_CHAR SA_DEFAULT_ATTRIBUTE_SEPARATOR_CHAR
44+
#define SA_EXISTS_ATTR_SEPARATOR_STR SA_DEFAULT_ATTRIBUTE_SEPARATOR_STR
45+
#define SA_PATTERN_ATTR_SEPARATOR_CHAR SA_DEFAULT_ATTRIBUTE_SEPARATOR_CHAR
46+
#define SA_PATTERN_ATTR_SEPARATOR_STR SA_DEFAULT_ATTRIBUTE_SEPARATOR_STR
47+
3348
namespace shellanything
3449
{
3550

src/Validator.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ namespace shellanything
193193
if (pos + name_length < mInverse.size())
194194
next = mInverse[pos + name_length];
195195

196-
if (next == '\0' || next == ';')
196+
if (next == '\0' || next == SA_INVERSE_ATTR_SEPARATOR_CHAR)
197197
{
198198
// Good. Keep looking
199199

@@ -203,11 +203,11 @@ namespace shellanything
203203
if (pos == 0)
204204
return true; // We have a match!
205205

206-
char previous = ';';
206+
char previous = SA_INVERSE_ATTR_SEPARATOR_CHAR;
207207
if (pos >= 1)
208208
previous = mInverse[pos - 1];
209209

210-
if (previous == ';')
210+
if (previous == SA_INVERSE_ATTR_SEPARATOR_CHAR)
211211
return true; // We have a match!
212212
}
213213

@@ -307,7 +307,7 @@ namespace shellanything
307307
PropertyManager & pmgr = PropertyManager::GetInstance();
308308

309309
//split
310-
ra::strings::StringVector property_list = ra::strings::Split(properties, ";");
310+
ra::strings::StringVector property_list = ra::strings::Split(properties, SA_PROPERTIES_ATTR_SEPARATOR_STR);
311311

312312
//each property specified must exists and be non-empty
313313
for(size_t i=0; i<property_list.size(); i++)
@@ -345,7 +345,7 @@ namespace shellanything
345345
PropertyManager & pmgr = PropertyManager::GetInstance();
346346

347347
//split
348-
ra::strings::StringVector accepted_file_extensions = ra::strings::Split(file_extensions, ";");
348+
ra::strings::StringVector accepted_file_extensions = ra::strings::Split(file_extensions, SA_FILEEXTENSION_ATTR_SEPARATOR_STR);
349349
Uppercase(accepted_file_extensions);
350350

351351
//for each file selected
@@ -374,7 +374,7 @@ namespace shellanything
374374
PropertyManager & pmgr = PropertyManager::GetInstance();
375375

376376
//split
377-
ra::strings::StringVector mandatory_files = ra::strings::Split(file_exists, ";");
377+
ra::strings::StringVector mandatory_files = ra::strings::Split(file_exists, SA_EXISTS_ATTR_SEPARATOR_STR);
378378

379379
//for each file
380380
for(size_t i=0; i<mandatory_files.size(); i++)
@@ -448,7 +448,7 @@ namespace shellanything
448448
return true;
449449

450450
//split
451-
ra::strings::StringVector classes = ra::strings::Split(class_, ";");
451+
ra::strings::StringVector classes = ra::strings::Split(class_, SA_CLASS_ATTR_SEPARATOR_STR);
452452

453453
bool valid = false;
454454
for (size_t i = 0; i < classes.size(); i++)
@@ -468,7 +468,7 @@ namespace shellanything
468468
PropertyManager & pmgr = PropertyManager::GetInstance();
469469

470470
//split
471-
ra::strings::StringVector classes = ra::strings::Split(class_, ";");
471+
ra::strings::StringVector classes = ra::strings::Split(class_, SA_CLASS_ATTR_SEPARATOR_STR);
472472

473473
// Search for file extensions. All file extensions must be extracted from the list and evaluated all at once.
474474
std::string file_extensions;
@@ -495,7 +495,7 @@ namespace shellanything
495495

496496
// Add to the file extension list
497497
if (!file_extensions.empty())
498-
file_extensions.insert(0, 1, ';');
498+
file_extensions.insert(0, 1, SA_CLASS_ATTR_SEPARATOR_CHAR);
499499
file_extensions.insert(0, file_extension.c_str());
500500

501501
found_file_extensions = true;
@@ -525,7 +525,7 @@ namespace shellanything
525525
if (!classes.empty())
526526
{
527527
//join remaining classes into a single string
528-
std::string classes_str = ra::strings::Join(classes, ";");
528+
std::string classes_str = ra::strings::Join(classes, SA_CLASS_ATTR_SEPARATOR_STR);
529529

530530
//for each file selected
531531
const Context::ElementList & context_elements = context.GetElements();
@@ -565,7 +565,7 @@ namespace shellanything
565565
PropertyManager & pmgr = PropertyManager::GetInstance();
566566

567567
//split
568-
ra::strings::StringVector patterns = ra::strings::Split(pattern, ";");
568+
ra::strings::StringVector patterns = ra::strings::Split(pattern, SA_PATTERN_ATTR_SEPARATOR_STR);
569569
Uppercase(patterns);
570570

571571
//for each file selected

0 commit comments

Comments
 (0)