Changeset 22fe2438b98e2d041b4481c0c8706096a8f160ce
- Timestamp:
- 05/24/08 11:40:57
(3 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1211622057 +0300
- git-parent:
[05cfa654a872bd3b6dc8123cc736110d3d022b20]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1211622057 +0300
- Message:
Simplify, fix and inline strcasecmp and strncasecmp
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r287081c |
r22fe243 |
|
| 729 | 729 | VLC_EXPORT( int, vlc_alphasort, ( const struct dirent **a, const struct dirent **b ) ); |
|---|
| 730 | 730 | |
|---|
| 731 | | VLC_EXPORT( int, vlc_strcasecmp, ( const char *s1, const char *s2 ) ); |
|---|
| 732 | | VLC_EXPORT( int, vlc_strncasecmp, ( const char *s1, const char *s2, size_t n ) ); |
|---|
| 733 | 731 | VLC_EXPORT( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) ); |
|---|
| 734 | 732 | |
|---|
| r287081c |
r22fe243 |
|
| 118 | 118 | #ifndef HAVE_STRCASECMP |
|---|
| 119 | 119 | # ifndef HAVE_STRICMP |
|---|
| 120 | | # define strcasecmp vlc_strcasecmp |
|---|
| | 120 | # include <ctype.h> |
|---|
| | 121 | static inline int strcasecmp (const char *s1, const char *s2) |
|---|
| | 122 | { |
|---|
| | 123 | for (size_t i = 0;; i++) |
|---|
| | 124 | { |
|---|
| | 125 | int d = tolower (s1[i]) - tolower (s2[i]); |
|---|
| | 126 | if (d) return d; |
|---|
| | 127 | } |
|---|
| | 128 | return 0; |
|---|
| | 129 | } |
|---|
| 121 | 130 | # else |
|---|
| 122 | 131 | # define strcasecmp stricmp |
|---|
| … | … | |
| 126 | 135 | #ifndef HAVE_STRNCASECMP |
|---|
| 127 | 136 | # ifndef HAVE_STRNICMP |
|---|
| 128 | | # define strncasecmp vlc_strncasecmp |
|---|
| | 137 | # include <ctype.h> |
|---|
| | 138 | static inline int strncasecmp (const char *s1, const char *s2, size_t n) |
|---|
| | 139 | { |
|---|
| | 140 | for (size_t i = 0; i < n; i++) |
|---|
| | 141 | { |
|---|
| | 142 | int d = tolower (s1[i]) - tolower (s2[i]); |
|---|
| | 143 | if (d) return d; |
|---|
| | 144 | } |
|---|
| | 145 | return 0; |
|---|
| | 146 | } |
|---|
| 129 | 147 | # else |
|---|
| 130 | 148 | # define strncasecmp strnicmp |
|---|
| r287081c |
r22fe243 |
|
| 75 | 75 | #endif |
|---|
| 76 | 76 | |
|---|
| 77 | | /***************************************************************************** |
|---|
| 78 | | * strcasecmp: compare two strings ignoring case |
|---|
| 79 | | *****************************************************************************/ |
|---|
| 80 | | #if !defined( HAVE_STRCASECMP ) && !defined( HAVE_STRICMP ) |
|---|
| 81 | | int vlc_strcasecmp( const char *s1, const char *s2 ) |
|---|
| 82 | | { |
|---|
| 83 | | int c1, c2; |
|---|
| 84 | | if( !s1 || !s2 ) return -1; |
|---|
| 85 | | |
|---|
| 86 | | while( *s1 && *s2 ) |
|---|
| 87 | | { |
|---|
| 88 | | c1 = tolower(*s1); |
|---|
| 89 | | c2 = tolower(*s2); |
|---|
| 90 | | |
|---|
| 91 | | if( c1 != c2 ) return (c1 < c2 ? -1 : 1); |
|---|
| 92 | | s1++; s2++; |
|---|
| 93 | | } |
|---|
| 94 | | |
|---|
| 95 | | if( !*s1 && !*s2 ) return 0; |
|---|
| 96 | | else return (*s1 ? 1 : -1); |
|---|
| 97 | | } |
|---|
| 98 | | #endif |
|---|
| 99 | | |
|---|
| 100 | | /***************************************************************************** |
|---|
| 101 | | * strncasecmp: compare n chars from two strings ignoring case |
|---|
| 102 | | *****************************************************************************/ |
|---|
| 103 | | #if !defined( HAVE_STRNCASECMP ) && !defined( HAVE_STRNICMP ) |
|---|
| 104 | | int vlc_strncasecmp( const char *s1, const char *s2, size_t n ) |
|---|
| 105 | | { |
|---|
| 106 | | int c1, c2; |
|---|
| 107 | | if( !s1 || !s2 ) return -1; |
|---|
| 108 | | |
|---|
| 109 | | while( n > 0 && *s1 && *s2 ) |
|---|
| 110 | | { |
|---|
| 111 | | c1 = tolower(*s1); |
|---|
| 112 | | c2 = tolower(*s2); |
|---|
| 113 | | |
|---|
| 114 | | if( c1 != c2 ) return (c1 < c2 ? -1 : 1); |
|---|
| 115 | | s1++; s2++; n--; |
|---|
| 116 | | } |
|---|
| 117 | | |
|---|
| 118 | | if( !n || (!*s1 && !*s2) ) return 0; |
|---|
| 119 | | else return (*s1 ? 1 : -1); |
|---|
| 120 | | } |
|---|
| 121 | | #endif |
|---|
| 122 | | |
|---|
| 123 | 77 | /****************************************************************************** |
|---|
| 124 | 78 | * strcasestr: find a substring (little) in another substring (big) |
|---|
| r287081c |
r22fe243 |
|
| 439 | 439 | vlc_sdp_Start |
|---|
| 440 | 440 | vlc_sendmsg |
|---|
| 441 | | vlc_strcasecmp |
|---|
| 442 | 441 | vlc_strcasestr |
|---|
| 443 | 442 | vlc_strlcpy |
|---|
| 444 | | vlc_strncasecmp |
|---|
| 445 | 443 | vlc_strtoll |
|---|
| 446 | 444 | vlc_submodule_create |
|---|