This repository has been archived by the owner on Jan 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds pattern matching to file extraction
- Loading branch information
1 parent
b5517c5
commit 279dba4
Showing
5 changed files
with
72 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "stringutils.h" | ||
|
||
int matchPattern(const char * pattern, const char * str) | ||
{ | ||
int p_offset = 0, s_offset = 0; | ||
char current_p_char = '\0', current_s_char = '\0', next_p_char = '\0'; | ||
|
||
while (str[s_offset] != '\0') { | ||
current_p_char = pattern[p_offset]; | ||
current_s_char = str[s_offset]; | ||
if (current_p_char == '*' && next_p_char == '\0') { | ||
next_p_char = pattern[p_offset+1]; | ||
} | ||
if (next_p_char != '\0') { | ||
if (current_s_char != next_p_char) { | ||
s_offset++; | ||
continue; | ||
} | ||
else { | ||
current_p_char = next_p_char; | ||
p_offset++; | ||
next_p_char = '\0'; | ||
} | ||
} | ||
if (current_p_char != current_s_char) return 1; | ||
|
||
s_offset++; | ||
p_offset++; | ||
} | ||
return (next_p_char != '\0'); | ||
} | ||
|
||
void cleanPath(char * path) | ||
{ | ||
for (int i = 0; path[i]; i++) { //replace all spaces and fat32 reserved characters in the path with underscores | ||
switch (path[i]) { | ||
case ' ': | ||
case '"': | ||
case '*': | ||
case ':': | ||
case '<': | ||
case '>': | ||
case '?': | ||
case '\\': | ||
case '|': | ||
path[i] = '_'; | ||
default: | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
#include "basic.h" | ||
|
||
int matchPattern(const char * pattern, const char * str); | ||
void cleanPath(char * path); |