FeatureNumList::VectorIntType*  FeatureNumList::StrToUInt16Vetor (const KKStr&  s)
{
  bool  valid = true;
  VectorIntType*  results = new VectorUint16 ();

  KKStrParser parser (s);
  parser.TrimWhiteSpace (" ");

  while  (parser.MoreTokens ())
  {
    KKStr  field = parser.GetNextToken (",\t");
    if  (field.Empty ())
      continue;
    auto dashPos = field.LocateCharacter ('-');
    if  (!dashPos)
    {
      kkint32 n = field.ToInt32 ();
      if ((n < 0) || ((kkuint32)n > maxIntType))
      {
        valid = false;
        break;
      }
      results->push_back ((IntType)n);
    }
    else
    {
      // We are looking at a range
      kkint32  startNum = field.SubStrSeg (0, dashPos).ToInt32 ();
      kkint32  endNum   = field.SubStrPart (dashPos + 1).ToInt32 ();

      if  ((startNum > endNum)  ||  (startNum < 0)  ||  ((kkuint32)endNum > maxIntType))
      {
        valid = false;
        break;
      }

      for  (kkint32 z = startNum;  z <= endNum;  ++z)
        results->push_back ((IntType)z);
    }
  }

  if  (!valid)
  {
    delete  results;
    results = NULL;
  }
  else
  {
    sort (results->begin (), results->end ());
  }

  return  results;
}  /* StrToUInt16Vetor */
Example #2
0
// Will scan for fields that are specific to 'JobValidation'
void  JobValidation::ProcessStatusStr (KKStrParser&  statusStr)
{
  log.Level (30) << "JobValidation::ProcessStatusStr[" << statusStr.Str () << "]" << endl;
  KKStr  fieldName;
  KKStr  fieldValue;

  while  (statusStr.MoreTokens ())
  {
    fieldName = statusStr.GetNextToken ("\t\n\r");
    fieldName.Upper ();

    fieldValue = statusStr.GetNextToken ("\t");
    fieldValue.TrimLeft ("\n\r\t ");
    fieldValue.TrimRight ("\n\r\t ");

    ProcessStatusField (fieldName, fieldValue);
  }
}  /* ProcessStatusStr */