QSPVariant qspArrayMinMaxItem(QSP_CHAR *name, QSP_BOOL isMin) { QSPVar *var; QSP_CHAR *str; QSP_BOOL isString; int curInd, count; QSPVariant res; if (!(var = qspVarReferenceWithType(name, QSP_FALSE, &isString))) return qspGetEmptyVariant(QSP_FALSE); curInd = -1; count = var->ValsCount; while (--count >= 0) { if (isString) { str = var->Values[count].Str; if (str && *str) { if (curInd >= 0) { if (isMin) { if (QSP_STRCOLL(str, var->Values[curInd].Str) < 0) curInd = count; } else if (QSP_STRCOLL(str, var->Values[curInd].Str) > 0) curInd = count; } else curInd = count; } } else if (curInd >= 0) { if (isMin) { if (var->Values[count].Num < var->Values[curInd].Num) curInd = count; } else if (var->Values[count].Num > var->Values[curInd].Num) curInd = count; } else curInd = count; } if (curInd < 0) return qspGetEmptyVariant(isString); if (res.IsStr = isString) QSP_STR(res) = qspGetNewText(var->Values[curInd].Str, -1); else QSP_NUM(res) = var->Values[curInd].Num; return res; }
QSPVariant qspGetVar(QSP_CHAR *name) { QSPVar *var; int index; if (!(var = qspGetVarData(name, QSP_FALSE, &index))) return qspGetEmptyVariant(QSP_FALSE); return qspGetVarValueByReference(var, index, *name == QSP_STRCHAR[0]); }
QSPVariant qspGetVarValueByReference(QSPVar *var, int ind, QSP_BOOL isStringType) { QSPVariant ret; QSP_CHAR *text; if (ind >= 0 && ind < var->ValsCount) { if (ret.IsStr = isStringType) { text = var->Values[ind].Str; QSP_STR(ret) = (text ? qspGetNewText(text, -1) : qspGetNewText(QSP_FMT(""), 0)); } else QSP_NUM(ret) = var->Values[ind].Num; return ret; } return qspGetEmptyVariant(isStringType); }