in edge-hub/core/src/Microsoft.Azure.Devices.Routing.Core/query/builtins/Substring.cs [54:70]
static string RuntimeStartLength(QueryValue input, QueryValue start, QueryValue length)
{
if (input?.ValueType != QueryValueType.String || start?.ValueType != QueryValueType.Double || length?.ValueType != QueryValueType.Double)
{
return Undefined.Instance;
}
string inputString = (string)input.Value;
double startIndex = (double)start.Value;
double lengthValue = (double)length.Value;
bool isValid = !inputString.IsNullOrUndefined() &&
startIndex.IsDefined() && startIndex < inputString.Length && startIndex >= 0 &&
lengthValue.IsDefined() && lengthValue >= 0 && lengthValue <= (inputString.Length - startIndex);
return isValid ? inputString.Substring((int)startIndex, (int)lengthValue) : Undefined.Instance;
}