Description
Returns the starting indices (in a CTLST instance) where a matching pattern is found within the buffer's value.
Prototype
DCTBUFF_Search...
D PR 10I 0
D@This * Value
D@TestStr * Value
D@Len 10I 0 Value
D@Indices * Value
Parameters
@This
Type | Pointer (*) |
Passing Mode | Value |
Description | The address of an CTBUFF instance. This pointer MUST be obtained through a call to CTBUFF_Constructor. |
@TestStr
Type | Pointer (*) |
Passing Mode | Value |
Description | The address of a buffer that holds the byte pattern (string) to match for. |
@Len
Type | 10I 0 |
Passing Mode | Value |
Description | The length in bytes of the byte pattern (this is not %Size(@TestStr) but rather the size of the buffer pointed to by @TestStr). |
@Indices
Type | Pointer (*) |
Passing Mode | Value |
Description | The address of a CTLST instance that will hold a list of indices where the pattern is found within the CTBUFF instance value. Indices are of type 10I 0. The CTLST instance must already be constructed before passing it's address to the CTBUFF_Search method. |
Return Values
Symbolic Constant | Value | Description |
CS_SUCCESS | 0 | The method succeeded. This does not mean that the pattern was found. The resulting number of indices returned in the CTLST instance pointed to by @Indices might still be zero. |
CS_FAILURE | 1 | The method failed. This does not mean that the pattern was not found in the CTBUFF instance value. Rather, this could be the result of an invalid pointer value for the @Indices parameter or an invalid @TestStr pointer or some similar reason. |
Examples
/include QINCSRC,CTBASE
DpBuffer S *
DpIndices S *
DString S 255A
DPattern S 10A
DIndex S 10I 0
DPatSize S 10I 0
DBytes S 10I 0
DRc S 10I 0
Di S 10I 0
DCount S 10I 0
/Free
pBuffer = CTBUFF_Constructor();
pIndices = CTLST_Constructor();
String = 'SELECT * FROM Table WHERE F1 = ? AND F2 <> ?';
CTBUFF_Set(pBuffer: %Addr(String): %Len(%Trim(String)));
// We want to know the positions of the SQL parameter
// placeholders; the resulting linked list will contain
// two integers: 32 and 44 (positions are one-based, one
// being the first character in the buffer
Pattern = '?';
PatSize = 1;
CTBUFF_Search(pBuffer: %Addr(Pattern): PatSize: pIndices);
Count = CTLST_Count(pIndices);
For i=1 To Count By 1;
Bytes = %Size(Index);
CTLST_Get(pIndices: %Addr(Index): Bytes: i);
EndFor;
CTBUFF_Destructor(pBuffer);
CTLST_Destructor(pIndices);
*InLR = *On;
Return;
/End-Free