/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include namespace MCore { const char* CharacterConstants::wordSeparators = " \n\t"; AZStd::string GenerateUniqueString(const char* prefix, const AZStd::function& validationFunction) { MCORE_ASSERT(validationFunction); const AZStd::string prefixString = prefix; // find the last letter index from the right size_t lastIndex = AZStd::string::npos; const size_t numCharacters = prefixString.size(); for (size_t i = numCharacters - 1; i >= 0; --i) { if (!AZStd::is_digit(prefixString[i])) { lastIndex = i + 1; break; } } // copy the string AZStd::string nameWithoutLastDigits = prefixString.substr(0, lastIndex); // remove all space on the right AzFramework::StringFunc::TrimWhiteSpace(nameWithoutLastDigits, false /* leading */, true /* trailing */); // generate the unique name uint32 nameIndex = 0; AZStd::string uniqueName = nameWithoutLastDigits + "0"; while (validationFunction(uniqueName) == false) { uniqueName = nameWithoutLastDigits + AZStd::to_string(++nameIndex); } return uniqueName; } AZStd::string ConstructStringSeparatedBySemicolons(const AZStd::vector& stringVec) { AZStd::string result; for (const AZStd::string& currentString : stringVec) { if (!result.empty()) { result += CharacterConstants::semiColon; } result += currentString; } return result; } } namespace AZStd { void to_string(string& str, bool value) { str = value ? "true" : "false"; } void to_string(string& str, const AZ::Vector2& value) { str = AZStd::string::format("%.8f,%.8f", static_cast(value.GetX()), static_cast(value.GetY())); } void to_string(string& str, const AZ::Vector3& value) { str = AZStd::string::format("%.8f,%.8f,%.8f", static_cast(value.GetX()), static_cast(value.GetY()), static_cast(value.GetZ())); } void to_string(string& str, const AZ::Vector4& value) { str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f", static_cast(value.GetX()), static_cast(value.GetY()), static_cast(value.GetZ()), static_cast(value.GetW())); } void to_string(string& str, const AZ::Quaternion& value) { str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f", static_cast(value.GetX()), static_cast(value.GetY()), static_cast(value.GetZ()), static_cast(value.GetW())); } void to_string(string& str, const AZ::Matrix4x4& value) { str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f", static_cast(value(0, 0)), static_cast(value(1, 0)), static_cast(value(2, 0)), static_cast(value(3, 0)), static_cast(value(0, 1)), static_cast(value(1, 1)), static_cast(value(2, 1)), static_cast(value(3, 1)), static_cast(value(0, 2)), static_cast(value(1, 2)), static_cast(value(2, 2)), static_cast(value(3, 2)), static_cast(value(0, 3)), static_cast(value(1, 3)), static_cast(value(2, 3)), static_cast(value(3, 3))); } void to_string(string& str, const AZ::Transform& value) { str = AZStd::string::format("%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f", static_cast(value(0, 0)), static_cast(value(1, 0)), static_cast(value(2, 0)), static_cast(value(0, 1)), static_cast(value(1, 1)), static_cast(value(2, 1)), static_cast(value(0, 2)), static_cast(value(1, 2)), static_cast(value(2, 2)), static_cast(value(0, 3)), static_cast(value(1, 3)), static_cast(value(2, 3))); } }