diff options
author | Zachary Turner <zturner@google.com> | 2016-09-17 02:00:02 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-09-17 02:00:02 +0000 |
commit | 6fa7681bb613f4b92889b55a232507671e8f39be (patch) | |
tree | 2b67bb2fac624c5cda50d4156b9e461dafdac2f1 /lldb/source/Interpreter/Args.cpp | |
parent | 271106cbb9d1ed70d6e57b72612b6653ba20fb10 (diff) | |
download | bcm5719-llvm-6fa7681bb613f4b92889b55a232507671e8f39be.tar.gz bcm5719-llvm-6fa7681bb613f4b92889b55a232507671e8f39be.zip |
Convert many functions to use StringRefs.
Where possible, remove the const char* version. To keep the
risk and impact here minimal, I've only done the simplest
functions.
In the process, I found a few opportunities for adding some
unit tests, so I added those as well.
Tested on Windows, Linux, and OSX.
llvm-svn: 281799
Diffstat (limited to 'lldb/source/Interpreter/Args.cpp')
-rw-r--r-- | lldb/source/Interpreter/Args.cpp | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp index 0edb9bcd02b..b6a60263e8f 100644 --- a/lldb/source/Interpreter/Args.cpp +++ b/lldb/source/Interpreter/Args.cpp @@ -765,37 +765,27 @@ char Args::StringToChar(llvm::StringRef s, char fail_value, bool *success_ptr) { return s[0]; } -const char *Args::StringToVersion(const char *s, uint32_t &major, - uint32_t &minor, uint32_t &update) { +bool Args::StringToVersion(llvm::StringRef string, uint32_t &major, + uint32_t &minor, uint32_t &update) { major = UINT32_MAX; minor = UINT32_MAX; update = UINT32_MAX; - if (s && s[0]) { - char *pos = nullptr; - unsigned long uval32 = ::strtoul(s, &pos, 0); - if (pos == s) - return s; - major = uval32; - if (*pos == '\0') { - return pos; // Decoded major and got end of string - } else if (*pos == '.') { - const char *minor_cstr = pos + 1; - uval32 = ::strtoul(minor_cstr, &pos, 0); - if (pos == minor_cstr) - return pos; // Didn't get any digits for the minor version... - minor = uval32; - if (*pos == '.') { - const char *update_cstr = pos + 1; - uval32 = ::strtoul(update_cstr, &pos, 0); - if (pos == update_cstr) - return pos; - update = uval32; - } - return pos; - } - } - return nullptr; + if (string.empty()) + return false; + + llvm::StringRef major_str, minor_str, update_str; + + std::tie(major_str, minor_str) = string.split('.'); + std::tie(minor_str, update_str) = minor_str.split('.'); + if (major_str.getAsInteger(10, major)) + return false; + if (!minor_str.empty() && minor_str.getAsInteger(10, minor)) + return false; + if (!update_str.empty() && update_str.getAsInteger(10, update)) + return false; + + return true; } const char *Args::GetShellSafeArgument(const FileSpec &shell, |