📄 liustrg.cpp
字号:
lilErr = LIUstripLeadingChars( pasCharToStrip, refStr );
}
}
return(lilErr);
} /* LIUstripLTchars end */
/*\p********************************************************************
** **
** **
NAME: LIUfortranToCstr
PURPOSE: convert a fortran string to a C string.
The fortran string is EXACTLY 'pasFortranStringLen'
bytes long. It is padded with trailing blanks.
It has NO null terminator. The 'refCstring' is
a C caharacter array AT LEAST 'pasFortranStringLen+1'
bytes long. After extracting and terminating the
C string from the Fortran string, trailing blanks
are stripped from the C string. Leading
blanks are NOT stripped however, as they MAY BE
significant.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** lilErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE LIUfortranToCstr
(INT32 pasFortranStringLen,
CHAR *pasFortranString,
CHAR *refCstring )
{ /* LIUfortranToCstr procedure */
/******************* Local Constant Declarations **********************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUfortranToCstr";
#endif
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE lilErr;
/************************* Procedure Body *****************************/
lilErr = FAILED_;
if (pasFortranStringLen <= 0)
{
#ifdef LIU_USE_ERA
ERAparameterError( LIL_PROC_NAME );
#endif
}
else if (pasFortranString == NULL || refCstring == NULL)
{
#ifdef LIU_USE_ERA
ERAparameterError( LIL_PROC_NAME );
#endif
}
else
{
memcpy((char *)refCstring,
(char *)pasFortranString,
(size_t)pasFortranStringLen);
refCstring[(int)pasFortranStringLen] = '\0';
LIUstripTrailingBlanks(refCstring);
lilErr = SUCCEEDED_;
}
return(lilErr);
} /* LIUfortranToCstr end */
/*\p********************************************************************
** **
** **
NAME: LIUcToFortranStr
PURPOSE: convert a NULL terminated C string to a
FORTRAN format string.
The fortran string is EXACTLY 'pasFortranStringLen'
bytes long. Up to, but no more than, 'pasFortranStringLen'
characters are copied from the C string to the fortran
string. The FORTRAN string is then padded, if necessary,
with trailing blanks - no null terminator is used.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** lilErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE LIUcToFortranStr
(INT32 pasFortranStringLen,
CHAR *pasCstring,
CHAR *refFortranString )
{ /* LIUcToFortranStr procedure */
/******************* Local Constant Declarations **********************/
#ifdef LIU_USE_ERA
CHARPTR LIL_PROC_NAME = "LIUcToFortranStr";
#endif
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE lilErr;
int lilLen;
/************************* Procedure Body *****************************/
lilErr = FAILED_;
if (pasFortranStringLen <= 0)
{
#ifdef LIU_USE_ERA
ERAparameterError( LIL_PROC_NAME );
#endif
}
else if (refFortranString == NULL || pasCstring == NULL)
{
#ifdef LIU_USE_ERA
ERAparameterError( LIL_PROC_NAME );
#endif
}
else
{
strncpy((char *)refFortranString,
(char *)pasCstring,
(size_t)pasFortranStringLen);
lilLen = (int)strlen(pasCstring);
while (lilLen < pasFortranStringLen)
{
refFortranString[lilLen] = ' ';
lilLen++;
}
lilErr = SUCCEEDED_;
}
return(lilErr);
} /* LIUcToFortranStr end */
/*\p*******************************************************************/
/* */
/* NAME: LIUstrchrLast */
/* */
/* PURPOSE: */
/* Find the last occurrence of the specified */
/* character. */
/* */
/* 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 */
/* last occurence of pasChar or NULL. */
/* */
/*\p*******************************************************************/
CHAR *LIUstrchrLast
(const CHAR *pasStr,
CHAR pasChar)
{
/*******************************************************************/
/* Local Variable Declarations */
/*******************************************************************/
CHAR *lilStrPtr;
/*******************************************************************/
/* Procedure Body */
/*******************************************************************/
lilStrPtr = NULL;
if (pasStr == NULL)
{
#ifdef LIU_USE_ERA
ERAerrorLog("LIUstrchrLast", "Input string is equal to NULL");
#endif
}
else
{
lilStrPtr = (CHAR *)pasStr;
lilStrPtr += (strlen(pasStr)-1);
while ((lilStrPtr != pasStr) && (tolower(*lilStrPtr) != pasChar))
lilStrPtr--;
if (*lilStrPtr != pasChar) lilStrPtr = NULL;
}
return (lilStrPtr);
} /* end of function LIUstrchrLast */
/*\p*******************************************************************/
/* */
/* NAME: LIUstrchriLast */
/* */
/* PURPOSE: */
/* Find the last occurrence of the specified */
/* character. */
/* */
/* 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 */
/* last occurence of pasChar or NULL. */
/* */
/*\p*******************************************************************/
CHAR *LIUstrchriLast
/* case-insensitive LIUstrchrLast */
(CHAR *pasStr,
CHAR pasChar)
{
/*******************************************************************/
/* Local Variable Declarations */
/*******************************************************************/
CHAR *lilStrPtr;
CHAR lilChar;
/*******************************************************************/
/* Procedure Body */
/*******************************************************************/
lilStrPtr = NULL;
if (pasStr == NULL)
{
#ifdef LIU_USE_ERA
ERAerrorLog("LIUstrchriLast", "Input string is equal to NULL");
#endif
}
else
{
lilStrPtr = pasStr;
lilStrPtr += (strlen(pasStr)-1);
lilChar = tolower (pasChar);
while ((lilStrPtr != pasStr) && (tolower(*lilStrPtr) != lilChar))
lilStrPtr--;
if (tolower(*lilStrPtr) != lilChar) lilStrPtr = NULL;
}
return (lilStrPtr);
} /* end of function LIUstrchriLast */
/*\p********************************************************************
** **
NAME: LIUisAllOneChar
PURPOSE: to see if the entire string conintains a repeating
list of characters all equal to 'pasCharToCheck'. If so,
return TRUE_, else FALSE_.
** Return Val type/expected/description **
** ------------ -------------------------------------------- **
** lilOne BOOLEAN, TRUE_ or FALSE_ **
**\p*******************************************************************/
BOOLEAN LIUisAllOneChar( int pasCharToCheck,
const CHAR *pasStr )
{
/*********** Local Constant & Variable Declarations *******************/
BOOLEAN lilOne;
char *lilCptr;
/************************* Procedure Body *****************************/
lilOne = FALSE_;
if (pasStr)
{
if (*pasStr)
{
lilOne = TRUE_;
lilCptr = (CHAR *)pasStr;
while (*lilCptr && lilOne == TRUE_)
{
if (*lilCptr != pasCharToCheck)
{
lilOne = FALSE_;
}
else
{
lilCptr++;
}
}
}
}
return(lilOne);
} /* LIUisAllOneChar end */
/*\p********************************************************************
** **
NAME: LIUgetPlural
NAME: LIUgetAblankStr
PURPOSE: to return "s" if integer is != 1, else return ""
Return " ", pointer to a single blank string. Useful
when print formatting fields.
** Return Val type/expected/description **
** ------------ -------------------------------------------- **
** lilPptr const char *, plural string pointer **
**\p*******************************************************************/
LOCAL char *limPlural = "s";
LOCAL char *limSingular = "";
LOCAL char *limAblank = " ";
const char *LIUgetPlural( INT32 pasCount )
{
/*********** Local Constant & Variable Declarations *******************/
const char *lilPptr;
/************************* Procedure Body *****************************/
lilPptr = (const char *)limPlural;
if (pasCount == 1)
{
lilPptr = (const char *)limSingular;
}
return(lilPptr);
} /* LIUgetPlural end */
const char *LIUgetAblankStr( )
{
return( (const char *)limAblank );
} /* LIUgetAblankStr end */
/*\p********************************************************************
** **
NAME: LIUgetAcharStr
NAME: LIUdeleteAcharStr
PURPOSE: Get a string filled with the character specified,
and null terminated - provide a complimentary delete
function, which is equivalent to LIMDELA(charPtr);
** Return Val type/expected/description **
** ------------ -------------------------------------------- **
** lilCptr char *, filled string pointer **
**\p*******************************************************************/
char *LIUgetAcharStr( int pasCharToGet,
int pasLenOfStr )
{
/*********** Local Constant & Variable Declarations *******************/
char *lilCptr;
/************************* Procedure Body *****************************/
if (pasLenOfStr < 2)
pasLenOfStr = 2;
lilCptr = new char[pasLenOfStr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -