[vlc-commits] Locale independent, case-ignoring ASCII string comparison functions
Antti Ajanki
git at videolan.org
Sat Jul 26 10:37:34 CEST 2014
vlc | branch: master | Antti Ajanki <antti.ajanki at iki.fi> | Fri Jul 25 12:05:00 2014 +0300| [da7bfe4df15163c99e024f2cd540551f605eeb0c] | committer: Rémi Denis-Courmont
Locale independent, case-ignoring ASCII string comparison functions
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=da7bfe4df15163c99e024f2cd540551f605eeb0c
---
include/vlc_strings.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/include/vlc_strings.h b/include/vlc_strings.h
index 3ce4884..2170c24 100644
--- a/include/vlc_strings.h
+++ b/include/vlc_strings.h
@@ -34,6 +34,63 @@
* @{
*/
+static inline int vlc_ascii_toupper( int c )
+{
+ if ( c >= 'a' && c <= 'z' )
+ return c + ( 'A' - 'a' );
+ else
+ return c;
+}
+
+static inline int vlc_ascii_tolower( int c )
+{
+ if ( c >= 'A' && c <= 'Z' )
+ return c + ( 'a' - 'A' );
+ else
+ return c;
+}
+
+/**
+ * Compare two ASCII strings ignoring case.
+ *
+ * The result is independent of the locale. If there are non-ASCII
+ * characters in the strings, their cases are NOT ignored in the
+ * comparison.
+ */
+static inline int vlc_ascii_strcasecmp( const char *psz1, const char *psz2 )
+{
+ const char *s1 = psz1;
+ const char *s2 = psz2;
+ int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
+ while ( *s1 && d == 0)
+ {
+ s1++;
+ s2++;
+ d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
+ }
+
+ return d;
+}
+
+static inline int vlc_ascii_strncasecmp( const char *psz1, const char *psz2, size_t n )
+{
+ const char *s1 = psz1;
+ const char *s2 = psz2;
+ const char *s1end = psz1 + n;
+ int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
+ while ( *s1 && s1 < s1end && d == 0)
+ {
+ s1++;
+ s2++;
+ d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
+ }
+
+ if (s1 == s1end)
+ return 0;
+ else
+ return d;
+}
+
VLC_API void resolve_xml_special_chars( char *psz_value );
VLC_API char * convert_xml_special_chars( const char *psz_content );
More information about the vlc-commits
mailing list