📄 liustrg.cpp
字号:
/*\t*******************************************************************/
/* Last Edited ......... 28-MAR-88 01:02:40 */
/* Filename ........... liuStrg.c */
/* Project ............. n/a */
/* Author ............. S. Balsarotti / B. Resnik / C. Strebel / */
/* S. Weidner / M. Ratcliff */
/* Drawing Number ..... */
/* Revision ........... */
/* Language ........... C */
/* Operating System ... n/a */
/* Processor .......... n/a */
/* Function: */
/* Tons of handy dandy string processing utilities. */
/* */
/*\t*******************************************************************/
/*\r*******************************************************************/
/* Revision History */
/**********************************************************************/
/*
Date By Change Description
dd-mmm-yy nnn text
--------- ---- -----------------------------------------------
22-DEC-88 SCB Standards Update
29-MAR-89 BPR More standards
21-JUL-89 SPT Moved LIUmatchesTemplate to the File Utils Mod.
21-AUG-89 MJE Fixed LIUreplaceChar to return error if input
string is NULL.
13-OCT-89 CES Updates hierarchy information and charts
30-OCT-89 MJE Updated module to reflect changes from code review.
29-JUN-90 BPR Added functions LIUstrstri, LIUstrncmpi, and
LIUstrchri.
Replaced "LIL_PROC_NAME" with LIL_PROC_NAME.
03-sep-91 bpr Replaced INT32 *pasNum with INT32 pasNum in
LIUstrncmpi
10-NOV-92 MJWR Added LIUstripTrailingBlanks and
LIUstripLeadingBlanks functions.
15-Feb-93 WV Added conditional compilation for include files.
25-JUN-93 MJWR Ported to C++/Windows environment.
17-Jun-94 MJWR Make ERAxxx compile time controlled
**\r*/
/*\i*******************************************************************/
/* Module Include Files */
/**********************************************************************/
/* System Include Files */
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <errno.h>
/* Constant Include Files */
#include "liidSys.h"
#include "erapdefs.h"
/* External Variable Include Files */
/***************** External Procedure Include Files *******************/
#include "erapRpt.h"
#include "liuStrg.h"
/*\i*/
/*\m*******************************************************************/
/* Module Declarations */
/**********************************************************************/
/* Module Constants */
/* Module Variables */
/* Module Procedure Declarations */
/*\m*/
/*\p*******************************************************************/
/* */
/* NAME: LIUmakeUppercase */
/* */
/* PURPOSE: Eliminate all lowercase characters from a string. */
/* */
/* */
/* SAMPLE CALL: lilErr = LIUmakeUppercase (inputStr, outputStr); */
/* */
/* */
/* INTERFACE DEFINITION: */
/* variable def. expected/description */
/* ------------ ----- ------------------------------------- */
/* pasInstringPtr PAS Input string */
/* */
/* refOutstringPtr REF Capitalized string */
/* */
/* lilErr FNC (SUCCEEDED_ / FAILED_) error return */
/* */
/*\p*******************************************************************/
STAT_TYPE LIUmakeUppercase
/* Copy string using all uppercase characters */
(
const CHAR *pasInstringPtr,
CHAR *refOutstringPtr
)
{ /* LIUmakeUppercase */
/**********************************************************************/
/* LOCAL CONSTANT DECLARATIONS */
/**********************************************************************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUmakeUppercase";
#endif
/**********************************************************************/
/* LOCAL VARIABLE DECLARATIONS */
/**********************************************************************/
STAT_TYPE lilErr;
INT32 lilLen;
INT32 lili;
CHAR lilch;
/**********************************************************************/
/* Procedure Body */
/**********************************************************************/
lilErr = SUCCEEDED_;
if (pasInstringPtr == NULL || refOutstringPtr == NULL)
{
lilErr = FAILED_;
#ifdef LIU_USE_ERA
ERAparameterError( LIL_PROC_NAME );
#endif
} /* end if */
lilLen = strlen(pasInstringPtr);
for (lili=0; lili < lilLen; lili++)
{
lilch = pasInstringPtr[(int)lili];
if (isalpha(lilch))
{
lilch = toupper(lilch);
}
refOutstringPtr[(int)lili] = lilch;
} /* End for loop */
refOutstringPtr[(int)lilLen] = '\0';
return( lilErr);
} /* LIUmakeUppercase */
/*\p*******************************************************************/
/* */
/* NAME: LIUreplaceChar */
/* */
/* PURPOSE: Replace all instances of a character in a string with */
/* another char. */
/* */
/* SAMPLE CALL: */
/* */
/* = LIUreplaceChar (textPtr, '\n', '@'); */
/* */
/* INTERFACE DEFINITION: */
/* variable def. expected/description */
/* ------------ ----- ------------------------------------- */
/* refText REF Pointer to the text string to be */
/* scanned for characters to be replaced */
/* pasSrc PAS character that will be replaced */
/* pasTar PAS character to replace it */
/* lilErr FNC (SUCCEEDED_ / FAILED_) error return */
/*\p*******************************************************************/
STAT_TYPE LIUreplaceChar
/* Translate specified character in string */
(CHAR *refText,
CHAR pasSrc,
CHAR pasTar)
{ /* LIUreplaceChar */
/*******************************************************************/
/* Local Constant Declarations */
/*******************************************************************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUreplaceChar";
#endif
/*******************************************************************/
/* Local Variable Declarations */
/*******************************************************************/
STAT_TYPE lilErr;
INT32 lilDone;
INT32 lilTemp;
CHAR lilTempStr[320];
CHAR lilSrc[2];
/*******************************************************************/
/* Procedure Body */
/*******************************************************************/
lilErr = SUCCEEDED_;
lilSrc[0] = pasSrc;
lilSrc[1] = NULL;
if (refText == NULL)
{
lilErr = FAILED_;
#ifdef LIU_USE_ERA
ERAerrorLog(LIL_PROC_NAME, "Input string is not valid.");
#endif
}
else
{
if (pasSrc == pasTar)
{
/*** Do Nothing *****/
}
else
{
strcpy(lilTempStr, refText);
lilDone = FALSE_;
while(!lilDone)
{
lilTemp = strcspn(lilTempStr, lilSrc);
if ((lilTemp > -1) && (lilTemp < (INT32)strlen(lilTempStr)))
{
lilTempStr[(int)lilTemp] = pasTar;
}
else
{
lilDone = TRUE_;
} /* end if-else */
} /* end while */
strcpy(refText, lilTempStr);
} /* end else */
} /* end else - if */
return(lilErr);
} /* end LIUreplaceChar */
/*\p*******************************************************************/
/* */
/* NAME: LIUintToString */
/* */
/* PURPOSE: This function will convert an integer value to its */
/* string representation and also will place a decimal point */
/* anyWhere within the string. */
/* */
/* SAMPLE CALL: */
/* */
/* = LIUintToString(Integer, Shift, StrLen, StrPtr); */
/* */
/* INTERFACE DEFINITION: */
/* variable def. expected/description */
/* ------------ ----- ------------------------------------- */
/* pasInt PAS The base integer to convert to string. */
/* pasShift PAS The position of the decimal point. */
/* pasStrLen PAS The length of string to return. */
/* refStr REF returning string. */
/* lilErr FNC (SUCCEEDED_ / FAILED_) error return */
/* */
/*\p*******************************************************************/
STAT_TYPE LIUintToString
/* Get ASCII string for integer & add decimal point */
(
INT32 pasInt,
INT32 pasShift,
INT32 pasStrLen,
CHAR *refStr
)
{ /* LIUintToString */
/*******************************************************************/
/* Local Constant Declarations */
/*******************************************************************/
#define LIL_STR_LEN 255
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUintToString";
#endif
/*******************************************************************/
/* Local Variable Declarations */
/*******************************************************************/
STAT_TYPE lilErr;
CHAR lilStr1[LIL_STR_LEN];
CHAR lilStr2[LIL_STR_LEN];
INT32 lilLen;
INT32 lili;
INT32 lilT;
INT32 lilj;
INT32 lilPos;
INT32 lilShf;
/*******************************************************************/
/* Procedure Body */
/*******************************************************************/
lilErr = SUCCEEDED_;
if (pasInt < 0)
{
lilErr = FAILED_;
#ifdef LIU_USE_ERA
ERAerrorLog ( LIL_PROC_NAME, "Cannot process negative numbers");
#endif
} /* end if */
if (refStr == NULL)
{
lilErr = FAILED_;
#ifdef LIU_USE_ERA
ERAerrorLog ( LIL_PROC_NAME, "String pointer is NULL");
#endif
}
else
{
sprintf(lilStr1, "%d\0", pasInt);
lilLen = strlen(lilStr1);
if ( (lilLen - pasShift + 2 > pasStrLen) || (pasShift + 2 > pasStrLen)
|| (pasStrLen > LIL_STR_LEN))
{
lilErr = FAILED_;
#ifdef LIU_USE_ERA
ERAerrorLog ( LIL_PROC_NAME, "Insufficient string memory");
#endif
} /* end if */
else
{
if ((pasShift >= 0 ) && (lilLen <= pasShift))
{
/* pad the left side with zeros. */
lilT = (pasShift - lilLen) + 1;
for(lili = 0; lili < lilT; lili++)
{
lilStr2[(int)lili] = '0';
} /* end for */
for (lili = lilT; lili < (lilT + lilLen); lili++)
{
lilStr2[(int)lili] = lilStr1[(int)(lili - lilT)];
}
lilStr2[(int)lili] = '\0';
lilPos = 1;
} /* end if */
else
if (pasShift < 0)
{
/* pad the rigth side with zeros. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -