blob: d4402997d672e423b4abc153b303d84884daed75 [file] [log] [blame]
The Android Open Source Project10e23ee2009-03-03 19:30:30 -08001/**
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
16char * op_xstrndup(char const * s, size_t len)
17{
18 return xmemdup(s, len, len + 1);
19}
20
21
22size_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
31int strisprefix(char const * str, char const * prefix)
32{
33 return strstr(str, prefix) == str;
34}
35
36
37char const * skip_ws(char const * c)
38{
39 while (*c == ' ' || *c == '\t' || *c == '\n')
40 ++c;
41 return c;
42}
43
44
45char const * skip_nonws(char const * c)
46{
47 while (*c && *c != ' ' && *c != '\t' && *c != '\n')
48 ++c;
49 return c;
50}
51
52
53int empty_line(char const * c)
54{
55 return !*skip_ws(c);
56}
57
58
59int comment_line(char const * c)
60{
61 return *skip_ws(c) == '#';
62}