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:
Brad ArantandClaude Opus 5.5 committed 2026-11-20 15:07:33 +00:00
1 parent 5f9a53aba2
commit ec3e40b71a
3 files changed
+57 -2

No files matched your search

+31 -1
View File
@@ -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.");