Handle streams separately in tree_add_track()
[cmus.git] / uchar.h
blob07870bd8c810d9ab53eb0ccb1eb6eb652420b175
1 /*
2 * Copyright 2004-2005 Timo Hirvonen
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
20 #ifndef _UCHAR_H
21 #define _UCHAR_H
23 typedef unsigned int uchar;
25 extern const char hex_tab[16];
28 * Invalid bytes are or'ed with this
29 * for example 0xff -> 0x100000ff
31 #define U_INVALID_MASK 0x10000000U
34 * @uch potential unicode character
36 * Returns 1 if @uch is valid unicode character, 0 otherwise
38 static inline int u_is_unicode(uchar uch)
40 return uch <= 0x0010ffffU;
44 * Returns size of @uch in bytes
46 static inline int u_char_size(uchar uch)
48 if (uch <= 0x0000007fU) {
49 return 1;
50 } else if (uch <= 0x000007ffU) {
51 return 2;
52 } else if (uch <= 0x0000ffffU) {
53 return 3;
54 } else if (uch <= 0x0010ffffU) {
55 return 4;
56 } else {
57 return 1;
62 * Returns width of @uch (normally 1 or 2, 4 for invalid chars (<xx>))
64 extern int u_char_width(uchar uch);
67 * @str any null-terminated string
69 * Returns 1 if @str is valid UTF-8 string, 0 otherwise.
71 extern int u_is_valid(const char *str);
74 * @str null-terminated UTF-8 string
76 * Retuns length of @str in UTF-8 characters.
78 extern int u_strlen(const char *str);
81 * @str null-terminated UTF-8 string
83 * Retuns width of @str.
85 extern int u_str_width(const char *str);
88 * @str null-terminated UTF-8 string
89 * @len number of characters to measure
91 * Retuns width of the first @len characters in @str.
93 extern int u_str_nwidth(const char *str, int len);
95 extern void u_prev_char_pos(const char *str, int *idx);
98 * @str null-terminated UTF-8 string
99 * @idx pointer to byte index in @str (not UTF-8 character index!)
100 * @uch pointer to returned unicode character
102 extern void u_get_char(const char *str, int *idx, uchar *uch);
105 * @str destination buffer
106 * @idx pointer to byte index in @str (not UTF-8 character index!)
107 * @uch unicode character
109 extern void u_set_char_raw(char *str, int *idx, uchar uch);
110 extern void u_set_char(char *str, int *idx, uchar uch);
113 * @dst destination buffer
114 * @src null-terminated UTF-8 string
115 * @width how much to copy
117 * Copies at most @count characters, less if null byte was hit.
118 * Null byte is _never_ copied.
119 * Actual width of copied characters is stored to @width.
121 * Returns number of _bytes_ copied.
123 extern int u_copy_chars(char *dst, const char *src, int *width);
126 * @str null-terminated UTF-8 string, must be long enough
127 * @width how much to skip
129 * Skips @count UTF-8 characters.
130 * Total width of skipped characters is stored to @width.
131 * Returned @width can be the given @width + 1 if the last skipped
132 * character was double width.
134 * Returns number of _bytes_ skipped.
136 extern int u_skip_chars(const char *str, int *width);
138 extern int u_strcasecmp(const char *a, const char *b);
139 extern int u_strncasecmp(const char *a, const char *b, int len);
140 extern char *u_strcasestr(const char *haystack, const char *needle);
142 static inline char *u_strcasestr_filename(const char *haystack, const char *needle)
144 return u_strcasestr(haystack, needle);
147 #endif