📄 liustrg.cpp
字号:
/* lilStatus FNC (INT32) = 0, pasStr1 = pasStr2 */
/* < 0, pasStr1 < pasStr2 */
/* > 0, pasStr1 > pasStr2 */
/* */
/*\p*******************************************************************/
INT32 LIUstrncmpi
/* Compare strings, case-insensitive */
(
const CHAR *pasStr1,
const CHAR *pasStr2,
INT32 pasNum
)
{
/*******************************************************************/
/* Local Variable Declarations */
/*******************************************************************/
INT32 lilIndex, lilMaxIndex;
INT32 lilStatus;
INT32 lilStrlen1;
INT32 lilStrlen2;
/*******************************************************************/
/* Procedure Body */
/*******************************************************************/
if ((pasStr1 == NULL) || (pasStr2 == NULL))
{
lilStatus = FAILED_;
#ifdef LIU_USE_ERA
ERAerrorLog("LIUstrncmpi", "Input strings are equal to NULL");
#endif
}
else
{
lilIndex = 0;
lilStatus = 0;
lilStrlen1 = strlen (pasStr1);
lilStrlen2 = strlen (pasStr2);
if (lilStrlen1 > lilStrlen2)
lilMaxIndex = lilStrlen2;
else
lilMaxIndex = lilStrlen1;
if (lilMaxIndex > pasNum)
lilMaxIndex = pasNum;
while ( (lilIndex < lilMaxIndex) &&
(tolower (pasStr1 [(int)lilIndex]) ==
tolower (pasStr2 [(int)lilIndex])) )
lilIndex++;
if (lilIndex == lilMaxIndex)
{
if (pasNum > lilMaxIndex)
{
if (lilStrlen1 != lilStrlen2)
{
if (lilStrlen1 < lilStrlen2)
{
--lilStatus;
}
else
{
++lilStatus;
}
}
}
}
else
{
if (tolower (pasStr1 [(int)lilIndex]) < tolower (pasStr2 [(int)lilIndex]) )
--lilStatus;
else
++lilStatus;
}
}
return (lilStatus);
} /* end of function LIUstrncmpi */
/*\p*******************************************************************/
/* */
/* NAME: LIUstrstri */
/* */
/* PURPOSE: */
/* Case insensitive LIUstrstr. */
/* */
/* SAMPLE CALL: */
/* */
/* subStrPtr = LIUstrstri (strPtr1, strPtr2); */
/* */
/* INTERFACE DEFINITION: */
/* variable def. expected/description */
/* ------------ ----- ------------------------------------- */
/* pasStr1 PAS String to be searched. */
/* pasStr2 PAS String to be matched. */
/* lilPtr FNC (INT8 *) pointer to substring match. */
/* NULL if no match. */
/* */
/*\p*******************************************************************/
CHAR *LIUstrstri /* Find substring within string */
(
const CHAR *pasStr1,
const CHAR *pasStr2
)
{
/*******************************************************************/
/* Local Variable Declarations */
/*******************************************************************/
CHAR *lilPtr;
INT32 lilStr2Len;
/*******************************************************************/
/* Procedure Body */
/*******************************************************************/
if ((pasStr1 == NULL) || (pasStr2 == NULL))
{
lilPtr = NULL;
#ifdef LIU_USE_ERA
ERAerrorLog("LIUstrstri", "Input strings are equal to NULL.");
#endif
}
else
{
lilStr2Len = strlen (pasStr2);
lilPtr = (CHAR *)pasStr1;
while ((lilPtr != NULL) &&
(LIUstrncmpi (lilPtr, pasStr2, lilStr2Len) != 0))
lilPtr = LIUstrchri (++lilPtr, pasStr2[0] );
} /* end if - else */
return (lilPtr);
} /* end of function LIUstrstri */
/*\p*******************************************************************/
/* */
/* NAME: LIUstrchri */
/* */
/* PURPOSE: */
/* Case-insensitive strchr. */
/* */
/* */
/* SAMPLE CALL: */
/* */
/* lilStr = LIUstrchri (strPtr1, strPtr2); */
/* */
/* INTERFACE DEFINITION: */
/* variable def. expected/description */
/* ------------ ----- ------------------------------------- */
/* pasStr PAS String to be searched. */
/* pasChar PAS Character to search for. */
/* lilStr FNC (CHAR *) Location in search string of */
/* first occurence of pasChar or NULL. */
/* */
/*\p*******************************************************************/
CHAR *LIUstrchri
/* case-insensitive strchr */
(const CHAR *pasStr,
CHAR pasChar)
{
/*******************************************************************/
/* Local Variable Declarations */
/*******************************************************************/
CHAR *lilStrPtr;
CHAR lilChar;
/*******************************************************************/
/* Procedure Body */
/*******************************************************************/
lilStrPtr = NULL;
if (pasStr == NULL)
{
#ifdef LIU_USE_ERA
ERAerrorLog("LIUstrchri", "Input string is equal to NULL");
#endif
}
else
{
lilChar = tolower (pasChar);
lilStrPtr = (CHAR *)pasStr;
while ((*lilStrPtr != '\0') && (tolower(*lilStrPtr) != lilChar))
lilStrPtr++;
if (!(*lilStrPtr)) lilStrPtr = NULL;
}
return (lilStrPtr);
} /* end of function LIUstrchri */
/*\p********************************************************************
** **
** **
NAME: LIUstripLeadingBlanks
PURPOSE: to remove any leading blanks from the referenced
string. This includes all blanks, new lines, carriage
returns, and tab characters.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** lilErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE LIUstripLeadingBlanks
( CHAR *refStr )
{ /* LIUstripLeadingBlanks procedure */
/******************* Local Constant Declarations **********************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUstripLeadingBlanks";
#endif
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE lilErr;
CHAR *lilPtr;
/************************* Procedure Body *****************************/
lilErr = SUCCEEDED_;
if (refStr == NULL)
{
lilErr = FAILED_;
#ifdef LIU_USE_ERA
ERAerrorLog( LIL_PROC_NAME, "Bad string pointer");
#endif
}
else
{
lilErr = SUCCEEDED_;
lilPtr = refStr;
/**************************************************
* Skip over all leading blanks to find start of
* source string.
*/
while (LIUisWhiteSpace( *lilPtr ) ) lilPtr++;
/**************************************************
* If pointer to end of blanks is not equal to
* referenced string, then there are some
* blanks to skip. Copy from the skip pointer
* back to the referenced string up to and including
* the string terminator.
*/
if (lilPtr != refStr) /* Then leading blanks to nuke */
{
do
{
*refStr = *lilPtr;
refStr++;
lilPtr++;
}
while (*lilPtr != '\0');
*refStr = '\0';
}
}
return(lilErr);
} /* LIUstripLeadingBlanks end */
/*\p********************************************************************
** **
** **
NAME: LIUstripTrailingBlanks
PURPOSE: to strip all trailing blanks, if any, from the
referenced string. Simply convert all trailing blanks,
tabs, newlines, and/or carriage returns to null terminators
until some other character is encountered or the entire
string has been processed.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** lilErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE LIUstripTrailingBlanks
( CHAR *refStr )
{ /* LIUstripTrailingBlanks procedure */
/******************* Local Constant Declarations **********************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUstripTrailingBlanks";
#endif
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE lilErr;
CHAR *lilPtr;
/************************* Procedure Body *****************************/
lilErr = SUCCEEDED_;
if (refStr == NULL)
{
lilErr = FAILED_;
#ifdef LIU_USE_ERA
ERAerrorLog( LIL_PROC_NAME, "Null string pointer");
#endif
}
else
{
lilPtr = refStr;
lilPtr += strlen(refStr);
if (lilPtr != refStr) /* then nonzero length */
{
lilPtr--;
do
{
if (LIUisWhiteSpace( *lilPtr) )
{
*lilPtr = '\0';
lilPtr--;
}
}
while ((lilPtr >= refStr) && (LIUisWhiteSpace( *lilPtr )));
}
}
return(lilErr);
} /* LIUstripTrailingBlanks end */
/*\p********************************************************************
** **
** **
NAME: LIUstripLTblanks
PURPOSE: to strip leading and trailing blanks from a string.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** lilErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -