DWORD readStringFromBuf()

in src/main/cpp/launcher/windows/src/ExtractUtils.c [101:124]


DWORD readStringFromBuf(SizedString *rest, SizedString * result, DWORD isUnicode) {
    if((rest->length)!=0) {
        // we have smth in the restBytes that we have read but haven`t yet proceeded
        DWORD i=0;
        for(i=0;i<rest->length;i++) {
            DWORD check = ((rest->bytes)[i]==0);
            if(isUnicode) {
                if ( (i/2)*2==i) {// i is even
                    check = check && (i < rest->length-1 && ((rest->bytes)[i+1]==0));
                } else {
                    check = 0;
                }
            }
            if( check ) { // we have found null character in the rest bytes
                result->bytes = appendStringN(NULL, 0, rest->bytes, i);
                result->length = i;
                modifyRestBytes(rest, i + 1 + isUnicode);
                return ERROR_OK;
            }
        }
        //here we have found no \0 character in the rest of bytes...
    }
    return ERROR_INPUTOUPUT;
}