enhancement
major
minor
major
minor
minor
#29670
TL-Script: Funktionen trim, trimStart und trimEnd entfernen Leerraum am Anfang und Ende einer Zeichenkette
Problem
TL-Script has no function that strips leading and trailing white space from a string. The only built-in that trims is the trim option of split(...), which applies to the parts of a split. A script normalizing user input, e.g. the search term of an app-bar search box submitted with a trailing space, has to spell it as a regular expression:
term -> regex('^\\s+|\\s+$').regexReplace($term.toString(), '')
This is hard to read and easy to get wrong. It is needed in the TL Development app, where Cursor ` found 10 tickets instead of the 15 of `Cursor, and a box of spaces searched for spaces.
Expected
A string function trim(string) / $s.trim() returning the string without leading and trailing white space (Unicode white space, as String.strip()), and null for null. Optionally trimStart / trimEnd.
Lösung
Drei neue TL-Script-Funktionen:
- trim(string) / $s.trim() – entfernt Leerraum am Anfang und am Ende,
- trimStart(string) / $s.trimStart() – entfernt Leerraum nur am Anfang,
- trimEnd(string) / $s.trimEnd() – entfernt Leerraum nur am Ende.
Als Leerraum gilt jedes Unicode-White-Space-Zeichen (wie String.strip()). Innerer Leerraum bleibt erhalten. Für null liefern die Funktionen null, andere Werte werden wie bei toLowerCase() zuerst in eine Zeichenkette umgewandelt.
term -> $term.trim()
Technisch
Eine GenericMethod Trim (Paket com.top_logic.model.search.expr.config.operations.string) mit konfigurierbarer Seite (BOTH, START, END), registriert als drei <method>-Einträge in modelSearchConf.config.xml. Hilfeseiten unter Developer Guide → TL-Script → Strings → StringFunctions.
Test
- test.com.top_logic.model.search.expr.TestSearchExpression