Subonsic API: added estimateContentLength parameter support for stream endpoint. fixes #244

This commit is contained in:
emeric
2022-08-20 14:56:16 +02:00
parent 49f0d40515
commit 1fb838c8d0
13 changed files with 162 additions and 104 deletions
+12
View File
@@ -63,6 +63,18 @@ readAs(std::string_view str)
return std::string {str};
}
template<>
std::optional<bool>
readAs(std::string_view str)
{
if (str == "1" || str == "true")
return true;
else if (str == "0" || str == "false")
return false;
return std::nullopt;
}
std::vector<std::string>
splitStringCopy(std::string_view string, std::string_view separators)
{
+5
View File
@@ -85,6 +85,11 @@ template<>
std::optional<std::string>
readAs(std::string_view str);
template<>
[[nodiscard]]
std::optional<bool>
readAs(std::string_view str);
[[nodiscard]]
std::string
replaceInString(std::string_view str, const std::string& from, const std::string& to);
+9
View File
@@ -109,3 +109,12 @@ TEST(StringUtils, escapeString)
EXPECT_EQ(StringUtils::escapeString("**||", "*|", '_'), "_*_*_|_|");
}
TEST(StringUtils, readAs)
{
EXPECT_EQ(StringUtils::readAs<bool>("true"), true);
EXPECT_EQ(StringUtils::readAs<bool>("1"), true);
EXPECT_EQ(StringUtils::readAs<bool>("false"), false);
EXPECT_EQ(StringUtils::readAs<bool>("0"), false);
EXPECT_EQ(StringUtils::readAs<bool>("foo"), std::nullopt);
EXPECT_EQ(StringUtils::readAs<bool>(""), std::nullopt);
}