strilib.c
来自「在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LE」· C语言 代码 · 共 137 行
C
137 行
/*
* FILENAME: strilib.c
*
* Copyright 1998- 2000 By InterNiche Technologies Inc. All rights reserved
*
* The file contains source for Common but not quite
* universal C library string functions. These are used by the http
* server, emailer, and perhaps others. This file has implementation
* for three functions, each of which can be enabled at compile time
* with a switch. INICHE_STRICMP enables stricmp() INICHE_STRNICMP
* enables strnicmp() INICHE_STRISTR enables stristr()
* Created for minimal C lib support.
*
* MODULE: MISCLIB
*
* ROUTINES: stricmp(), strnicmp(), stristr(),
*
* PORTABLE: yes
*/
/* Additional Copyrights: */
/* Portions Copyright 1993 by NetPort software John Bartas 12/2/99 - Added
* stristr(). Atul
*/
#include "in_utils.h"
#ifdef INICHE_STRICMP /* bring in stricmp() */
int strnicmp(char * s1, char * s2, int len); /* forward decl. */
/* FUNCTION: stricmp()
*
* stricmp() - string compare which ignores case. Returns 0 if
* strings match.
*
*
* PARAM1: char * s1
* PARAM2: char * s2
*
* RETURNS:
*/
int
stricmp(char * s1, char * s2)
{
int l1, l2;
l1 = strlen(s1); /* get both lengths */
l2 = strlen(s2);
/* call strnicmp with maximum length */
return( strnicmp(s1, s2, ( l1 > l2 )?l1:l2 ));
}
#endif /* INICHE_STRICMP */
#ifdef INICHE_STRNICMP /* bring in strnicmp() */
/* FUNCTION: strnicmp()
*
* strnicmp() - string compare which ignores case but limits compare
* size. Returns 0 if strings match.
*
*
* PARAM1: char * s1
* PARAM2: char * s2
* PARAM3: int len
*
* RETURNS:
*/
int
strnicmp(char * s1, char * s2, int len)
{
char c1, c2;
while (len--)
{
c1 = (char)((*s1++) & ~0x20);
c2 = (char)((*s2++) & ~0x20);
if (c1 == c2)
{
if (c1 == 0) /* end of both strings */
return 0; /* they match */
continue; /* check next char */
}
else if(c1 < c2)
return -1;
else /* c1 > c2 */
return 1;
}
return 0;
}
#endif /* INICHE_STRICMP */
#ifdef INICHE_STRISTR /* bring in stricmp() */
/* FUNCTION: stristr()
*
* stristr(str1, str2) - look for str2 (case insensitive) inside str1
*
* PARAM1: char * str1
* PARAM2: char * str2
*
* RETURNS:
*/
char *
stristr(char * str1, char * str2)
{
char c1, c2;
c1 = (char)((*str2) & ~0x20); /* 1st char of sub-string in upper case */
while (*str1)
{
c2 = (char)((*str1) & ~0x20); /* c1=toupper(*str2) */
if (c1 == c2) /* found first char of str2 in str1 */
{
if (strnicmp(str1, str2, strlen(str2)) == 0)
{
return str1; /* found str2 at str1 */
}
}
str1++;
}
return (char*)0;
}
#endif /* INICHE_STRISTR */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?