📄 liustrg.cpp
字号:
if (pasShift < 0)
{
lilShf = -pasShift;
}
else
{
lilShf = pasShift;
}
lilT = lilShf + 1;
for (lili = 0; lili < lilLen; lili++)
{
lilStr2[(int)lili] = lilStr1[(int)lili];
}
for (lili = lilLen; lili < (lilLen + lilT); lili++)
{
lilStr2[(int)lili] = '0';
}
lilStr2[(int)lili] = '\0';
lilPos = lilT + lilLen - 1;
}
else
{
strcpy(lilStr2, lilStr1);
lilPos = strlen(lilStr2) - pasShift;
} /* end if-else-if */
/*************************************************************/
/* If the decimal point shift is not equal to zero then place*/
/* the decimal point at the appropriate place in the string. */
/* Otherwise leave the decimal point off. */
/*************************************************************/
if (pasShift != 0)
{
lilj = 0;
for (lili = 0; lili < (INT32)(strlen(lilStr2) + 1); lili++)
{
if (lili == lilPos)
{
refStr[(int)lili] = '.';
}
else
{
refStr[(int)lili] = lilStr2[(int)lilj];
lilj++;
} /* end if-else */
} /* end for */
}
else
{
lili = strlen(lilStr2) + 1;
strcpy(refStr, lilStr2);
} /* end if - else */
refStr[(int)lili] = '\0';
/****************************************************************/
/* If the string length is ok then return the string else pad */
/* the begining of the string with enough blank spaces to make */
/* up the requested final string length. */
/****************************************************************/
if ((INT32)strlen(refStr) == pasStrLen)
lilErr = SUCCEEDED_;
else
{
lilT = pasStrLen - strlen(refStr);
strcpy(lilStr2, refStr);
for (lili = 0; lili < lilT; lili++)
refStr[(int)lili] = ' ';
for (lili = lilT; lili < (lilT + strlen(lilStr2)); lili++)
refStr[(int)lili] = lilStr2[(int)(lili - lilT)];
refStr[(int)lili] = '\0';
lilErr = SUCCEEDED_;
} /* end if - else */
} /* end else */
} /* end else */
return(lilErr);
} /* end LIUintToString */
/*\p*******************************************************************/
/* */
/* NAME: LIUstrcmp */
/* and LIUstrcmpi */
/* */
/* PURPOSE: */
/* Case-sensitive followed by .. */
/* Case-insensitive comparison of two strings; works */
/* same as standard strcmp otherwise. */
/* */
/* */
/* SAMPLE CALL: */
/* */
/* lilErr = LIUstrcmpi (strPtr1, strPtr2); */
/* */
/* INTERFACE DEFINITION: */
/* variable def. expected/description */
/* ------------ ----- ------------------------------------- */
/* pasStr1 PAS String to be compared. */
/* pasStr2 PAS String to be compared. */
/* lilStatus FNC (INT32) = 0, pasStr1 = pasStr2 */
/* < 0, pasStr1 < pasStr2 */
/* > 0, pasStr1 > pasStr2 */
/* */
/*\p*******************************************************************/
INT32 LIUstrcmp // For completeness only
/* Compare strings, case-sensitive */
(
const CHAR *pasStr1,
const CHAR *pasStr2
)
{
return ((INT32)strcmp( (const char *)pasStr1, (const char *)pasStr2 ));
}
INT32 LIUstrcmpi
/* Compare strings, case-insensitive */
(
const CHAR *pasStr1,
const CHAR *pasStr2
)
{
/*******************************************************************/
/* Local Variable Declarations */
/*******************************************************************/
INT32 lilIndex, lilMaxIndex;
INT32 lilStatus;
/*******************************************************************/
/* Procedure Body */
/*******************************************************************/
if ((pasStr1 == NULL) || (pasStr2 == NULL))
{
lilStatus = FAILED_;
#ifdef LIU_USE_ERA
ERAerrorLog("LIUstrcmpi", "Input strings are equal to NULL");
#endif
}
else
{
lilIndex = 0;
lilStatus = 0;
lilMaxIndex = (INT32)strlen (pasStr1);
if ((INT32)strlen (pasStr2) < lilMaxIndex)
lilMaxIndex = strlen (pasStr2);
while ( (lilIndex < lilMaxIndex) &&
(tolower (pasStr1 [(int)lilIndex]) == tolower (pasStr2 [(int)lilIndex])) )
lilIndex++;
if (lilIndex == lilMaxIndex)
{
if (strlen(pasStr1) != strlen (pasStr2))
{
if ((INT32)strlen(pasStr1) == lilMaxIndex)
--lilStatus;
else
++lilStatus;
}
}
else
{
if (tolower (pasStr1 [(int)lilIndex]) < tolower (pasStr2 [(int)lilIndex]) )
--lilStatus;
else
++lilStatus;
}
}
return (lilStatus);
} /* end of function LIUstrcmpi */
/*\p*******************************************************************/
/* */
/* NAME: LIUstrstr */
/* */
/* PURPOSE: */
/* Returns pointer to a substring of pasStr1 that matches */
/* pasStr2; otherwise returns NULL */
/* */
/* SAMPLE CALL: */
/* */
/* subStrPtr = LIUstrstr (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 *LIUstrstr /* 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("LIUstrstr", "Input strings are equal to NULL.");
#endif
}
else
{
lilStr2Len = strlen (pasStr2);
lilPtr = (CHAR *)pasStr1;
while ((lilPtr != NULL) &&
(strncmp (lilPtr, pasStr2, (int)lilStr2Len) != 0))
lilPtr = strchr (++lilPtr, pasStr2 [0] );
} /* end if - else */
return (lilPtr);
} /* end of function LIUstrstr */
/*\p*******************************************************************/
/* */
/* NAME: LIUfindSubfield */
/* */
/* PURPOSE: to find out if the template that is passed in matches */
/* any of the subfield in the field that was passed in, */
/* and if so, which subfield. */
/* */
/* SAMPLE CALL: lilErr = LIUfindSubfield( lilField, */
/* "MY_TEMPLATE", &lilPos); */
/* */
/* INTERFACE DEFINITION: */
/* variable def. expected/description */
/* ------------ ----- ------------------------------------- */
/* pasListPtr PAS (CHAR *) points to a string containing */
/* substrings separated by a single NULL */
/* character. pasListPtr is double NULL */
/* terminated. (two consecutive NULL's) */
/* pasItemPtr PAS ptr to template string to search for */
/* refPosition REF subfield number (starting at 0) */
/* that matches the template. */
/* lilErr FNC (SUCCEEDED_ / FAILED_) error return */
/* */
/*\p*******************************************************************/
STAT_TYPE LIUfindSubfield
/* Get number of subfield matching template */
(
const CHAR *pasListPtr,
const CHAR *pasItemPtr,
INT32 *refPosition
)
{
/**********************************************************************/
/* Local Constant Declarations */
/**********************************************************************/
#ifdef LIU_USE_ERA
CHAR *LIL_PROC_NAME = "LIUfindSubfield";
#endif
/**********************************************************************/
/* Local Variable Declarations */
/**********************************************************************/
STAT_TYPE lilErr ;/* error return flag */
CHAR *lilSubfieldPtr ;/* current position in the passed field */
INT32 lilSubfieldLen ;/* length of current subfield */
INT32 lilI ;/* loop counter (='s current subfield) */
INT32 lilFound ;/* (T/F) has record been found? */
/**********************************************************************/
/* Procedure Body */
/**********************************************************************/
lilErr = SUCCEEDED_;
if ((pasListPtr == NULL) || (pasItemPtr == NULL) || (refPosition == NULL))
{
lilErr = FAILED_;
#ifdef LIU_USE_ERA
ERAparameterError( LIL_PROC_NAME );
#endif
}
else
{
lilSubfieldPtr = (CHAR *)pasListPtr ;
lilFound = FALSE_;
lilI = 0;
while (lilSubfieldPtr[0] != '\0')
{
/* find length of current subfield (including the NULL) */
lilSubfieldLen = (INT32)strlen( lilSubfieldPtr) + 1;
/* compare subfield to the template */
if (strncmp(pasItemPtr ,lilSubfieldPtr, (int)lilSubfieldLen) == 0)
{ /* then */
/* template has been found, note position, stop looping */
lilFound = TRUE_;
*refPosition = lilI;
lilSubfieldPtr = "\0";
}
else
{
/* go on looking in the remaining subfields */
lilI++;
lilSubfieldPtr += (int)lilSubfieldLen;
} /* endif */
} /* endwhile */
/* report status of search */
if (lilFound == TRUE_)
{ /* then */
lilErr = SUCCEEDED_;
}
else
{
lilErr = FAILED_;
} /* end else */
} /* end if - else */
return( lilErr);
} /* end LIUfindSubfield */
/*\p*******************************************************************/
/* */
/* NAME: LIUstrncmpi */
/* */
/* PURPOSE: */
/* Case-insensitive comparison of two strings; works */
/* same as standard strncmp otherwise. The maximum numbers of */
/* characters to compare is specified. */
/* */
/* SAMPLE CALL: */
/* */
/* lilErr = LIUstrncmpi (strPtr1, strPtr2, 30); */
/* */
/* INTERFACE DEFINITION: */
/* variable def. expected/description */
/* ------------ ----- ------------------------------------- */
/* pasStr1 PAS String to be compared. */
/* pasStr2 PAS String to be compared. */
/* pasNum PAS Number of characters to compare. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -