[Lldb-commits] [lldb] [lldb-vscode] Allow specifying a custom escape prefix for LLDB commands (PR #69238)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 18 19:40:09 PDT 2023


================
@@ -52,12 +52,17 @@ llvm::StringRef GetAsString(const llvm::json::Value &value);
 /// \param[in] key
 ///     The key to use when extracting the value
 ///
+/// \param[in] defaultValue
+///     The default value to return if the key is not present
+///
 /// \return
 ///     A llvm::StringRef that contains the string value for the
-///     specified \a key, or an empty string if there is no key that
+///     specified \a key, or the default value if there is no key that
 ///     matches or if the value is not a string.
-llvm::StringRef GetString(const llvm::json::Object &obj, llvm::StringRef key);
-llvm::StringRef GetString(const llvm::json::Object *obj, llvm::StringRef key);
+llvm::StringRef GetString(const llvm::json::Object &obj, llvm::StringRef key,
+                          llvm::StringRef defaultValue = "");
+llvm::StringRef GetString(const llvm::json::Object *obj, llvm::StringRef key,
+                          llvm::StringRef defaultValue = "");
----------------
clayborg wrote:

Setting `defaultValue` to `""` is different from what it was doing previously when it used to return `lldb::StringRef()`. The latter will return a StringRef with NULL and zero size, where "" will return something with a valid pointer and zero size. So this should be:
```
llvm::StringRef GetString(const llvm::json::Object &obj, llvm::StringRef key,
                          llvm::StringRef defaultValue = llvm::StringRef());
llvm::StringRef GetString(const llvm::json::Object *obj, llvm::StringRef key,
                          llvm::StringRef defaultValue = llvm::StringRef());
```

https://github.com/llvm/llvm-project/pull/69238


More information about the lldb-commits mailing list