From ad0335b1ad9188d3cfce02e2e17a79709a6058b5 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Wed, 29 Nov 2017 11:14:35 +0100 Subject: [PATCH] Rename escapeTabValue to escapeConsoleOutputString Also improved documentation on it --- src/dcd/client/client.d | 2 +- src/dcd/common/messages.d | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/dcd/client/client.d b/src/dcd/client/client.d index 315b674..e3bba31 100644 --- a/src/dcd/client/client.d +++ b/src/dcd/client/client.d @@ -348,7 +348,7 @@ Socket createSocket(string socketFile, ushort port) void printDocResponse(ref const AutocompleteResponse response) { import std.algorithm : each; - response.completions.each!(a => a.documentation.escapeTabValue(true).writeln); + response.completions.each!(a => a.documentation.escapeConsoleOutputString(true).writeln); } void printIdentifierResponse(ref const AutocompleteResponse response) diff --git a/src/dcd/common/messages.d b/src/dcd/common/messages.d index 5e7ba37..7341ee3 100644 --- a/src/dcd/common/messages.d +++ b/src/dcd/common/messages.d @@ -188,11 +188,11 @@ struct AutocompleteResponse */ ulong symbolIdentifier; - deprecated("use completions[].documentation + escapeTabValue instead") string[] docComments() @property + deprecated("use completions[].documentation + escapeConsoleOutputString instead") string[] docComments() @property { string[] ret; foreach (ref completion; completions) - ret ~= completion.documentation.escapeTabValue(true); + ret ~= completion.documentation.escapeConsoleOutputString(true); return ret; } @@ -293,8 +293,13 @@ bool serverIsRunning(bool useTCP, string socketFile, ushort port) return false; } -/// Escapes \n, \t and \ in the string. If single is true \t won't be escaped. -string escapeTabValue(string s, bool single = false) +/// Escapes \n, \t and \ in the string. If `single` is true \t won't be escaped. +/// Params: +/// s = the string to escape +/// single = if true, `s` is already tab separated and only needs to be escape new lines. +/// Otherwise `s` is treated as one value that is meant to be printed tab separated with other values. +/// Returns: An escaped string that is safe to print to the console so it can be read line by line +string escapeConsoleOutputString(string s, bool single = false) { import std.array : Appender; @@ -338,5 +343,5 @@ string makeTabSeparated(string[] args...) import std.algorithm : map; import std.array : join; - return args.map!(a => a.escapeTabValue).join("\t"); + return args.map!(a => a.escapeConsoleOutputString).join("\t"); }