Upstream | cc2ee17 | 1970-01-12 13:46:40 +0000 | [diff] [blame^] | 1 | /** |
| 2 | * @file op_string.c |
| 3 | * general purpose C string handling implementation. |
| 4 | * |
| 5 | * @remark Copyright 2003 OProfile authors |
| 6 | * @remark Read the file COPYING |
| 7 | * |
| 8 | * @author John Levon |
| 9 | * @author Philippe Elie |
| 10 | */ |
| 11 | |
| 12 | #include <string.h> |
| 13 | #include "op_libiberty.h" |
| 14 | |
| 15 | |
| 16 | char * op_xstrndup(char const * s, size_t len) |
| 17 | { |
| 18 | return xmemdup(s, len, len + 1); |
| 19 | } |
| 20 | |
| 21 | |
| 22 | size_t op_hash_string(char const * str) |
| 23 | { |
| 24 | size_t hash = 0; |
| 25 | for (; *str; ++str) |
| 26 | hash ^= (hash << 16) ^ (hash >> 8) ^ *str; |
| 27 | return hash; |
| 28 | } |
| 29 | |
| 30 | |
| 31 | int strisprefix(char const * str, char const * prefix) |
| 32 | { |
| 33 | return strstr(str, prefix) == str; |
| 34 | } |
| 35 | |
| 36 | |
| 37 | char const * skip_ws(char const * c) |
| 38 | { |
| 39 | while (*c == ' ' || *c == '\t' || *c == '\n') |
| 40 | ++c; |
| 41 | return c; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | char const * skip_nonws(char const * c) |
| 46 | { |
| 47 | while (*c && *c != ' ' && *c != '\t' && *c != '\n') |
| 48 | ++c; |
| 49 | return c; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | int empty_line(char const * c) |
| 54 | { |
| 55 | return !*skip_ws(c); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | int comment_line(char const * c) |
| 60 | { |
| 61 | return *skip_ws(c) == '#'; |
| 62 | } |