search-for-sequence

gabbapeople/sim7020/search-for-sequence

Check the string for a specific character sequence.
search-for-sequence
@/search-for-sequence
Check the string for a specific character sequence.
STRstring
Source string.
SEQstring
Sequence to search.
SRCHpulse
Triggers a new search.
search-for-sequence
STR
SEQ
SRCH
T
F
Fpulse
Fires if the sequence is not found.
Tpulse
Fires if the sequence is found.
To use the node in your project you should have the gabbapeople/sim7020 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {

  if (isInputDirty<input_SRCH>(ctx)) {

    auto str = getValue<input_STR>(ctx);
    char *_str = (char*)malloc(sizeof(char) * (length(str) + 1));
    memset(_str, '\0', length(str) + 1);
    dump(str, _str);

    auto seq = getValue<input_SEQ>(ctx);
    char *_seq = (char*)malloc(sizeof(char) * (length(seq) + 1));
    memset(_seq, '\0', length(seq) + 1);
    dump(seq, _seq);

    char* ptr;
    ptr = strstr(_str, _seq);

    if (ptr != NULL) {
        emitValue<output_T>(ctx, 1);
    } else {
        emitValue<output_F>(ctx, 1);
    }

    free(_str);
    free(_seq);
  }
}