From 9793393f1fc4540f95e2b81e93e449f0e52136eb Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 16 Oct 2018 10:24:50 +0200 Subject: [PATCH] lib: added class AsciiControlCharacters - unit separator - group separator - record separator --- core/src/lib/ascii_control_characters.h | 37 +++++++++++++++++++ .../qualified_resource_name_type_converter.cc | 9 +++-- .../qualified_resource_name_type_converter.h | 1 - 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 core/src/lib/ascii_control_characters.h diff --git a/core/src/lib/ascii_control_characters.h b/core/src/lib/ascii_control_characters.h new file mode 100644 index 00000000000..a92389a81aa --- /dev/null +++ b/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_ */ diff --git a/core/src/lib/qualified_resource_name_type_converter.cc b/core/src/lib/qualified_resource_name_type_converter.cc index 0cb5caff09b..57d46b505e8 100644 --- a/core/src/lib/qualified_resource_name_type_converter.cc +++ b/core/src/lib/qualified_resource_name_type_converter.cc @@ -20,6 +20,7 @@ */ #include "qualified_resource_name_type_converter.h" +#include "lib/ascii_control_characters.h" #include #include @@ -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; } @@ -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; } @@ -94,7 +97,7 @@ bool QualifiedResourceNameTypeConverter::StringToResource(std::string &name_of_r const std::string &str_in) const { std::vector 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; } diff --git a/core/src/lib/qualified_resource_name_type_converter.h b/core/src/lib/qualified_resource_name_type_converter.h index b0b9c2e4cac..37cf1850168 100644 --- a/core/src/lib/qualified_resource_name_type_converter.h +++ b/core/src/lib/qualified_resource_name_type_converter.h @@ -38,7 +38,6 @@ class QualifiedResourceNameTypeConverter { int StringToResourceType(const std::string &) const; private: - static constexpr char record_separator_ = 0x1e; const std::map type_name_relation_map_; const std::map name_type_relation_map_; };