summaryrefslogtreecommitdiff
path: root/src/libaudcore/audstrings.h
blob: de47590e3d02223172a04d7f68f0a2b2ea6aba84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * audstrings.h
 * Copyright 2009-2012 John Lindgren and William Pitcock
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions, and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions, and the following disclaimer in the documentation
 *    provided with the distribution.
 *
 * This software is provided "as is" and without any warranty, express or
 * implied. In no event shall the authors be liable for any damages arising from
 * the use of this software.
 */

#ifndef LIBAUDCORE_STRINGS_H
#define LIBAUDCORE_STRINGS_H

#include <stdarg.h>
#include <stdint.h>

#include <initializer_list>

#include <libaudcore/index.h>
#include <libaudcore/objects.h>

int strcmp_safe (const char * a, const char * b, int len = -1);
int strcmp_nocase (const char * a, const char * b, int len = -1);
int strlen_bounded (const char * s, int len = -1);

StringBuf str_copy (const char * s, int len = -1);
StringBuf str_concat (const std::initializer_list<const char *> & strings);
StringBuf str_printf (const char * format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
StringBuf str_vprintf (const char * format, va_list args);

bool str_has_prefix_nocase (const char * str, const char * prefix);
bool str_has_suffix_nocase (const char * str, const char * suffix);

unsigned str_calc_hash (const char * str);

const char * strstr_nocase (const char * haystack, const char * needle);
const char * strstr_nocase_utf8 (const char * haystack, const char * needle);

static inline char * strstr_nocase (char * haystack, const char * needle)
    { return (char *) strstr_nocase ((const char *) haystack, needle); }
static inline char * strstr_nocase_utf8 (char * haystack, const char * needle)
    { return (char *) strstr_nocase_utf8 ((const char *) haystack, needle); }

StringBuf str_tolower (const char * str);
StringBuf str_tolower_utf8 (const char * str);

void str_replace_char (char * string, char old_c, char new_c);

StringBuf str_decode_percent (const char * str, int len = -1);
StringBuf str_encode_percent (const char * str, int len = -1);

StringBuf str_convert (const char * str, int len, const char * from_charset, const char * to_charset);
StringBuf str_from_locale (const char * str, int len = -1);
StringBuf str_to_locale (const char * str, int len = -1);

/* Requires: aud_init() */
StringBuf str_to_utf8 (const char * str, int len); // no "len = -1" to avoid ambiguity
StringBuf str_to_utf8 (StringBuf && str);

StringBuf filename_normalize (StringBuf && filename);
StringBuf filename_get_parent (const char * filename);
StringBuf filename_get_base (const char * filename);
StringBuf filename_build (const std::initializer_list<const char *> & elems);
StringBuf filename_to_uri (const char * filename);
StringBuf uri_to_filename (const char * uri, bool use_locale = true);
StringBuf uri_to_display (const char * uri);

void uri_parse (const char * uri, const char * * base_p, const char * * ext_p,
 const char * * sub_p, int * isub_p);

StringBuf uri_get_scheme (const char * uri);
StringBuf uri_get_extension (const char * uri);

/* Requires: aud_init() */
StringBuf uri_construct (const char * path, const char * reference);

int str_compare (const char * a, const char * b);
int str_compare_encoded (const char * a, const char * b);

Index<String> str_list_to_index (const char * list, const char * delims);
StringBuf index_to_str_list (const Index<String> & index, const char * sep);

int str_to_int (const char * string);
double str_to_double (const char * string);
StringBuf int_to_str (int val);
StringBuf double_to_str (double val);

bool str_to_int_array (const char * string, int * array, int count);
StringBuf int_array_to_str (const int * array, int count);
bool str_to_double_array (const char * string, double * array, int count);
StringBuf double_array_to_str (const double * array, int count);

/* Requires: aud_init() */
StringBuf str_format_time (int64_t milliseconds);

#endif /* LIBAUDCORE_STRINGS_H */