diff --git a/Operand.cpp b/Operand.cpp index 77c7edd..a1673a2 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -225,7 +225,37 @@ namespace jet { if(in.ifNext(")")) { string = parm1.string.trim(); } 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")) { if(!in.ifNext("(")) throw coreutils::Exception("Expecting ( for TOUPPER parameters."); diff --git a/docs/JetCore.pdf b/docs/JetCore.pdf index 026da6c..3b53732 100644 Binary files a/docs/JetCore.pdf and b/docs/JetCore.pdf differ diff --git a/docs/JetCore.tex b/docs/JetCore.tex index 61d713f..ac5a4c1 100644 --- a/docs/JetCore.tex +++ b/docs/JetCore.tex @@ -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 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{right} @@ -270,7 +279,16 @@ the first parameter then the entire parameter is returned. \subsection{round} 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} @@ -283,6 +301,13 @@ the value as a string. \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} Use the expr function to parse the string contents contained in the expr string.