substext: pass margin and font to regions
[vlc.git] / include / vlc_strings.h
blob9828fbd728ee791d409568405f280634132b91a6
1 /*****************************************************************************
2 * vlc_strings.h: String functions
3 *****************************************************************************
4 * Copyright (C) 2006 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Antoine Cellerier <dionoea at videolan dot org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_STRINGS_H
25 #define VLC_STRINGS_H 1
27 /**
28 * \defgroup strings String helpers
29 * @{
30 * \file
31 * Helper functions for nul-terminated strings
34 static inline int vlc_ascii_toupper( int c )
36 if ( c >= 'a' && c <= 'z' )
37 return c + ( 'A' - 'a' );
38 else
39 return c;
42 static inline int vlc_ascii_tolower( int c )
44 if ( c >= 'A' && c <= 'Z' )
45 return c + ( 'a' - 'A' );
46 else
47 return c;
50 /**
51 * Compare two ASCII strings ignoring case.
53 * The result is independent of the locale. If there are non-ASCII
54 * characters in the strings, their cases are NOT ignored in the
55 * comparison.
57 static inline int vlc_ascii_strcasecmp( const char *psz1, const char *psz2 )
59 const char *s1 = psz1;
60 const char *s2 = psz2;
61 int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
62 while ( *s1 && d == 0)
64 s1++;
65 s2++;
66 d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
69 return d;
72 static inline int vlc_ascii_strncasecmp( const char *psz1, const char *psz2, size_t n )
74 const char *s1 = psz1;
75 const char *s2 = psz2;
76 const char *s1end = psz1 + n;
77 int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
78 while ( *s1 && s1 < s1end && d == 0)
80 s1++;
81 s2++;
82 d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
85 if (s1 == s1end)
86 return 0;
87 else
88 return d;
91 /**
92 * Decodes XML entities.
94 * Decodes a null-terminated UTF-8 string of XML character data into a regular
95 * nul-terminated UTF-8 string. In other words, replaces XML entities and
96 * numerical character references with the corresponding characters.
98 * This function operates in place (the output is always of smaller or equal
99 * length than the input) and always succeeds.
101 * \param str null-terminated string [IN/OUT]
103 VLC_API void vlc_xml_decode(char *st);
106 * Encodes XML entites.
108 * Substitutes unsafe characters in a null-terminated UTF-8 strings with an
109 * XML entity or numerical character reference.
111 * \param str null terminated UTF-8 string
112 * \return On success, a heap-allocated null-terminated string is returned.
113 * If the input string was not a valid UTF-8 sequence, NULL is returned and
114 * errno is set to EILSEQ.
115 * If there was not enough memory, NULL is returned and errno is to ENOMEM.
117 VLC_API char *vlc_xml_encode(const char *str) VLC_MALLOC;
119 VLC_API char * vlc_b64_encode_binary( const uint8_t *, size_t );
120 VLC_API char * vlc_b64_encode( const char * );
122 VLC_API size_t vlc_b64_decode_binary_to_buffer( uint8_t *p_dst, size_t i_dst_max, const char *psz_src );
123 VLC_API size_t vlc_b64_decode_binary( uint8_t **pp_dst, const char *psz_src );
124 VLC_API char * vlc_b64_decode( const char *psz_src );
127 * Convenience wrapper for strftime().
129 * Formats the current time into a heap-allocated string.
131 * @param tformat time format (as with C strftime())
132 * @return an allocated string (must be free()'d), or NULL on memory error.
134 VLC_API char *vlc_strftime( const char * );
137 * Formats input meta-data.
139 * Formats input and input item meta-informations into a heap-allocated string.
141 VLC_API char *vlc_strfinput( input_thread_t *, const char * );
143 static inline char *str_format( input_thread_t *input, const char *fmt )
145 char *s1 = vlc_strftime( fmt );
146 char *s2 = vlc_strfinput( input, s1 );
147 free( s1 );
148 return s2;
151 VLC_API int vlc_filenamecmp(const char *, const char *);
153 void filename_sanitize(char *);
156 * @}
159 #endif