1 #include "utils/string_utils.hpp" 2 3 #include "utils/dbus_path_utils.hpp" 4 5 #include <cmath> 6 7 namespace details 8 { 9 constexpr std::string_view allowedCharactersInId = 10 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; 11 repeat(size_t n)12std::string repeat(size_t n) 13 { 14 std::string result; 15 for (size_t i = 0; i < n; i++) 16 { 17 result += allowedCharactersInId; 18 } 19 return result; 20 } 21 getString(size_t length)22std::string getString(size_t length) 23 { 24 return details::repeat( 25 std::ceil(static_cast<double>(length) / 26 static_cast<double>(allowedCharactersInId.length()))) 27 .substr(0, length); 28 } 29 getStringWithSpaces(size_t length)30std::string getStringWithSpaces(size_t length) 31 { 32 std::string result = getString(length); 33 size_t idx = 1; 34 while (idx < length) 35 { 36 result[idx] = ' '; 37 idx += 5; 38 } 39 return result; 40 } 41 } // namespace details 42 43 namespace utils::string_utils 44 { getMaxPrefix()45std::string getMaxPrefix() 46 { 47 return details::getString(constants::maxPrefixLength); 48 } 49 getMaxId()50std::string getMaxId() 51 { 52 return details::getString(constants::maxIdNameLength); 53 } 54 getMaxName()55std::string getMaxName() 56 { 57 return details::getStringWithSpaces(constants::maxIdNameLength); 58 } 59 getTooLongPrefix()60std::string getTooLongPrefix() 61 { 62 return details::getString(constants::maxPrefixLength + 1); 63 } 64 getTooLongId()65std::string getTooLongId() 66 { 67 return details::getString(constants::maxIdNameLength + 1); 68 } 69 getTooLongName()70std::string getTooLongName() 71 { 72 return details::getStringWithSpaces(constants::maxIdNameLength + 1); 73 } 74 } // namespace utils::string_utils 75