================
@@ -240,6 +241,121 @@ inline std::string StripAnsiTerminalCodes(llvm::StringRef
str) {
return stripped;
}
+inline size_t ColumnWidth(llvm::StringRef str) {
+ std::string stripped = ansi::StripAnsiTerminalCodes(str);
+ return llvm::sys::locale::columnWidth(stripped);
+}
+
+/// Trim the given string to the given visible length, at a word boundary.
+/// Visible length means its width when rendered to the terminal.
+/// The string can include ANSI codes and Unicode.
+///
+/// For a single word string, that word is returned in its entirety regardless
+/// of it's visible length.
+///
+/// This function is similar to TrimAndPad, except that it must split on a word
+/// boundary. So there are some noteable differences:
+/// * Has a special case for single words that exceed desired visible
+/// length.
+/// * Must track whether the most recent modifications was on a word boundary
+/// or not.
+/// * If the trimming finishes without the result ending on a word boundary,
+/// it must find the nearest boundary to that trim point by trimming more.
+inline std::string TrimAtWordBoundary(llvm::StringRef str,
----------------
DavidSpickett wrote:
I think this could return a StringRef, but that would make it diverge from
TrimAndPad more. So I'd prefer to do that in its own change, if this PR is
accepted.
It seems like it would work, since TrimAtWordBoundary never needs to add
characters. Won't avoid all copies, because we have to do some ANSI removal
during the loop.
https://github.com/llvm/llvm-project/pull/183314
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits