1 /** 2 * @file op_string.h 3 * general purpose C string handling declarations. 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 #ifndef OP_STRING_H 13 #define OP_STRING_H 14 15 #include <string.h> 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /** 22 * @param s: input string 23 * @param len: len char to copy 24 * 25 * Allocate and copy len character from s to a newly allocated buffer then 26 * append a '\0' terminator. Return the newly allocated string 27 */ 28 char * op_xstrndup(char const * s, size_t len); 29 30 /** 31 * @param s: string to hash 32 * 33 * Generate a hash code from a string 34 */ 35 size_t op_hash_string(char const * s); 36 37 /** 38 * @param str: string to test 39 * @param prefix: prefix string 40 * 41 * return non zero if prefix parameters is a prefix of str 42 */ 43 int strisprefix(char const * str, char const * prefix); 44 45 /** 46 * @param c: input string 47 * 48 * return a pointer to the first location in c which is not a blank space 49 * where blank space are in " \t\n" 50 */ 51 char const * skip_ws(char const * c); 52 53 /** 54 * @param c: input string 55 * 56 * return a pointer to the first location in c which is a blank space 57 * where blank space are in " \t\n" 58 */ 59 char const * skip_nonws(char const * c); 60 61 /** 62 * @param c: input string 63 * 64 * return non zero if c string contains only blank space 65 * where blank space are in " \t\n" 66 */ 67 int empty_line(char const * c); 68 69 /** 70 * @param c: input string 71 * 72 * return non zero if c string is a comment. Comment are lines with optional 73 * blank space at left then a '#' character. Blank space are in " \t\n" 74 */ 75 int comment_line(char const * c); 76 77 #ifdef __cplusplus 78 } 79 #endif 80 81 #endif /* !OP_STRING_H */ 82