File: SAMKeywordValuePair.cpp

package info (click to toggle)
pbseqlib 0~20161219-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,924 kB
  • ctags: 5,123
  • sloc: cpp: 82,727; makefile: 305; python: 239; sh: 8
file content (50 lines) | stat: -rw-r--r-- 1,337 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "SAMKeywordValuePair.hpp"


bool SplitSAMKeyValuePair(std::string &kvPair, std::string &key, std::string &value) {
  size_t sepIndex = kvPair.find_first_of(":");
  if (sepIndex == kvPair.npos) {
    return false;
  }
  else {
    key = kvPair.substr(0, sepIndex);
    value = kvPair.substr(sepIndex+1);
    return true;
  }
}

bool SplitSAMTypedKeyValuePair(std::string kvPair, std::string &key,
                               std::string &kvType, std::string &value) {
  std::vector<std::string> strValues;
  ParseSeparatedList(kvPair, strValues, ':', 3);
  if (strValues.size() != 3) {
    return false;
  }
  else {
    key = strValues[0];
    kvType = strValues[1];
    value  = strValues[2];
    return true;
  }
}

bool TypedKeywordValuePair::Separate(std::string &kvPair, std::string &kvKey,
                                     std::string &kvType, std::string &kvValue) {
  if (SplitSAMTypedKeyValuePair(kvPair, kvKey, kvType, kvValue) == false) {
    return false;
  }
  return true;
}

void KeywordValueStringsToPairs(std::vector<std::string> &kvStrings, std::vector<SAMKeywordValuePair> &kvPairs) {

  kvPairs.resize(kvStrings.size());

  if (kvStrings.size() == 0) {
    return;
  }

  for (size_t i = 0; i < kvStrings.size(); i++ ) {
    SplitSAMKeyValuePair(kvStrings[i], kvPairs[i].key, kvPairs[i].value);
  }
}