sub-string

gweimer/utils/sub-string

Pull substring from STR starting at OFST for LEN
sub-string
@/sub-string
Pull substring from STR starting at OFST for LEN
STRstring
String to parse
OFSTbyte
Offset for starting substring
LENbyte
Length of substring
sub-string
STR
OFST
LEN
SUB
SUBstring
Substring found
To use the node in your project you should have the gweimer/utils 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

node {
    char* strBuff;
    char* subBuff;
    size_t maxlen;
    CStringView view;

    void evaluate(Context ctx) {

        if (isSettingUp() || isInputDirty<input_STR>(ctx) || isInputDirty<input_OFST>(ctx) || isInputDirty<input_LEN>(ctx)) {
            auto str = getValue<input_STR>(ctx);
            maxlen = length(str);
            char* strBuff = new char[maxlen+1];
            memset(strBuff, '\0', maxlen + 1);
            dump(str, strBuff);
            auto ofst = getValue<input_OFST>(ctx);
            auto len = getValue<input_LEN>(ctx);
            subBuff = new char[maxlen+1];
            memset(subBuff, '\0', maxlen + 1);
            if (ofst < maxlen) {
                if (ofst+len > maxlen) {
                    len = maxlen-ofst;
                }
                for (auto i = 0; i < len; i++) {
                    subBuff[i] = strBuff[ofst+i];
                }
            }
            view = CStringView(subBuff);
            emitValue<output_SUB>(ctx, XString(&view));
        }
    }
}