Evo C++ Library v0.5.1
map_alg.h
Go to the documentation of this file.
1 // Evo C++ Library
2 /* Copyright 2019 Justin Crowell
3 Distributed under the BSD 2-Clause License -- see included file LICENSE.txt for details.
4 */
6 
7 #pragma once
8 #ifndef INCL_evo_impl_map_alg_h
9 #define INCL_evo_impl_map_alg_h
10 
11 #include "../strtok.h"
12 
13 namespace evo {
16 
18 
19 // Implementation
21 namespace impl
22 {
23  template<class TMap, class TStr>
24  typename TMap::Size map_addsplit(TMap& map, const TStr& str, char delim=',', char kvdelim='=') {
25  char delims_buf[2];
26  delims_buf[0] = delim;
27  delims_buf[1] = kvdelim;
28  const SubString delims(delims_buf, 2);
29  const SubString EMPTY;
30 
31  typename TMap::Size count = 0;
32  bool created;
33  StrTok tok(str);
34  for (; tok.nextany(delims); ++count) {
35  typename TMap::Value& val = map.get(tok.value().convert<typename TMap::Key>(), &created);
36  if (tok.delim().null() || *tok.delim() == delim) {
37  if (!created)
39  } else {
40  if (tok.next(delim))
41  val = tok.value().convert<typename TMap::Value>();
42  else if (!created)
44  }
45  }
46  }
47 }
50 
52 }
53 #endif
Evo C++ Library namespace.
Definition: alg.h:11
static void init(Item *data, ulong size=1)
Initialize data using default constructor.
Definition: container.h:198