Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/jit/jit-util.c  view on Meta::CPAN

/*@
 * @deftypefun int jit_strcmp (const char *@var{str1}, const char *@var{str2})
 * Compare the two strings @var{str1} and @var{str2}, returning
 * a negative, zero, or positive value depending upon their relationship.
 * @end deftypefun
@*/
int jit_strcmp(const char *str1, const char *str2)
{
#ifdef HAVE_STRCMP
	return strcmp(str1, str2);
#else
	int ch1, ch2;
	for(;;)
	{
		ch1 = *str1++;
		ch2 = *str2++;
		if(ch1 != ch2 || !ch1 || !ch2)
		{
			break;
		}
	}
	return (ch1 - ch2);
#endif
}

/*@
 * @deftypefun int jit_strncmp (const char *@var{str1}, const char *@var{str2}, unsigned int @var{len})
 * Compare the two strings @var{str1} and @var{str2}, returning
 * a negative, zero, or positive value depending upon their relationship.
 * At most @var{len} characters are compared.
 * @end deftypefun
@*/
int jit_strncmp(const char *str1, const char *str2, unsigned int len)
{
#ifdef HAVE_STRNCMP
	return strncmp(str1, str2, len);
#else
	int ch1, ch2;
	while(len > 0)
	{
		ch1 = *str1++;
		ch2 = *str2++;
		if(ch1 != ch2 || !ch1 || !ch2)
		{
			return (ch1 - ch2);
		}
		--len;
	}
	return 0;
#endif
}

/*@
 * @deftypefun int jit_stricmp (const char *@var{str1}, const char *@var{str2})
 * Compare the two strings @var{str1} and @var{str2}, returning
 * a negative, zero, or positive value depending upon their relationship.
 * Instances of the English letters A to Z are converted into their
 * lower case counterparts before comparison.
 *
 * Note: this function is guaranteed to use English case comparison rules,
 * no matter what the current locale is set to, making it suitable for
 * comparing token tags and simple programming language identifiers.
 *
 * Locale-sensitive string comparison is complicated and usually specific
 * to the front end language or its supporting runtime library.  We
 * deliberately chose not to handle this in @code{libjit}.
 * @end deftypefun
@*/
int jit_stricmp(const char *str1, const char *str2)
{
	int ch1, ch2;
	for(;;)
	{
		ch1 = *str1++;
		ch2 = *str2++;
		if(ch1 >= 'A' && ch1 <= 'Z')
		{
			ch1 = ch1 - 'A' + 'a';
		}
		if(ch2 >= 'A' && ch2 <= 'Z')
		{
			ch2 = ch2 - 'A' + 'a';
		}
		if(ch1 != ch2 || !ch1 || !ch2)
		{
			break;
		}
	}
	return (ch1 - ch2);
}

/*@
 * @deftypefun int jit_strnicmp (const char *@var{str1}, const char *@var{str2}, unsigned int @var{len})
 * Compare the two strings @var{str1} and @var{str2}, returning
 * a negative, zero, or positive value depending upon their relationship.
 * At most @var{len} characters are compared.  Instances of the English
 * letters A to Z are converted into their lower case counterparts
 * before comparison.
 * @end deftypefun
@*/
int jit_strnicmp(const char *str1, const char *str2, unsigned int len)
{
	int ch1, ch2;
	while(len > 0)
	{
		ch1 = *str1++;
		ch2 = *str2++;
		if(ch1 >= 'A' && ch1 <= 'Z')
		{
			ch1 = ch1 - 'A' + 'a';
		}
		if(ch2 >= 'A' && ch2 <= 'Z')
		{
			ch2 = ch2 - 'A' + 'a';
		}
		if(ch1 != ch2 || !ch1 || !ch2)
		{
			return (ch1 - ch2);
		}
		--len;
	}



( run in 0.421 second using v1.01-cache-2.11-cpan-5735350b133 )