diff options
| author | Shawn O. Pearce <spearce@spearce.org> | 2008-12-31 14:35:39 -0800 |
|---|---|---|
| committer | Shawn O. Pearce <spearce@spearce.org> | 2008-12-31 14:35:39 -0800 |
| commit | 9eb7976448bf684dfb41993ef6c76098978ff933 (patch) | |
| tree | 9ae72bd6780d6cd354719a1d84120e0690ffb5a7 /src/util.c | |
| parent | 8ed341c55ed4d6f4cdc8bf4f0ca18a08c93f6962 (diff) | |
| download | libgit2-9eb7976448bf684dfb41993ef6c76098978ff933.tar.gz | |
Add string utility functions for prefix and suffix compares
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 64b5d4fbe..feb1bd8ab 100644 --- a/src/util.c +++ b/src/util.c @@ -24,3 +24,23 @@ char *git__strdup(const char *s) return git_ptr_error(GIT_ENOMEM); return r; } + +int git__prefixcmp(const char *str, const char *prefix) +{ + for (;;) { + char p = *(prefix++), s; + if (!p) + return 0; + if ((s = *(str++)) != p) + return s - p; + } +} + +int git__suffixcmp(const char *str, const char *suffix) +{ + size_t a = strlen(str); + size_t b = strlen(suffix); + if (a < b) + return -1; + return strcmp(str + (a - b), suffix); +} |
