From e1dddce2392b13e6019af64c3fc4b0b245cdb32e Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Tue, 20 Oct 2020 11:08:58 -0700 Subject: [PATCH] remove azure hpp (#809) Remove Azure.hpp Make Azure/Core/Strings.hpp public Move ToLower and InvariantIsEqual to Strings.hpp Also removing `AZURE_UNREFERENCED_PARAMETER` fixes: https://github.com/Azure/azure-sdk-for-cpp/issues/811 --- sdk/core/azure-core/CHANGELOG.md | 4 +++ .../azure-core/inc/azure/core/http/policy.hpp | 1 - .../inc/azure/core/logging/logging.hpp | 2 -- .../inc/azure/core/{azure.hpp => strings.hpp} | 16 +++--------- sdk/core/azure-core/src/http/curl/curl.cpp | 1 - sdk/core/azure-core/src/http/raw_response.cpp | 4 +-- sdk/core/azure-core/src/http/request.cpp | 10 +++---- .../azure-core/src/http/transport_policy.cpp | 2 +- sdk/core/azure-core/src/http/url.cpp | 4 +-- .../src/http/winhttp/win_http_transport.cpp | 5 ++-- sdk/core/azure-core/src/strings.cpp | 6 ++--- sdk/core/azure-core/test/ut/string.cpp | 6 ++--- .../src/shared_key_policy.cpp | 26 +++++++++---------- 13 files changed, 38 insertions(+), 49 deletions(-) rename sdk/core/azure-core/inc/azure/core/{azure.hpp => strings.hpp} (53%) diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 7ba346f4c..7182cd8f9 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -5,6 +5,10 @@ ### Breaking Changes - `Azure::Core::Http::Url::AppendPath` now does not encode the input by default. +- Removed `azure.hpp`. + +### New Features +- Added `strings.hpp` with `Azure::Core::Strings::LocaleInvariantCaseInsensitiveEqual` and `Azure::Core::Strings::ToLower`. ### Other changes and Improvements diff --git a/sdk/core/azure-core/inc/azure/core/http/policy.hpp b/sdk/core/azure-core/inc/azure/core/http/policy.hpp index 470810cfa..85fb3868d 100644 --- a/sdk/core/azure-core/inc/azure/core/http/policy.hpp +++ b/sdk/core/azure-core/inc/azure/core/http/policy.hpp @@ -8,7 +8,6 @@ #pragma once -#include "azure/core/azure.hpp" #include "azure/core/context.hpp" #include "azure/core/http/http.hpp" #include "azure/core/http/transport.hpp" diff --git a/sdk/core/azure-core/inc/azure/core/logging/logging.hpp b/sdk/core/azure-core/inc/azure/core/logging/logging.hpp index 0f5542943..38c54b898 100644 --- a/sdk/core/azure-core/inc/azure/core/logging/logging.hpp +++ b/sdk/core/azure-core/inc/azure/core/logging/logging.hpp @@ -9,8 +9,6 @@ #pragma once -#include "azure/core/azure.hpp" - #include #include #include diff --git a/sdk/core/azure-core/inc/azure/core/azure.hpp b/sdk/core/azure-core/inc/azure/core/strings.hpp similarity index 53% rename from sdk/core/azure-core/inc/azure/core/azure.hpp rename to sdk/core/azure-core/inc/azure/core/strings.hpp index c6de367e2..a4df0e195 100644 --- a/sdk/core/azure-core/inc/azure/core/azure.hpp +++ b/sdk/core/azure-core/inc/azure/core/strings.hpp @@ -2,25 +2,17 @@ // SPDX-License-Identifier: MIT /** - * @file - * @brief Common definitions. + * @brief Public utility functions for strings. + * */ - #pragma once -#include "azure/core/internal/contract.hpp" - #include -/** - * @brief Used in implementations to mark an unreferenced function parameter. - */ -#define AZURE_UNREFERENCED_PARAMETER(x) ((void)(x)); - -namespace Azure { namespace Core { namespace Details { +namespace Azure { namespace Core { namespace Strings { bool LocaleInvariantCaseInsensitiveEqual(const std::string& lhs, const std::string& rhs) noexcept; std::string const ToLower(const std::string& src) noexcept; unsigned char ToLower(const unsigned char src) noexcept; -}}} // namespace Azure::Core::Details +}}} // namespace Azure::Core::Strings diff --git a/sdk/core/azure-core/src/http/curl/curl.cpp b/sdk/core/azure-core/src/http/curl/curl.cpp index 9def28627..48522c799 100644 --- a/sdk/core/azure-core/src/http/curl/curl.cpp +++ b/sdk/core/azure-core/src/http/curl/curl.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: MIT #include "azure/core/http/curl/curl.hpp" -#include "azure/core/azure.hpp" #include "azure/core/http/http.hpp" #include "azure/core/internal/log.hpp" diff --git a/sdk/core/azure-core/src/http/raw_response.cpp b/sdk/core/azure-core/src/http/raw_response.cpp index 33c3b4d7c..4e5c896cf 100644 --- a/sdk/core/azure-core/src/http/raw_response.cpp +++ b/sdk/core/azure-core/src/http/raw_response.cpp @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include "azure/core/azure.hpp" #include "azure/core/http/http.hpp" +#include "azure/core/strings.hpp" #include #include @@ -32,7 +32,7 @@ void RawResponse::AddHeader(uint8_t const* const begin, uint8_t const* const las } // Always toLower() headers - auto headerName = Azure::Core::Details::ToLower(std::string(start, end)); + auto headerName = Azure::Core::Strings::ToLower(std::string(start, end)); start = end + 1; // start value while (start < last && (*start == ' ' || *start == '\t')) { diff --git a/sdk/core/azure-core/src/http/request.cpp b/sdk/core/azure-core/src/http/request.cpp index a08c634a7..2566b47c3 100644 --- a/sdk/core/azure-core/src/http/request.cpp +++ b/sdk/core/azure-core/src/http/request.cpp @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include "azure/core/azure.hpp" #include "azure/core/http/http.hpp" +#include "azure/core/strings.hpp" #include #include @@ -24,12 +24,10 @@ static std::map MergeMaps( void Request::AddHeader(std::string const& name, std::string const& value) { - auto headerNameLowerCase = Azure::Core::Details::ToLower(name); + auto headerNameLowerCase = Azure::Core::Strings::ToLower(name); return this->m_retryModeEnabled - ? Details::InsertHeaderWithValidation( - this->m_retryHeaders, headerNameLowerCase, value) - : Details::InsertHeaderWithValidation( - this->m_headers, headerNameLowerCase, value); + ? Details::InsertHeaderWithValidation(this->m_retryHeaders, headerNameLowerCase, value) + : Details::InsertHeaderWithValidation(this->m_headers, headerNameLowerCase, value); } void Request::RemoveHeader(std::string const& name) diff --git a/sdk/core/azure-core/src/http/transport_policy.cpp b/sdk/core/azure-core/src/http/transport_policy.cpp index d3b53180e..44e58096c 100644 --- a/sdk/core/azure-core/src/http/transport_policy.cpp +++ b/sdk/core/azure-core/src/http/transport_policy.cpp @@ -10,7 +10,7 @@ std::unique_ptr TransportPolicy::Send( Request& request, NextHttpPolicy nextHttpPolicy) const { - AZURE_UNREFERENCED_PARAMETER(nextHttpPolicy); + (void)nextHttpPolicy; /** * The transport policy is always the last policy. * Call the transport and return diff --git a/sdk/core/azure-core/src/http/url.cpp b/sdk/core/azure-core/src/http/url.cpp index d389221ff..26f527603 100644 --- a/sdk/core/azure-core/src/http/url.cpp +++ b/sdk/core/azure-core/src/http/url.cpp @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include "azure/core/azure.hpp" #include "azure/core/http/http.hpp" +#include "azure/core/strings.hpp" #include #include @@ -20,7 +20,7 @@ Url::Url(const std::string& url) if (schemeIter != std::string::npos) { std::transform(url.begin(), url.begin() + schemeIter, std::back_inserter(m_scheme), [](char c) { - return static_cast(Azure::Core::Details::ToLower(static_cast(c))); + return static_cast(Azure::Core::Strings::ToLower(static_cast(c))); }); pos = url.begin() + schemeIter + schemeEnd.length(); diff --git a/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp b/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp index 297828529..17cf77975 100644 --- a/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp +++ b/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include "azure/core/azure.hpp" #include "azure/core/http/http.hpp" #include "azure/core/http/winhttp/win_http_client.hpp" @@ -15,8 +14,8 @@ WinHttpTansport::~WinHttpTansport() {} std::unique_ptr WinHttpTansport::Send(Context const& context, Request& request) { - AZURE_UNREFERENCED_PARAMETER(context); - AZURE_UNREFERENCED_PARAMETER(request); + void(context); + void(request); throw; } diff --git a/sdk/core/azure-core/src/strings.cpp b/sdk/core/azure-core/src/strings.cpp index 250905c72..cac9021ad 100644 --- a/sdk/core/azure-core/src/strings.cpp +++ b/sdk/core/azure-core/src/strings.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include "azure/core/azure.hpp" +#include "azure/core/strings.hpp" #include @@ -67,7 +67,7 @@ const unsigned char c_LocaleInvariantLowercaseTable[256] = { }; } // unnamed namespace -namespace Azure { namespace Core { namespace Details { +namespace Azure { namespace Core { namespace Strings { unsigned char ToLower(const unsigned char symbol) noexcept { @@ -97,4 +97,4 @@ namespace Azure { namespace Core { namespace Details { }); } -}}} // namespace Azure::Core::Details +}}} // namespace Azure::Core::Strings diff --git a/sdk/core/azure-core/test/ut/string.cpp b/sdk/core/azure-core/test/ut/string.cpp index e4babc2d7..8e0e8d9ae 100644 --- a/sdk/core/azure-core/test/ut/string.cpp +++ b/sdk/core/azure-core/test/ut/string.cpp @@ -1,13 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT +#include "azure/core/strings.hpp" #include "gtest/gtest.h" -#include #include TEST(String, invariantCompare) { - using Azure::Core::Details::LocaleInvariantCaseInsensitiveEqual; + using Azure::Core::Strings::LocaleInvariantCaseInsensitiveEqual; EXPECT_TRUE(LocaleInvariantCaseInsensitiveEqual("", "")); EXPECT_TRUE(LocaleInvariantCaseInsensitiveEqual("a", "a")); EXPECT_TRUE(LocaleInvariantCaseInsensitiveEqual("A", "a")); @@ -22,7 +22,7 @@ TEST(String, invariantCompare) TEST(String, toLower) { - using Azure::Core::Details::ToLower; + using Azure::Core::Strings::ToLower; EXPECT_TRUE(ToLower("") == ""); EXPECT_TRUE(ToLower("a") == "a"); EXPECT_TRUE(ToLower("A") == "a"); diff --git a/sdk/storage/azure-storage-common/src/shared_key_policy.cpp b/sdk/storage/azure-storage-common/src/shared_key_policy.cpp index 96bc71412..4cc715068 100644 --- a/sdk/storage/azure-storage-common/src/shared_key_policy.cpp +++ b/sdk/storage/azure-storage-common/src/shared_key_policy.cpp @@ -4,6 +4,7 @@ #include "azure/storage/common/shared_key_policy.hpp" #include "azure/core/http/http.hpp" +#include "azure/core/strings.hpp" #include "azure/storage/common/crypt.hpp" #include @@ -16,20 +17,19 @@ namespace Azure { namespace Storage { string_to_sign += Azure::Core::Http::HttpMethodToString(request.GetMethod()) + "\n"; const auto& headers = request.GetHeaders(); - for (std::string headerName : - {"Content-Encoding", - "Content-Language", - "Content-Length", - "Content-MD5", - "Content-Type", - "Date", - "If-Modified-Since", - "If-Match", - "If-None-Match", - "If-Unmodified-Since", - "Range"}) + for (std::string headerName : {"Content-Encoding", + "Content-Language", + "Content-Length", + "Content-MD5", + "Content-Type", + "Date", + "If-Modified-Since", + "If-Match", + "If-None-Match", + "If-Unmodified-Since", + "Range"}) { - auto ite = headers.find(Azure::Core::Details::ToLower(headerName)); + auto ite = headers.find(Azure::Core::Strings::ToLower(headerName)); if (ite != headers.end()) { if (headerName == "Content-Length" && ite->second == "0")