From eb075660e7cb61b138c2da337115c59857f89e17 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 16 Jul 2008 22:55:07 +0000 Subject: network protocol cleanup, radar test (doesn't work) --- src/auxiliary/functions.cc | 13 ++++++++++++- src/auxiliary/functions.h | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src/auxiliary') diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc index 5edff56..dbfc799 100644 --- a/src/auxiliary/functions.cc +++ b/src/auxiliary/functions.cc @@ -96,7 +96,7 @@ const std::string text_strip_lowercase(const std::string &text) return r; } -const std::string spaces(const std::string &text,size_t n) +const std::string pad_left(const std::string &text,size_t n) { size_t l = text_length(text); if (n <= l) @@ -108,6 +108,17 @@ const std::string spaces(const std::string &text,size_t n) return s; } +const std::string pad_right(const std::string &text,size_t n) +{ + size_t l = text_length(text); + if (n <= l) + return text; + + std::string s(text); + s.append(n-l, ' '); + return s; +} + void to_lowercase(std::string &text) { for (std::string::iterator i = text.begin(); i != text.end(); ++i) diff --git a/src/auxiliary/functions.h b/src/auxiliary/functions.h index e8704d4..557ab45 100644 --- a/src/auxiliary/functions.h +++ b/src/auxiliary/functions.h @@ -35,7 +35,10 @@ inline bool is_color_code(char const *c) { return (is_base_color_code(c) || is_c size_t text_length(const std::string &text); /// prepend spaces to a string up to the desired lenght, excluding color codes -const std::string spaces(const std::string &text, size_t n); +const std::string pad_left(const std::string &text, size_t n); + +/// append spaces to a string up to the desired lenght, excluding color codes +const std::string pad_right(const std::string &text, size_t n); /// convert a string to lowercase void to_lowercase(std::string &text); -- cgit v1.2.3