[flang-commits] [flang] [llvm] [flang] Implement SPLIT intrinsic subroutine with tests (PR #185584)
via flang-commits
flang-commits at lists.llvm.org
Sat Mar 14 01:15:54 PDT 2026
================
@@ -992,6 +992,56 @@ static RT_API_ATTRS void TokenizePositionsImpl(Descriptor &first,
}
}
+// SPLIT - scans for the next separator character in STRING.
+// When BACK is false (or absent), returns the position of the leftmost
+// character in SET whose position in STRING is greater than POS, or
+// LEN(STRING)+1 if no such character exists.
+// When BACK is true, returns the position of the rightmost character in
+// SET whose position in STRING is less than POS, or 0 if no such
+// character exists.
+template <typename CHAR>
+static RT_API_ATTRS std::size_t SplitImpl(const CHAR *string,
+ std::size_t stringLen, const CHAR *set, std::size_t setLen, std::size_t pos,
+ bool back) {
+ if (back) {
+ // Scan backwards from position pos-1 (1-indexed pos means index pos-2)
+ // looking for the rightmost separator at position < pos.
+ if (pos <= 1) {
+ return 0;
+ }
+ std::size_t scanLen = pos - 1; // number of characters to scan
+ if (scanLen > stringLen) {
+ scanLen = stringLen;
+ }
+ for (std::size_t i = scanLen; i > 0; --i) {
----------------
laoshd wrote:
Re-implemented in terms of SCAN. No need for this nested loops any more.
https://github.com/llvm/llvm-project/pull/185584
More information about the flang-commits
mailing list