Example #1
0
template<class OutputIterator> inline void
tws::core::copy_string_array(const rapidjson::Value& jvalues,
                             OutputIterator result)
{
  if(!jvalues.IsArray())
    throw conversion_error() << tws::error_description("copy_string_array: can only copy arrays of strings.");
  
  if(jvalues.Empty())
    return;
  
  const rapidjson::SizeType nelements = jvalues.Size();
  
  for(rapidjson::SizeType i = 0; i != nelements; ++i)
  {
    const rapidjson::Value& jelement = jvalues[i];
    
    if(!jelement.IsString())
      throw conversion_error() << tws::error_description("copy_string_array: only string elements are allowed in array.");
    
    if(jelement.IsNull())
      continue;
    
    *result++ = jelement.GetString();
  }
}
void JSONArrayToStringVector(const rapidjson::Value& Obj, std::vector<std::string>& Vector)
{
    Vector.clear();

    if (Obj.IsArray() && !Obj.Empty())
    {
        for (unsigned int i=0; i<Obj.Capacity(); i++)
        {
            if (Obj[i].IsString())
                Vector.push_back(std::string(Obj[i].GetString()));
        }
    }
}
void JSONArrayToStringSet(const rapidjson::Value& Obj, std::set<T>& Set)
{
    Set.clear();

    if (Obj.IsArray() && !Obj.Empty())
    {
        for (unsigned int i=0; i<Obj.Capacity(); i++)
        {
            if (Obj[i].IsString())
                Set.insert(T(Obj[i].GetString()));
        }
    }
}