diff options
Diffstat (limited to 'src/support')
-rw-r--r-- | src/support/file.cpp | 8 | ||||
-rw-r--r-- | src/support/file.h | 6 | ||||
-rw-r--r-- | src/support/string.h | 10 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/support/file.cpp b/src/support/file.cpp index b4c410b5e..68ffbb5ac 100644 --- a/src/support/file.cpp +++ b/src/support/file.cpp @@ -77,6 +77,14 @@ T wasm::read_file(const std::string& filename, return input; } +std::string wasm::read_possible_response_file(const std::string& input) { + if (input.size() == 0 || input[0] != '@') { + return input; + } + return wasm::read_file<std::string>( + input.substr(1), Flags::Text, Flags::Release); +} + // Explicit instantiations for the explicit specializations. template std::string wasm::read_file<>(const std::string&, Flags::BinaryOption, Flags::DebugOption); diff --git a/src/support/file.h b/src/support/file.h index 67d63315b..fb3cad564 100644 --- a/src/support/file.h +++ b/src/support/file.h @@ -39,12 +39,18 @@ template<typename T> T read_file(const std::string& filename, Flags::BinaryOption binary, Flags::DebugOption debug); + // Declare the valid explicit specializations. extern template std::string read_file<>(const std::string&, Flags::BinaryOption, Flags::DebugOption); extern template std::vector<char> read_file<>(const std::string&, Flags::BinaryOption, Flags::DebugOption); +// Given a string which may be a response file (i.e., a filename starting +// with "@"), if it is a response file read it and return that, or if it +// is not a response file, return it as is. +std::string read_possible_response_file(const std::string&); + class Output { public: // An empty filename will open stdout instead. diff --git a/src/support/string.h b/src/support/string.h index 72bbdb509..b3d12c6ae 100644 --- a/src/support/string.h +++ b/src/support/string.h @@ -21,6 +21,7 @@ #ifndef wasm_support_string_h #define wasm_support_string_h +#include <cctype> #include <string> #include <vector> @@ -104,6 +105,15 @@ inline bool wildcardMatch(const std::string& pattern, return value.size() == pattern.size(); } +// Removes any extra whitespace or \0. +inline std::string trim(const std::string& input) { + size_t size = input.size(); + while (size > 0 && (isspace(input[size - 1]) || input[size - 1] == '\0')) { + size--; + } + return input.substr(0, size); +} + } // namespace String } // namespace wasm |