MCPcopy Create free account
hub / github.com/Kitware/VTK / ConsumeStringToDoublesMap

Method ConsumeStringToDoublesMap

Filters/Statistics/vtkStatisticsAlgorithm.cxx:870–928  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

868}
869
870std::size_t vtkStatisticsAlgorithm::ConsumeStringToDoublesMap(
871 const std::string& source, std::map<std::string, std::vector<double>>& map)
872{
873 std::string work = source;
874 std::string key;
875 std::vector<double> tuple;
876 std::size_t consumed = 0;
877 std::size_t keySize;
878 std::size_t stringSize;
879 std::size_t ii;
880 tuple.clear();
881 for (ii = 0; ii < work.size(); work = work.substr(stringSize, std::string::npos))
882 {
883 if ((work[ii] == '{' && tuple.empty()) || (work[ii] == ',' && !tuple.empty()))
884 {
885 work = work.substr(1, std::string::npos);
886 ++consumed;
887
888 // Handle an empty map with no key-value pairs:
889 if (work[ii] == '}')
890 {
891 ++consumed;
892 return consumed;
893 }
894
895 keySize = vtkStatisticsAlgorithm::ConsumeString(work, key);
896 if (keySize == 0)
897 {
898 return 0;
899 }
900 consumed += keySize;
901 if (work[ii + keySize] != ':')
902 {
903 return 0;
904 }
905 // Consume the ":" between key and value.
906 ++consumed;
907 work = work.substr(1 + keySize, std::string::npos);
908
909 stringSize = vtkStatisticsAlgorithm::ConsumeDoubleTuple(work, tuple);
910 if (stringSize == 0)
911 {
912 return 0;
913 }
914 consumed += stringSize;
915 map[key] = tuple;
916 }
917 else if (work[ii] == '}' && consumed > 0)
918 {
919 ++consumed;
920 return consumed;
921 }
922 else
923 {
924 return 0;
925 }
926 }
927 return 0;

Callers 1

Calls 3

clearMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected