Skip to content

Commit

Permalink
lib: added class AsciiControlCharacters
Browse files Browse the repository at this point in the history
- unit separator
- group separator
- record separator
  • Loading branch information
franku committed Oct 30, 2018
1 parent 17656b9 commit d33c683
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
37 changes: 37 additions & 0 deletions core/src/lib/ascii_control_characters.h
@@ -0,0 +1,37 @@
/**
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2018 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

#ifndef BAREOS_LIB_ASCII_CONTROL_CHARACTERS_H_
#define BAREOS_LIB_ASCII_CONTROL_CHARACTERS_H_ 1

class AsciiControlCharacters {
public:
static char UnitSeparator() { return unit_separator_; }
static char RecordSeparator() { return record_separator_; }
static char GroupSeparator() { return group_separator_; }

private:
static constexpr char unit_separator_ = 0x1f;
static constexpr char record_separator_ = 0x1e;
static constexpr char group_separator_ = 0x1d;
};

#endif /* BAREOS_LIB_ASCII_CONTROL_CHARACTERS_H_ */
9 changes: 6 additions & 3 deletions core/src/lib/qualified_resource_name_type_converter.cc
Expand Up @@ -20,6 +20,7 @@
*/

#include "qualified_resource_name_type_converter.h"
#include "lib/ascii_control_characters.h"

#include <sstream>
#include <algorithm>
Expand Down Expand Up @@ -61,7 +62,7 @@ bool QualifiedResourceNameTypeConverter::ResourceToString(const std::string &nam
{
std::string r_name = ResourceTypeToString(r_type);
if (r_name.empty()) { return false; }
str_out = r_name + record_separator_ + name_of_resource;
str_out = r_name + AsciiControlCharacters::RecordSeparator() + name_of_resource;
return true;
}

Expand All @@ -72,7 +73,9 @@ bool QualifiedResourceNameTypeConverter::ResourceToString(const std::string &nam
{
std::string r_name = ResourceTypeToString(r_type);
if (r_name.empty()) { return false; }
str_out = r_name + record_separator_ + name_of_resource + record_separator_ + std::to_string(job_id);
str_out = r_name + AsciiControlCharacters::RecordSeparator()
+ name_of_resource + AsciiControlCharacters::RecordSeparator()
+ std::to_string(job_id);
return true;
}

Expand All @@ -94,7 +97,7 @@ bool QualifiedResourceNameTypeConverter::StringToResource(std::string &name_of_r
const std::string &str_in) const
{
std::vector<std::string> string_list;
SplitStringIntoList(str_in, string_list, record_separator_, 3);
SplitStringIntoList(str_in, string_list, AsciiControlCharacters::RecordSeparator(), 3);
if (string_list.size() < 2) { /* minimum of parameters are name_of_resource and r_type */
return false;
}
Expand Down
1 change: 0 additions & 1 deletion core/src/lib/qualified_resource_name_type_converter.h
Expand Up @@ -38,7 +38,6 @@ class QualifiedResourceNameTypeConverter {
int StringToResourceType(const std::string &) const;

private:
static constexpr char record_separator_ = 0x1e;
const std::map<int, std::string> type_name_relation_map_;
const std::map<std::string, int> name_type_relation_map_;
};
Expand Down

0 comments on commit d33c683

Please sign in to comment.