Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WStringStream to accept const char strings #135

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Wt/Dbo/StringStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <Wt/WDllDefs.h>

#include <iostream>
#include <cstring>
#include <string>
#include <vector>

Expand Down
7 changes: 0 additions & 7 deletions src/Wt/WStringStream.C
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@ WStringStream& WStringStream::operator<< (char c)
return *this;
}

WStringStream& WStringStream::operator<< (char *s)
{
append(s, std::strlen(s));

return *this;
}

WStringStream& WStringStream::operator<< (const std::string& s)
{
append(s.data(), s.length());
Expand Down
26 changes: 7 additions & 19 deletions src/Wt/WStringStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define WT_WSTRING_STREAM_H_

#include <Wt/WDllDefs.h>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -98,31 +99,18 @@ class WT_API WStringStream
*/
void append(const char *s, int length);

#ifndef WT_TARGET_JAVA
/*
* Should not be implemented but is needed to support the specialization
* for string literals !
*/
template <typename T>
inline WStringStream& operator<< (T t) {
WStringStream please_cast_to_a_supported_type = t;
please_cast_to_a_supported_type << 'a'; // silence compiler for normal case
return *this;
}

template <std::size_t N>
WStringStream& operator<< (const char (&s)[N]) {
append(s, N-1); return *this;
}
#endif // WT_TARGET_JAVA

/*! \brief Appends a character.
*/
WStringStream& operator<< (char);

/*! \brief Appends a C string.
*/
WStringStream& operator<< (char *s);
WStringStream& operator<< (const char *s)
{
append(s, std::strlen(s));

return *this;
}

/*! \brief Appends a C++ string.
*/
Expand Down
10 changes: 0 additions & 10 deletions src/web/EscapeOStream.C
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,6 @@ void EscapeOStream::append(const char *s, std::size_t len)
put(s, *this);
}

EscapeOStream& EscapeOStream::operator<< (char *s)
{
if (c_special_ == 0)
stream_ << s;
else
put(s, *this);

return *this;
}

void EscapeOStream::append(const std::string& s, const EscapeOStream& rules)
{
if (rules.c_special_ == 0)
Expand Down
23 changes: 9 additions & 14 deletions src/web/EscapeOStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,17 @@ class WT_API EscapeOStream
void append(const std::string& s, const EscapeOStream& rules);
void append(const char *s, std::size_t len);

#ifndef WT_TARGET_JAVA
/*
* Should not be implemented but is needed to support the specialization
* for string literals !
*/
template <typename T>
inline EscapeOStream& operator<< (T t);

template <std::size_t N>
EscapeOStream& operator<< (const char (&s)[N]) {
append(s, N-1); return *this;
EscapeOStream& operator<< (char);
EscapeOStream& operator<< (const char *s)
{
if (c_special_ == 0)
stream_ << s;
else
put(s, *this);

return *this;
}
#endif // WT_TARGET_JAVA

EscapeOStream& operator<< (char);
EscapeOStream& operator<< (char *s);
EscapeOStream& operator<< (const std::string& s);
EscapeOStream& operator<< (int);
EscapeOStream& operator<< (long long);
Expand Down