Commit c80c8e6c authored by Victor Zverovich's avatar Victor Zverovich Committed by Facebook GitHub Bot

Move toStdString to FBString.h

Summary: Move `toStdString` to `FBString.h` because it's fbstring-related and remove the dependency between `String.h` and `FBString.h`. This is possible because the only other use of fbstring in `String.h` is removed in previous diff.

Reviewed By: yfeldblum

Differential Revision: D20195591

fbshipit-source-id: b5ff7c918669e063e24bf91155a2496f82d7e975
parent e5ccead7
...@@ -2806,6 +2806,23 @@ typedef basic_fbstring<char> fbstring; ...@@ -2806,6 +2806,23 @@ typedef basic_fbstring<char> fbstring;
template <class T, class R, class A, class S> template <class T, class R, class A, class S>
FOLLY_ASSUME_RELOCATABLE(basic_fbstring<T, R, A, S>); FOLLY_ASSUME_RELOCATABLE(basic_fbstring<T, R, A, S>);
// Compatibility function, to make sure toStdString(s) can be called
// to convert a std::string or fbstring variable s into type std::string
// with very little overhead if s was already std::string
inline std::string toStdString(const folly::fbstring& s) {
return std::string(s.data(), s.size());
}
inline const std::string& toStdString(const std::string& s) {
return s;
}
// If called with a temporary, the compiler will select this overload instead
// of the above, so we don't return a (lvalue) reference to a temporary.
inline std::string&& toStdString(std::string&& s) {
return std::move(s);
}
} // namespace folly } // namespace folly
// Hash functions to make fbstring usable with e.g. unordered_map // Hash functions to make fbstring usable with e.g. unordered_map
......
...@@ -26,31 +26,13 @@ ...@@ -26,31 +26,13 @@
#include <folly/Conv.h> #include <folly/Conv.h>
#include <folly/ExceptionString.h> #include <folly/ExceptionString.h>
#include <folly/FBString.h>
#include <folly/Portability.h> #include <folly/Portability.h>
#include <folly/Range.h> #include <folly/Range.h>
#include <folly/ScopeGuard.h> #include <folly/ScopeGuard.h>
#include <folly/Traits.h> #include <folly/Traits.h>
// Compatibility function, to make sure toStdString(s) can be called
// to convert a std::string or fbstring variable s into type std::string
// with very little overhead if s was already std::string
namespace folly { namespace folly {
inline std::string toStdString(const folly::fbstring& s) {
return std::string(s.data(), s.size());
}
inline const std::string& toStdString(const std::string& s) {
return s;
}
// If called with a temporary, the compiler will select this overload instead
// of the above, so we don't return a (lvalue) reference to a temporary.
inline std::string&& toStdString(std::string&& s) {
return std::move(s);
}
/** /**
* C-Escape a string, making it suitable for representation as a C string * C-Escape a string, making it suitable for representation as a C string
* literal. Appends the result to the output string. * literal. Appends the result to the output string.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment