-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdlib.h> | ||
|
||
#include <string.h> | ||
#include <ctype.h> | ||
|
||
#include "filesystem.h" | ||
#include "guess_uri_type.h" | ||
|
||
int guess_uri_type(const char* const something) { | ||
|
||
int status = 0; | ||
|
||
const unsigned char a = something[0]; | ||
const unsigned char b = something[1]; | ||
|
||
if (strncmp(something, "https://", 8) == 0 || strncmp(something, "http://", 7) == 0) { | ||
return GUESS_URI_TYPE_URL; | ||
} | ||
|
||
status = ( | ||
(a == '.' && (b == '/' || b == '\\')) || (isalpha(a) && b == ':') || (a == '/' || a == '\\') | ||
); | ||
|
||
if (!status) { | ||
status = file_exists(something); | ||
} | ||
|
||
if (status) { | ||
return GUESS_URI_TYPE_LOCAL_FILE; | ||
} | ||
|
||
return GUESS_URI_TYPE_SOMETHING_ELSE; | ||
|
||
} |
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,10 @@ | ||
#if !defined(GUESS_URI_TYPE_H) | ||
#define GUESS_URI_TYPE_H | ||
|
||
#define GUESS_URI_TYPE_URL 0x01 | ||
#define GUESS_URI_TYPE_LOCAL_FILE 0x02 | ||
#define GUESS_URI_TYPE_SOMETHING_ELSE 0x03 | ||
|
||
int guess_uri_type(const char* const something); | ||
|
||
#endif |