summaryrefslogtreecommitdiff
path: root/util/mongoutils
diff options
context:
space:
mode:
authorDwight <dwight@10gen.com>2010-05-24 13:38:53 -0400
committerDwight <dwight@10gen.com>2010-05-24 13:38:53 -0400
commit1b1fbec129cd118b90c2299405929729e1cecef6 (patch)
tree59231bd4e6ec2a3bfd3f264fd897a4126a49ec7d /util/mongoutils
parentef2e50415891479b7263c57f5bd37fb3d9f0b26b (diff)
downloadmongo-1b1fbec129cd118b90c2299405929729e1cecef6.tar.gz
rs
Diffstat (limited to 'util/mongoutils')
-rw-r--r--util/mongoutils/html.h20
-rw-r--r--util/mongoutils/str.h24
2 files changed, 43 insertions, 1 deletions
diff --git a/util/mongoutils/html.h b/util/mongoutils/html.h
index 9e022e37a2a..44c8ce14235 100644
--- a/util/mongoutils/html.h
+++ b/util/mongoutils/html.h
@@ -85,12 +85,30 @@ namespace mongoutils {
return ss.str();
}
- inline string red(string contentHtml, bool color) {
+ inline string red(string contentHtml, bool color=true) {
if( !color ) return contentHtml;
stringstream ss;
ss << "<span style=\"color:#A00;\">" << contentHtml << "</span>";
return ss.str();
}
+ inline string blue(string contentHtml, bool color=true) {
+ if( !color ) return contentHtml;
+ stringstream ss;
+ ss << "<span style=\"color:#00A;\">" << contentHtml << "</span>";
+ return ss.str();
+ }
+ inline string yellow(string contentHtml, bool color=true) {
+ if( !color ) return contentHtml;
+ stringstream ss;
+ ss << "<span style=\"color:#FD0;\">" << contentHtml << "</span>";
+ return ss.str();
+ }
+ inline string green(string contentHtml, bool color=true) {
+ if( !color ) return contentHtml;
+ stringstream ss;
+ ss << "<span style=\"color:#0A0;\">" << contentHtml << "</span>";
+ return ss.str();
+ }
inline string p(string contentHtml) {
stringstream ss;
diff --git a/util/mongoutils/str.h b/util/mongoutils/str.h
index 86d8f8d6704..87187387703 100644
--- a/util/mongoutils/str.h
+++ b/util/mongoutils/str.h
@@ -34,6 +34,20 @@ namespace mongoutils {
using namespace std;
+ inline bool startsWith(const char *str, const char *prefix) {
+ size_t l = strlen(prefix);
+ if ( strlen(str) < l ) return false;
+ return strncmp(str, prefix, l) == 0;
+ }
+ inline bool startsWith(string s, string p) { return startsWith(s.c_str(), p.c_str()); }
+
+ inline bool endsWith(string s, string p) {
+ int l = p.size();
+ int x = s.size();
+ if( x < l ) return false;
+ return strncmp(s.c_str()+x-l, p.c_str(), l) == 0;
+ }
+
/** find char x, and return rest of string thereafter, or "" if not found */
inline const char * after(const char *s, char x) {
const char *p = strchr(s, x);
@@ -42,6 +56,16 @@ namespace mongoutils {
const char *p = strchr(s.c_str(), x);
return (p != 0) ? string(p+1) : ""; }
+ inline const char * after(const char *s, const char *x) {
+ const char *p = strstr(s, x);
+ return (p != 0) ? p+strlen(x) : ""; }
+ inline string after(string s, string x) {
+ const char *p = strstr(s.c_str(), x.c_str());
+ return (p != 0) ? string(p+x.size()) : ""; }
+
+ inline bool contains(string s, string x) {
+ return strstr(s.c_str(), x.c_str()) != 0; }
+
/** @return everything befor the character x, else entire string */
inline string before(const string& s, char x) {
const char *p = strchr(s.c_str(), x);