Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-05-24 10:10:37 +0000
committerStijn Buys <ingar@osirion.org>2008-05-24 10:10:37 +0000
commita010f94390422eefa366a5f390c1f9e3ccc66fd5 (patch)
tree798f63addb6931fb08208927afff509185709c7c /src/auxiliary
parent4a4a5473b82d1f5b6f654cabac99272bce89854b (diff)
text_length functions, improved lighting, r_bbox draws bounding boxes
Diffstat (limited to 'src/auxiliary')
-rw-r--r--src/auxiliary/functions.cc28
-rw-r--r--src/auxiliary/functions.h9
2 files changed, 36 insertions, 1 deletions
diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc
index 373a6f0..2b42bae 100644
--- a/src/auxiliary/functions.cc
+++ b/src/auxiliary/functions.cc
@@ -48,4 +48,32 @@ const std::string article(const char * word)
return w;
}
+size_t text_length(const std::string &text)
+{
+ const char *c = text.c_str();
+ size_t len = 0;
+ while (*c) {
+ if (is_color_code(c)) {
+ c++;
+ } else {
+ len++;
+ }
+ c++;
+ }
+
+ return len;
+}
+
+const std::string spaces(const std::string &text,size_t n)
+{
+ size_t l = text_length(text);
+ if (n <= l)
+ return text;
+
+ std::string s;
+ s.assign(n-l, ' ');
+ s.append(text);
+ return s;
+}
+
}
diff --git a/src/auxiliary/functions.h b/src/auxiliary/functions.h
index eff5143..cd9ed13 100644
--- a/src/auxiliary/functions.h
+++ b/src/auxiliary/functions.h
@@ -14,9 +14,10 @@
namespace aux
{
-/// if n != 1, append a plural s to word
+/// append an "s" to a word, depending on the amount
const std::string plural(const char * word, size_t n);
+/// append an "s" to a word, depending on the amount
inline const std::string plural(const std::string & word, size_t n) { return plural(word.c_str(), n); }
/// prepend the "a" or "an" article to a word
@@ -29,6 +30,12 @@ inline bool is_base_color_code(char const *c) { return ((*c == '^') && (*(c+1) >
inline bool is_core_color_code(char const *c) { return ((*c == '^') && (*(c+1) >= 'A') && (*(c+1) <= 'Z')); }
inline bool is_color_code(char const *c) { return (is_base_color_code(c) || is_core_color_code(c)); }
+
+/// length of a string, excluding color codes
+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);
}
#endif // __INCLUDED_AUX_FUNCTIONS_H__