param.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021 The urg_stamped Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SCIP2_PARAM_H
18 #define SCIP2_PARAM_H
19 
20 #include <string>
21 #include <algorithm>
22 
23 namespace scip2
24 {
26 {
27  bool parsed;
29  std::string key;
30  std::string value;
31  std::string error;
32 
34  : parsed(false)
35  , checksum_matched(false)
36  {
37  }
38 };
39 
40 static ParsedParam parseParamLine(const std::string& line)
41 {
42  ParsedParam ret;
43 
44  if (line.size() < 3)
45  {
46  // ":;[checksum]"
47  ret.error = "parameter line must have at least 3 chars";
48  return ret;
49  }
50 
51  const auto delm = std::find(line.begin(), line.end(), ':');
52  if (delm == line.end())
53  {
54  ret.error = "delimiter not found";
55  return ret;
56  }
57  auto ie = line.rbegin();
58  const uint8_t checksum = *ie;
59  ++ie;
60  if (*ie != ';')
61  {
62  ret.error = "checksum delimiter not found";
63  return ret;
64  }
65  const auto end = line.end() - 2;
66  ret.parsed = true;
67  ret.key = std::string(line.begin(), delm);
68  ret.value = std::string(delm + 1, end);
69 
70  uint8_t sum = 0;
71  for (auto it = line.begin(); it != end; ++it)
72  {
73  sum += *it;
74  }
75  if ((sum & 0x3F) + 0x30 == checksum)
76  {
77  ret.checksum_matched = true;
78  }
79  return ret;
80 }
81 } // namespace scip2
82 
83 #endif // SCIP2_PARAM_H
bool checksum_matched
Definition: param.h:28
std::string key
Definition: param.h:29
static ParsedParam parseParamLine(const std::string &line)
Definition: param.h:40
std::string error
Definition: param.h:31
std::string value
Definition: param.h:30


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Mon Jul 3 2023 02:11:32