diff options
Diffstat (limited to 'common/str.cpp')
| -rw-r--r-- | common/str.cpp | 36 | 
1 files changed, 33 insertions, 3 deletions
diff --git a/common/str.cpp b/common/str.cpp index c21e4412db..740e7b6a06 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -17,9 +17,6 @@   * You should have received a copy of the GNU General Public License   * along with this program; if not, write to the Free Software   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$   */  #include "common/str.h" @@ -836,3 +833,36 @@ size_t strlcat(char *dst, const char *src, size_t size) {  }  }	// End of namespace Common + +// Portable implementation of stricmp / strcasecmp / strcmpi. +// TODO: Rename this to Common::strcasecmp +int scumm_stricmp(const char *s1, const char *s2) { +	byte l1, l2; +	do { +		// Don't use ++ inside tolower, in case the macro uses its +		// arguments more than once. +		l1 = (byte)*s1++; +		l1 = tolower(l1); +		l2 = (byte)*s2++; +		l2 = tolower(l2); +	} while (l1 == l2 && l1 != 0); +	return l1 - l2; +} + +// Portable implementation of strnicmp / strncasecmp / strncmpi. +// TODO: Rename this to Common::strncasecmp +int scumm_strnicmp(const char *s1, const char *s2, uint n) { +	byte l1, l2; +	do { +		if (n-- == 0) +			return 0;	// no difference found so far -> signal equality + +		// Don't use ++ inside tolower, in case the macro uses its +		// arguments more than once. +		l1 = (byte)*s1++; +		l1 = tolower(l1); +		l2 = (byte)*s2++; +		l2 = tolower(l2); +	} while (l1 == l2 && l1 != 0); +	return l1 - l2; +}  | 
