⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liustrg.cpp

📁 用c++变得一个测量财富的+游戏
💻 CPP
📖 第 1 页 / 共 5 页
字号:

STAT_TYPE LIUstripLTblanks
( CHAR *refStr )

{ /* LIUstripLTblanks procedure */

/******************* Local Constant Declarations **********************/
#ifdef LIU_USE_ERA
/* CHARPTR LIL_PROC_NAME = "LIUstripLTblanks"; */
#endif

/******************* Local Variable Declarations **********************/
/* error return flag       */
STAT_TYPE  lilErr;

/************************* Procedure Body *****************************/
lilErr = LIUstripTrailingBlanks( refStr );
if (lilErr == SUCCEEDED_) 
  {
  if (LIUisWhiteSpace( *refStr ))
    {
    lilErr = LIUstripLeadingBlanks( refStr );
    }
  }

return(lilErr);
} /* LIUstripLTblanks end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  LIUisWhiteSpace

    PURPOSE:  to check if a character is "white space" such as
      a blank, tab, new line, or carriage return.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   lilWht             FNC    TRUE_ if blank space, else FALSE_      **
**\p*******************************************************************/

INT32 LIUisWhiteSpace
( INT32 pasCh )


{ /* LIUisWhiteSpace procedure */

/******************* Local Constant Declarations **********************/

/******************* Local Variable Declarations **********************/
int  lilWht;

/************************* Procedure Body *****************************/

lilWht = FALSE_;

if ((pasCh == ' ') ||
    (pasCh == '\t')||
    (pasCh == '\n')||
    (pasCh == '\r'))
  {
  lilWht = TRUE_;
  }

return(lilWht);
} /* LIUisWhiteSpace end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  LIUstripULblanks

    PURPOSE:  to strip leading and trailing blanks from a string.
      Then convert any embedded blanks to underscore
      characters.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   lilErr             FNC    (SUCCEEDED_ / FAILED_) error return    **
**\p*******************************************************************/

STAT_TYPE LIUstripULblanks
( CHAR *refStr )

{ /* LIUstripULblanks procedure */

/******************* Local Constant Declarations **********************/

/******************* Local Variable Declarations **********************/
/* error return flag       */
STAT_TYPE  lilErr;
CHAR      *lilCptr;

/************************* Procedure Body *****************************/
lilErr = LIUstripLTblanks( refStr );

if (lilErr == SUCCEEDED_)
  {
  lilCptr = refStr;
  while (*lilCptr != '\0')
    {
    if (LIUisWhiteSpace( *lilCptr ) )
      {
      *lilCptr = '_';
      }
    lilCptr++;
    }
  }

return(lilErr);
} /* LIUstripULblanks end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  LIUstrncpy

    PURPOSE:  to copy no more than 'pasDestBufSize-1' characters
    from 'pasSrc' to 'refDest'.  Then make certain that 'refDest'
    is null terminated.  Works same as 'strncpy' but GUARANTEES
    the destination string is null terminated - something strncpy
    fails to do.  (If you pass a string that is NOT properly
    terminated to other string functions, you may violate your
    memory and crash the computer!)

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   lilErr             FNC    (SUCCEEDED_ / FAILED_) error return    **
**\p*******************************************************************/

STAT_TYPE LIUstrncpy
( CHAR              *refDest,
  const CHAR        *pasSrc,
  INT32             pasDestBufSize )

{ /* LIUstrncpy procedure */

/******************* Local Constant Declarations **********************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUstrncpy";
#endif

#define LIL_MIN_BUF_SIZE 2

/******************* Local Variable Declarations **********************/
/* error return flag       */
STAT_TYPE  lilErr;

/************************* Procedure Body *****************************/


if ((refDest == NULL) || (pasSrc == NULL))
  {
#ifdef LIU_USE_ERA
  ERAparameterError( LIL_PROC_NAME );
#endif
  lilErr = FAILED_;
  }
else if (pasDestBufSize < LIL_MIN_BUF_SIZE)
  {
#ifdef LIU_USE_ERA
  ERAparameterError( LIL_PROC_NAME );
#endif
  lilErr = FAILED_;
  }
else
  {
  lilErr = SUCCEEDED_;
  strncpy( refDest, pasSrc, (size_t)pasDestBufSize );
  refDest[(int)pasDestBufSize-1] = '\0';
  }

return(lilErr);
} /* LIUstrncpy end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  LIUstripLeadingChars

    PURPOSE:  to remove any leading characters from the referenced
      string.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   lilErr             FNC    (SUCCEEDED_ / FAILED_) error return    **
**\p*******************************************************************/

STAT_TYPE LIUstripLeadingChars
( int   pasCharToStrip,
  CHAR *refStr )

{ /* LIUstripLeadingChars procedure */

/******************* Local Constant Declarations **********************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUstripLeadingChars";
#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 chars to find start of
  * source string.
  */
  while ( *lilPtr == pasCharToStrip ) lilPtr++;
  /**************************************************
  * If pointer to end of chars is not equal to
  * referenced string, then there are some
  * chars to skip.  Copy from the skip pointer
  * back to the referenced string up to and including
  * the string terminator.
  */
  if (lilPtr != refStr) /* Then leading chars to nuke */
    {
    do
      {
      *refStr = *lilPtr;
      refStr++;
      lilPtr++;
      }
    while (*lilPtr != '\0');
    *refStr = '\0';
    }
  }

return(lilErr);
} /* LIUstripLeadingChars end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  LIUstripTrailingChars

    PURPOSE:  to strip all trailing chars, if any, from the
      referenced string.  Simply convert all trailing chars,
      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 LIUstripTrailingChars
( int   pasCharToStrip,
  CHAR *refStr )

{ /* LIUstripTrailingChars procedure */

/******************* Local Constant Declarations **********************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUstripTrailingChars";
#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 ( *lilPtr == pasCharToStrip )
        {
        *lilPtr = '\0';
        lilPtr--;
        }
      }
    while ((lilPtr > refStr) && (LIUisWhiteSpace( *lilPtr )));
    }
  }

return(lilErr);
} /* LIUstripTrailingChars end */


/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  LIUstripLTchars

    PURPOSE:  to strip leading and trailing chars from a string.
**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   lilErr             FNC    (SUCCEEDED_ / FAILED_) error return    **
**\p*******************************************************************/

STAT_TYPE LIUstripLTchars
( int   pasCharToStrip,
  CHAR *refStr )

{ /* LIUstripLTchars procedure */

/******************* Local Constant Declarations **********************/

/******************* Local Variable Declarations **********************/
/* error return flag       */
STAT_TYPE  lilErr;

/************************* Procedure Body *****************************/
lilErr = LIUstripTrailingChars( pasCharToStrip, refStr );

if (lilErr == SUCCEEDED_) 
  {
  if ( *refStr == pasCharToStrip )
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -