mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
Use llvm::Twine instead of llvm::StringRef in several places. (#58)
This commit is contained in:
@@ -17,10 +17,12 @@
|
||||
|
||||
namespace wpi {
|
||||
|
||||
llvm::StringRef UnescapeURI(llvm::StringRef str,
|
||||
llvm::StringRef UnescapeURI(const llvm::Twine& str,
|
||||
llvm::SmallVectorImpl<char>& buf, bool* error) {
|
||||
llvm::SmallString<128> strBuf;
|
||||
llvm::StringRef strStr = str.toStringRef(strBuf);
|
||||
buf.clear();
|
||||
for (auto i = str.begin(), end = str.end(); i != end; ++i) {
|
||||
for (auto i = strStr.begin(), end = strStr.end(); i != end; ++i) {
|
||||
// pass non-escaped characters to output
|
||||
if (*i != '%') {
|
||||
// decode + to space
|
||||
@@ -55,12 +57,14 @@ llvm::StringRef UnescapeURI(llvm::StringRef str,
|
||||
return llvm::StringRef{buf.data(), buf.size()};
|
||||
}
|
||||
|
||||
llvm::StringRef EscapeURI(llvm::StringRef str, llvm::SmallVectorImpl<char>& buf,
|
||||
bool spacePlus) {
|
||||
llvm::StringRef EscapeURI(const llvm::Twine& str,
|
||||
llvm::SmallVectorImpl<char>& buf, bool spacePlus) {
|
||||
static const char *const hexLut = "0123456789ABCDEF";
|
||||
|
||||
llvm::SmallString<128> strBuf;
|
||||
llvm::StringRef strStr = str.toStringRef(strBuf);
|
||||
buf.clear();
|
||||
for (auto i = str.begin(), end = str.end(); i != end; ++i) {
|
||||
for (auto i = strStr.begin(), end = strStr.end(); i != end; ++i) {
|
||||
// pass unreserved characters to output
|
||||
if (std::isalnum(*i) || *i == '-' || *i == '_' || *i == '.' || *i == '~') {
|
||||
buf.push_back(*i);
|
||||
@@ -168,11 +172,11 @@ bool FindMultipartBoundary(raw_istream& is, llvm::StringRef boundary,
|
||||
}
|
||||
}
|
||||
|
||||
HttpLocation::HttpLocation(llvm::StringRef url_, bool* error,
|
||||
HttpLocation::HttpLocation(const llvm::Twine& url_, bool* error,
|
||||
std::string* errorMsg)
|
||||
: url{url_} {
|
||||
: url{url_.str()} {
|
||||
// Split apart into components
|
||||
llvm::StringRef query{url_};
|
||||
llvm::StringRef query{url};
|
||||
|
||||
// scheme:
|
||||
llvm::StringRef scheme;
|
||||
|
||||
@@ -65,11 +65,11 @@ void raw_mem_istream::read_impl(void* data, std::size_t len) {
|
||||
m_left -= len;
|
||||
}
|
||||
|
||||
static int getFD(llvm::StringRef Filename, std::error_code &EC) {
|
||||
static int getFD(const llvm::Twine& Filename, std::error_code &EC) {
|
||||
// Handle "-" as stdin. Note that when we do this, we consider ourself
|
||||
// the owner of stdin. This means that we can do things like close the
|
||||
// file descriptor when we're done and set the "binary" flag globally.
|
||||
if (Filename == "-") {
|
||||
if (Filename.isSingleStringRef() && Filename.getSingleStringRef() == "-") {
|
||||
EC = std::error_code();
|
||||
return STDIN_FILENO;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ static int getFD(llvm::StringRef Filename, std::error_code &EC) {
|
||||
return FD;
|
||||
}
|
||||
|
||||
raw_fd_istream::raw_fd_istream(llvm::StringRef filename, std::error_code& ec,
|
||||
raw_fd_istream::raw_fd_istream(const llvm::Twine& filename, std::error_code& ec,
|
||||
std::size_t bufSize)
|
||||
: raw_fd_istream(getFD(filename, ec), true, bufSize) {}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "llvm/SmallVector.h"
|
||||
#include "llvm/StringMap.h"
|
||||
#include "llvm/StringRef.h"
|
||||
#include "llvm/Twine.h"
|
||||
#include "support/raw_istream.h"
|
||||
#include "support/raw_socket_istream.h"
|
||||
#include "support/raw_socket_ostream.h"
|
||||
@@ -27,14 +28,15 @@ namespace wpi {
|
||||
// @param buf Buffer for output
|
||||
// @param error Set to true if an error occurred
|
||||
// @return Escaped string
|
||||
llvm::StringRef UnescapeURI(llvm::StringRef str,
|
||||
llvm::StringRef UnescapeURI(const llvm::Twine& str,
|
||||
llvm::SmallVectorImpl<char>& buf, bool* error);
|
||||
|
||||
// Escape a string with %xx-encoding.
|
||||
// @param buf Buffer for output
|
||||
// @param spacePlus If true, encodes spaces to '+' rather than "%20"
|
||||
// @return Escaped string
|
||||
llvm::StringRef EscapeURI(llvm::StringRef str, llvm::SmallVectorImpl<char>& buf,
|
||||
llvm::StringRef EscapeURI(const llvm::Twine& str,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
bool spacePlus = true);
|
||||
|
||||
// Parse a set of HTTP headers. Saves just the Content-Type and Content-Length
|
||||
@@ -60,7 +62,7 @@ bool FindMultipartBoundary(wpi::raw_istream& is, llvm::StringRef boundary,
|
||||
class HttpLocation {
|
||||
public:
|
||||
HttpLocation() = default;
|
||||
HttpLocation(llvm::StringRef url_, bool* error, std::string* errorMsg);
|
||||
HttpLocation(const llvm::Twine& url_, bool* error, std::string* errorMsg);
|
||||
|
||||
std::string url; // retain copy
|
||||
std::string user; // unescaped
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace llvm {
|
||||
template <typename T>
|
||||
class SmallVectorImpl;
|
||||
class StringRef;
|
||||
class Twine;
|
||||
}
|
||||
|
||||
namespace wpi {
|
||||
@@ -94,7 +95,7 @@ class raw_mem_istream : public raw_istream {
|
||||
|
||||
class raw_fd_istream : public raw_istream {
|
||||
public:
|
||||
raw_fd_istream(llvm::StringRef filename, std::error_code& ec,
|
||||
raw_fd_istream(const llvm::Twine& filename, std::error_code& ec,
|
||||
std::size_t bufSize = 4096);
|
||||
raw_fd_istream(int fd, bool shouldClose, std::size_t bufSize = 4096);
|
||||
~raw_fd_istream() override;
|
||||
|
||||
Reference in New Issue
Block a user