-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1951 from ApexAI/iox-1942-introduce-further-seman…
…tic-string-types Iox 1942 introduce further semantic string types
- Loading branch information
Showing
16 changed files
with
615 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef IOX_HOOFS_POSIX_VOCABULARY_FILE_NAME_HPP | ||
#define IOX_HOOFS_POSIX_VOCABULARY_FILE_NAME_HPP | ||
|
||
#include "iox/semantic_string.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool file_name_does_contain_invalid_characters(const string<platform::IOX_MAX_FILENAME_LENGTH>& value) noexcept; | ||
bool file_name_does_contain_invalid_content(const string<platform::IOX_MAX_FILENAME_LENGTH>& value) noexcept; | ||
} // namespace details | ||
|
||
/// @brief Represents a single file name. It is not allowed to contain any path elements | ||
/// like "./some_file" or "path/to/file". Just a plain old simple "my_file.bla". | ||
class FileName : public SemanticString<FileName, | ||
platform::IOX_MAX_FILENAME_LENGTH, | ||
details::file_name_does_contain_invalid_content, | ||
details::file_name_does_contain_invalid_characters> | ||
{ | ||
using Parent = SemanticString<FileName, | ||
platform::IOX_MAX_FILENAME_LENGTH, | ||
details::file_name_does_contain_invalid_content, | ||
details::file_name_does_contain_invalid_characters>; | ||
using Parent::Parent; | ||
}; | ||
} // namespace iox | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef IOX_HOOFS_POSIX_VOCABULARY_FILE_PATH_HPP | ||
#define IOX_HOOFS_POSIX_VOCABULARY_FILE_PATH_HPP | ||
|
||
#include "iox/semantic_string.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool file_path_does_contain_invalid_characters(const string<platform::IOX_MAX_PATH_LENGTH>& value) noexcept; | ||
bool file_path_does_contain_invalid_content(const string<platform::IOX_MAX_PATH_LENGTH>& value) noexcept; | ||
} // namespace details | ||
|
||
/// @brief Represents a path to a file. It is not allowed to end with a path separator | ||
/// since this would then be a path to a directory. A valid file path is for | ||
/// instance "path/to/file" but not "path/to/file/". | ||
class FilePath : public SemanticString<FilePath, | ||
platform::IOX_MAX_PATH_LENGTH, | ||
details::file_path_does_contain_invalid_content, | ||
details::file_path_does_contain_invalid_characters> | ||
{ | ||
using Parent = SemanticString<FilePath, | ||
platform::IOX_MAX_PATH_LENGTH, | ||
details::file_path_does_contain_invalid_content, | ||
details::file_path_does_contain_invalid_characters>; | ||
using Parent::Parent; | ||
}; | ||
} // namespace iox | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef IOX_HOOFS_POSIX_VOCABULARY_GROUP_NAME_HPP | ||
#define IOX_HOOFS_POSIX_VOCABULARY_GROUP_NAME_HPP | ||
|
||
#include "iox/semantic_string.hpp" | ||
#include "iox/user_name.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool group_name_does_contain_invalid_characters(const string<platform::MAX_GROUP_NAME_LENGTH>& value) noexcept; | ||
bool group_name_does_contain_invalid_content(const string<platform::MAX_GROUP_NAME_LENGTH>& value) noexcept; | ||
} // namespace details | ||
|
||
/// @brief Represents a POSIX group name | ||
class GroupName : public SemanticString<GroupName, | ||
platform::MAX_GROUP_NAME_LENGTH, | ||
details::group_name_does_contain_invalid_content, | ||
details::group_name_does_contain_invalid_characters> | ||
{ | ||
using Parent = SemanticString<GroupName, | ||
platform::MAX_GROUP_NAME_LENGTH, | ||
details::group_name_does_contain_invalid_content, | ||
details::group_name_does_contain_invalid_characters>; | ||
using Parent::Parent; | ||
}; | ||
} // namespace iox | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef IOX_HOOFS_POSIX_VOCABULARY_PATH_HPP | ||
#define IOX_HOOFS_POSIX_VOCABULARY_PATH_HPP | ||
|
||
#include "iox/file_path.hpp" | ||
#include "iox/semantic_string.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool path_does_contain_invalid_content(const string<platform::IOX_MAX_PATH_LENGTH>& value) noexcept; | ||
} // namespace details | ||
|
||
/// @brief Represents a path to a file or a directory. | ||
class Path : public SemanticString<Path, | ||
platform::IOX_MAX_PATH_LENGTH, | ||
details::path_does_contain_invalid_content, | ||
details::file_path_does_contain_invalid_characters> | ||
{ | ||
using Parent = SemanticString<Path, | ||
platform::IOX_MAX_PATH_LENGTH, | ||
details::path_does_contain_invalid_content, | ||
details::file_path_does_contain_invalid_characters>; | ||
using Parent::Parent; | ||
}; | ||
} // namespace iox | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "iox/file_name.hpp" | ||
#include "iox/filesystem.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool file_name_does_contain_invalid_characters(const string<platform::IOX_MAX_FILENAME_LENGTH>& value) noexcept | ||
{ | ||
const auto valueSize = value.size(); | ||
|
||
for (uint64_t i{0}; i < valueSize; ++i) | ||
{ | ||
// AXIVION Next Construct AutosarC++19_03-A3.9.1: Not used as an integer but as actual character | ||
const char c{value.unchecked_at(i)}; | ||
|
||
const bool isSmallLetter{internal::ASCII_A <= c && c <= internal::ASCII_Z}; | ||
const bool isCapitalLetter{internal::ASCII_CAPITAL_A <= c && c <= internal::ASCII_CAPITAL_Z}; | ||
const bool isNumber{internal::ASCII_0 <= c && c <= internal::ASCII_9}; | ||
const bool isSpecialCharacter{c == internal::ASCII_DASH || c == internal::ASCII_DOT | ||
|| c == internal::ASCII_COLON || c == internal::ASCII_UNDERSCORE}; | ||
|
||
if ((!isSmallLetter && !isCapitalLetter) && (!isNumber && !isSpecialCharacter)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool file_name_does_contain_invalid_content(const string<platform::IOX_MAX_FILENAME_LENGTH>& value) noexcept | ||
{ | ||
return (value.empty() || value == "." || value == ".."); | ||
} | ||
} // namespace details | ||
} // namespace iox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "iox/file_path.hpp" | ||
#include "iox/filesystem.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool file_path_does_contain_invalid_characters(const string<platform::IOX_MAX_PATH_LENGTH>& value) noexcept | ||
{ | ||
const auto valueSize = value.size(); | ||
|
||
for (uint64_t i{0}; i < valueSize; ++i) | ||
{ | ||
// AXIVION Next Construct AutosarC++19_03-A3.9.1: Not used as an integer but as actual character | ||
const char c{value.unchecked_at(i)}; | ||
|
||
const bool isSmallLetter{internal::ASCII_A <= c && c <= internal::ASCII_Z}; | ||
const bool isCapitalLetter{internal::ASCII_CAPITAL_A <= c && c <= internal::ASCII_CAPITAL_Z}; | ||
const bool isNumber{internal::ASCII_0 <= c && c <= internal::ASCII_9}; | ||
const bool isSpecialCharacter{c == internal::ASCII_DASH || c == internal::ASCII_DOT | ||
|| c == internal::ASCII_COLON || c == internal::ASCII_UNDERSCORE}; | ||
|
||
const bool isPathSeparator{[&] { | ||
for (const auto separator : platform::IOX_PATH_SEPARATORS) | ||
{ | ||
if (c == separator) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}()}; | ||
|
||
if ((!isSmallLetter && !isCapitalLetter) && (!isNumber && !isSpecialCharacter) && !isPathSeparator) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool file_path_does_contain_invalid_content(const string<platform::IOX_MAX_PATH_LENGTH>& value) noexcept | ||
{ | ||
return !isValidPathToFile(value); | ||
} | ||
} // namespace details | ||
} // namespace iox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2023 by Apex.AI Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "iceoryx_platform/platform_settings.hpp" | ||
#include "iox/filesystem.hpp" | ||
#include "iox/string.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool group_name_does_contain_invalid_characters(const string<platform::MAX_GROUP_NAME_LENGTH>& value) noexcept | ||
{ | ||
for (uint64_t i = 0; i < value.size(); ++i) | ||
{ | ||
// AXIVION Next Construct AutosarC++19_03-A3.9.1: Not used as an integer but as actual character | ||
const char c{value.unchecked_at(i)}; | ||
|
||
const bool contains_a_to_z = internal::ASCII_A <= c && c <= internal::ASCII_Z; | ||
const bool contains_0_to_9 = internal::ASCII_0 <= c && c <= internal::ASCII_9; | ||
const bool contains_dash = c == internal::ASCII_DASH; | ||
|
||
if (!contains_a_to_z && !contains_0_to_9 && !contains_dash) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool group_name_does_contain_invalid_content(const string<platform::MAX_GROUP_NAME_LENGTH>& value) noexcept | ||
{ | ||
// group name is not allowed to be empty | ||
if (value.empty()) | ||
{ | ||
return true; | ||
} | ||
|
||
// AXIVION Next Construct AutosarC++19_03-A3.9.1: Not used as an integer but as actual character | ||
const char c{value.unchecked_at(0)}; | ||
// a group name is not allowed to start with a number or dash | ||
return (c == internal::ASCII_DASH || (internal::ASCII_0 <= c && c <= internal::ASCII_9)); | ||
} | ||
} // namespace details | ||
} // namespace iox |
Oops, something went wrong.