diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2021-08-31 22:01:34 -0400 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-09-01 20:40:19 -0400 |
| commit | 9e98e443ca5e95bfb570536187c6e155bc126e59 (patch) | |
| tree | d1eccc035814b3628a795c4d0fcc058fd76f60ab /src | |
| parent | e5ba0a3c37a5a1a24f1904d56ebf8d30df9df75f (diff) | |
| download | libgit2-9e98e443ca5e95bfb570536187c6e155bc126e59.tar.gz | |
url: introduce `git_net_url_matches_pattern_list`
Provide a utility method on a url to determine if it matches any pattern
in a comma-separated list, similar to what one would find in `NO_PROXY`
environment variables.
Diffstat (limited to 'src')
| -rw-r--r-- | src/net.c | 19 | ||||
| -rw-r--r-- | src/net.h | 3 |
2 files changed, 22 insertions, 0 deletions
@@ -459,6 +459,25 @@ bool git_net_url_matches_pattern(git_net_url *url, const char *pattern) return matches_pattern(url, pattern, strlen(pattern)); } +bool git_net_url_matches_pattern_list( + git_net_url *url, + const char *pattern_list) +{ + const char *pattern, *pattern_end, *sep; + + for (pattern = pattern_list; + pattern && *pattern; + pattern = sep ? sep + 1 : NULL) { + sep = strchr(pattern, ','); + pattern_end = sep ? sep : strchr(pattern, '\0'); + + if (matches_pattern(url, pattern, (pattern_end - pattern))) + return true; + } + + return false; +} + void git_net_url_dispose(git_net_url *url) { if (url->username) @@ -58,6 +58,9 @@ extern int git_net_url_fmt_path(git_buf *buf, git_net_url *url); extern bool git_net_url_matches_pattern( git_net_url *url, const char *pattern); +extern bool git_net_url_matches_pattern_list( + git_net_url *url, + const char *pattern_list); /** Disposes the contents of the structure. */ extern void git_net_url_dispose(git_net_url *url); |
