Skip to content

Commit 4a9f5f8

Browse files
committed
Merge pull request #80 from glynos/uri_builder_non_array_string_literals
Added tests for const and non-const non array string literals with the uri_builder.
2 parents adba3f9 + 1dbdf54 commit 4a9f5f8

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

include/network/uri/detail/translate.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ struct translate_impl<char[N]> {
2323
std::string operator()(const char *source) const { return source; }
2424
};
2525

26+
template <>
27+
struct translate_impl<char *> {
28+
std::string operator()(const char *source) const { return source; }
29+
};
30+
31+
template <>
32+
struct translate_impl<const char *> {
33+
std::string operator()(const char *source) const { return source; }
34+
};
35+
2636
template <int N>
2737
struct translate_impl<const char[N]> {
2838
std::string operator()(const char *source) const { return source; }
@@ -51,6 +61,22 @@ struct translate_impl<wchar_t[N]> {
5161
}
5262
};
5363

64+
template <>
65+
struct translate_impl<wchar_t *> {
66+
std::string operator()(const wchar_t *source) const {
67+
translate_impl<std::wstring> impl;
68+
return impl(source);
69+
}
70+
};
71+
72+
template <>
73+
struct translate_impl<const wchar_t *> {
74+
std::string operator()(const wchar_t *source) const {
75+
translate_impl<std::wstring> impl;
76+
return impl(source);
77+
}
78+
};
79+
5480
template <typename Source>
5581
inline std::string translate(const Source &source) {
5682
translate_impl<Source> impl;

test/uri_builder_test.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,3 +722,29 @@ TEST(builder_test, path_should_be_prefixed_with_slash_2) {
722722
.scheme("ftp").host("127.0.0.1").path("noleadingslash/foo.txt");
723723
ASSERT_EQ("/noleadingslash/foo.txt", builder.uri().path());
724724
}
725+
726+
TEST(builder, non_array_string_literals_should_work) {
727+
const char* p = "http";
728+
const char* q = "foo";
729+
network::uri_builder builder;
730+
731+
builder
732+
.scheme(p)
733+
.host("example.com")
734+
.path(q)
735+
;
736+
ASSERT_EQ("http://example.com/foo", builder.uri());
737+
}
738+
739+
TEST(builder, non_const_non_array_string_literals_should_work) {
740+
const char* p = "http";
741+
const char* q = "foo";
742+
network::uri_builder builder;
743+
744+
builder
745+
.scheme(const_cast<char *>(p))
746+
.host("example.com")
747+
.path(const_cast<char *>(q))
748+
;
749+
ASSERT_EQ("http://example.com/foo", builder.uri());
750+
}

0 commit comments

Comments
 (0)