forked from eclipse-iceoryx/iceoryx
-
Notifications
You must be signed in to change notification settings - Fork 0
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 eclipse-iceoryx#1943 from ApexAI/iox-1942-introduc…
…e-semantic-string Iox 1942 introduce semantic string
- Loading branch information
Showing
8 changed files
with
1,121 additions
and
4 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
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,43 @@ | ||
// 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_USER_NAME_HPP | ||
#define IOX_HOOFS_POSIX_VOCABULARY_USER_NAME_HPP | ||
|
||
#include "iox/semantic_string.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool user_name_does_contain_invalid_characters(const string<platform::MAX_USER_NAME_LENGTH>& value) noexcept; | ||
bool user_name_does_contain_invalid_content(const string<platform::MAX_USER_NAME_LENGTH>& value) noexcept; | ||
} // namespace details | ||
|
||
class UserName : public SemanticString<UserName, | ||
platform::MAX_USER_NAME_LENGTH, | ||
details::user_name_does_contain_invalid_content, | ||
details::user_name_does_contain_invalid_characters> | ||
{ | ||
using Parent = SemanticString<UserName, | ||
platform::MAX_USER_NAME_LENGTH, | ||
details::user_name_does_contain_invalid_content, | ||
details::user_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,58 @@ | ||
// 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/string.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace details | ||
{ | ||
bool user_name_does_contain_invalid_characters(const string<platform::MAX_USER_NAME_LENGTH>& value) noexcept | ||
{ | ||
for (uint64_t i = 0; i < value.size(); ++i) | ||
{ | ||
const bool contains_a_to_z = 'a' <= value[i] && value[i] <= 'z'; | ||
const bool contains_0_to_9 = '0' <= value[i] && value[i] <= '9'; | ||
const bool contains_dash = value[i] == '-'; | ||
|
||
if (!contains_a_to_z && !contains_0_to_9 && !contains_dash) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool user_name_does_contain_invalid_content(const string<platform::MAX_USER_NAME_LENGTH>& value) noexcept | ||
{ | ||
// user name is not allowed to be empty | ||
if (value.empty()) | ||
{ | ||
return true; | ||
} | ||
|
||
// a user name is not allowed to start with a number or dash | ||
if (value[0] == '-' || ('0' <= value[0] && value[0] <= '9')) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} // namespace details | ||
} // namespace iox |
Oops, something went wrong.