Add ltrim and rtrim expression functions
ltrim(x) removes leading blanks and rtrim(x) removes trailing blanks, using the same characters trim removes (space, tab, newline). rtrim counts by index so an all-blank value becomes empty. The manual now documents trim, ltrim and rtrim with examples. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5f9a53aba2
commit
ec3e40b71a
3 files changed
+57
-2
No files matched your search
+31
-1
@@ -225,7 +225,37 @@ namespace jet {
|
|||||||
if(in.ifNext(")")) {
|
if(in.ifNext(")")) {
|
||||||
string = parm1.string.trim();
|
string = parm1.string.trim();
|
||||||
} else
|
} else
|
||||||
throw coreutils::Exception("Expecting ) at end of TRIM expression.");
|
throw coreutils::Exception("Expecting ) at end of TRIM expression.");
|
||||||
|
} else if(in.ifNextIgnoreCase("LTRIM")) {
|
||||||
|
// Leading blanks only - the same characters TRIM removes (space,
|
||||||
|
// tab, newline).
|
||||||
|
if(!in.ifNext("("))
|
||||||
|
throw coreutils::Exception("Expecting ( for LTRIM parameters.");
|
||||||
|
Operand parm1(in, tag);
|
||||||
|
if(in.ifNext(")")) {
|
||||||
|
const char *data = parm1.string.getData();
|
||||||
|
int len = parm1.string.getLength();
|
||||||
|
int start = 0;
|
||||||
|
while((start < len) && ((data[start] == ' ') || (data[start] == '\t') || (data[start] == '\n')))
|
||||||
|
++start;
|
||||||
|
string = parm1.string.substring(start, len - start);
|
||||||
|
} else
|
||||||
|
throw coreutils::Exception("Expecting ) at end of LTRIM expression.");
|
||||||
|
} else if(in.ifNextIgnoreCase("RTRIM")) {
|
||||||
|
// Trailing blanks only. Counted by index rather than with
|
||||||
|
// trimTrailingWhitespace(), which stops one character short and
|
||||||
|
// would leave " " for an all-blank value.
|
||||||
|
if(!in.ifNext("("))
|
||||||
|
throw coreutils::Exception("Expecting ( for RTRIM parameters.");
|
||||||
|
Operand parm1(in, tag);
|
||||||
|
if(in.ifNext(")")) {
|
||||||
|
const char *data = parm1.string.getData();
|
||||||
|
int len = parm1.string.getLength();
|
||||||
|
while((len > 0) && ((data[len - 1] == ' ') || (data[len - 1] == '\t') || (data[len - 1] == '\n')))
|
||||||
|
--len;
|
||||||
|
string = parm1.string.substring(0, len);
|
||||||
|
} else
|
||||||
|
throw coreutils::Exception("Expecting ) at end of RTRIM expression.");
|
||||||
} else if(in.ifNextIgnoreCase("TOUPPER")) {
|
} else if(in.ifNextIgnoreCase("TOUPPER")) {
|
||||||
if(!in.ifNext("("))
|
if(!in.ifNext("("))
|
||||||
throw coreutils::Exception("Expecting ( for TOUPPER parameters.");
|
throw coreutils::Exception("Expecting ( for TOUPPER parameters.");
|
||||||
|
|||||||
Binary file not shown.
+26
-1
@@ -263,6 +263,15 @@ the second parameter from the parameter passed as the first parameter.
|
|||||||
If the number of characters to return is greater than the length of
|
If the number of characters to return is greater than the length of
|
||||||
the first parameter then the entire parameter is returned.
|
the first parameter then the entire parameter is returned.
|
||||||
|
|
||||||
|
\subsection{ltrim}
|
||||||
|
|
||||||
|
Use the ltrim function to remove the leading blanks (spaces, tabs and
|
||||||
|
newlines) from a value. Trailing blanks are kept.
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
ltrim(' abc ') returns 'abc '
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
\subsection{reverse}
|
\subsection{reverse}
|
||||||
|
|
||||||
\subsection{right}
|
\subsection{right}
|
||||||
@@ -270,7 +279,16 @@ the first parameter then the entire parameter is returned.
|
|||||||
\subsection{round}
|
\subsection{round}
|
||||||
|
|
||||||
Use the round function to round a numeric value to the specified
|
Use the round function to round a numeric value to the specified
|
||||||
number of digits after the decimal point.
|
number of digits after the decimal point.
|
||||||
|
|
||||||
|
\subsection{rtrim}
|
||||||
|
|
||||||
|
Use the rtrim function to remove the trailing blanks (spaces, tabs and
|
||||||
|
newlines) from a value. Leading blanks are kept.
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
rtrim(' abc ') returns ' abc'
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
\subsection{substring}
|
\subsection{substring}
|
||||||
|
|
||||||
@@ -283,6 +301,13 @@ the value as a string.
|
|||||||
|
|
||||||
\subsection{trim}
|
\subsection{trim}
|
||||||
|
|
||||||
|
Use the trim function to remove the blanks (spaces, tabs and newlines)
|
||||||
|
from both ends of a value. See also ltrim and rtrim.
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
trim(' abc ') returns 'abc'
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
\subsection{expr}
|
\subsection{expr}
|
||||||
|
|
||||||
Use the expr function to parse the string contents contained in the expr string.
|
Use the expr function to parse the string contents contained in the expr string.
|
||||||
|
|||||||
Reference in new issue
Block a user