#include "motorconst.h"
#include "ustring.h"
-bool checkRe (const ustring& name, uregex& re) {
+bool checkRe (const ustring& name, const uregex& re) {
umatch m;
if (usearch (name, m, re)) {
}
}
-bool checkRe (uiterator& b, uiterator& e, uregex& re) {
+bool checkRe (const uiterator& b, const uiterator& e, const uregex& re) {
umatch m;
if (usearch (b, e, m, re)) {
}
bool checkAbsoluteResourceName (const ustring& name) {
-// static uregex re ("^/(" kWNAME "{0,127}/)*" kWNAME "{0,127}(\\." kWORD "{1,16})?$");
static uregex re ("^/(" kFName "/)*" kFName "$");
return (checkRe (name, re));
}
bool checkASCII (const ustring& name) {
-// static uregex re ("^[ -\\x7e]*$");
-// return (checkRe (name, re));
static uregex re ("[^ -\\x7e]");
return (! checkRe (name, re));
return (checkRe (name, re));
}
+bool checkAlNum (const uiterator& b, const uiterator& e) {
+ static uregex re ("^[a-zA-Z_0-9]+$");
+
+ return (checkRe (b, e, re));
+}
+
bool checkNum (const ustring& text) {
- return (checkRe (text, re_num));
+ return (checkNum (text.begin (), text.end ()));
}
-bool checkNum (uiterator& b, uiterator& e) {
+bool checkNum (const uiterator& b, const uiterator& e) {
return (checkRe (b, e, re_num));
}
-static uregex re_width ("^[0-9]+(\\.[0-9]+)?(%|px|pt|in|mm|cm|em|ex)?$");
-bool checkWidth (uiterator& b, uiterator& e) {
+bool checkWidth (const uiterator& b, const uiterator& e) {
+ static uregex re_width ("^[0-9]+(\\.[0-9]+)?(%|px|pt|in|mm|cm|em|ex)?$");
return (checkRe (b, e, re_width));
}
bool checkWidth (const ustring& text) {
- return (checkRe (text, re_width));
+// return (checkRe (text, re_width));
+ return (checkWidth (text.begin (), text.end ()));
}
-static uregex re_color ("^#([0-9a-fA-F]{3}){1,2}$");
-bool checkColor (uiterator& b, uiterator& e) {
+bool checkColor (const uiterator& b, const uiterator& e) {
+ static uregex re_color ("^#([0-9a-fA-F]{3}){1,2}$");
return (checkRe (b, e, re_color));
}
bool checkColor (const ustring& text) {
- return (checkRe (text, re_color));
+// return (checkRe (text, re_color));
+ return (checkColor (text.begin (), text.end ()));
}
-static uregex re_wikiid ("^" rWikiID "$");
-bool checkWikiID (uiterator& b, uiterator& e) {
+bool checkWikiID (const uiterator& b, const uiterator& e) {
+ static uregex re_wikiid ("^" rWikiID "$");
return (checkRe (b, e, re_wikiid));
}
bool checkWikiID (const ustring& text) {
- return (checkRe (text, re_wikiid));
+// return (checkRe (text, re_wikiid));
+ return (checkWikiID (text.begin (), text.end ()));
}
bool checkAry (const ustring& name) {
#define UA_Opera 0x00000800
#define UA_NetFront 0x00001000
-bool checkRe (const ustring& name, uregex& re);
-bool checkRe (uiterator& b, uiterator& e, uregex& re);
+bool checkRe (const ustring& name, const uregex& re);
+bool checkRe (const uiterator& b, const uiterator& e, const uregex& re);
bool checkName (const ustring& name);
bool checkFilename (const ustring& name);
bool checkResourceName (const ustring& name);
bool checkHostname (const ustring& name);
bool checkMimeType (const ustring& name);
bool checkMailAddr (const ustring& name);
+bool checkAlNum (const uiterator& b, const uiterator& e);
bool checkNum (const ustring& text);
-bool checkNum (uiterator& b, uiterator& e);
-bool checkWidth (uiterator& b, uiterator& e);
+bool checkNum (const uiterator& b, const uiterator& e);
+bool checkWidth (const uiterator& b, const uiterator& e);
bool checkWidth (const ustring& text);
bool checkColor (uiterator& b, uiterator& e);
bool checkColor (const ustring& text);
-bool checkWikiID (uiterator& b, uiterator& e);
+bool checkWikiID (const uiterator& b, const uiterator& e);
bool checkWikiID (const ustring& text);
bool checkAry (const ustring& name);
bool checkAry (const ustring& name, ustring& sym);
#include "utf16.h"
#include <boost/regex.hpp>
#include <boost/regex/pattern_except.hpp>
+#include <boost/algorithm/string.hpp>
#include <vector>
#include <algorithm>
#include <stdlib.h>
return ans;
}
+ustring toLower (const ustring& str) {
+ return boost::to_lower_copy (str);
+}
+
+ustring toUpper (const ustring& str) {
+ return boost::to_upper_copy (str);
+}
class MNodePtr;
ustring formatString (const ustring& format, boost::ptr_vector<MNodePtr>& par);
ustring formatDateString (const ustring& format, time_t tm);
+ustring toLower (const ustring& str);
+ustring toUpper (const ustring& str);
#endif /* UTIL_STRING_H */
#include "mlenv.h"
#include "motorenv.h"
#include "formfile.h"
+#include "utf8.h"
#include "util_apache.h"
#include "util_check.h"
#include "util_const.h"
char* e = getenv (name);
if (e) {
- return newMNode_str (new ustring (e));
+ ustring s (e);
+ return newMNode_str (new ustring (fixUTF8 (s)));
} else {
return NULL;
}
}
/*DOC:
+===get-http-header===
+ (get-http-header NAME) -> STRING
+
+*/
+//#AFUNC get-http-header ml_get_http_header
+MNode* ml_get_http_header (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ ustring name;
+ ustring::iterator b, e;
+
+ if (! arg)
+ throw (uErrorWrongNumber);
+ name = toUpper (eval_text1 (arg->car (), mlenv));
+ nextNode (arg);
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ b = name.begin ();
+ e = name.end ();
+ for (; b != e; b ++) {
+ if (*b == '-') {
+ *b = '_';
+ }
+ }
+
+ if (checkAlNum (name.begin (), e) && name.length () < 128) {
+ name = ustring (CharConst ("HTTP_")).append (name);
+ char* e = getenv (name.c_str ());
+ if (e) {
+ ustring s (e);
+ return newMNode_str (new ustring (fixUTF8 (s)));
+ } else {
+ return NULL;
+ }
+ } else {
+ return NULL;
+ }
+}
+
+/*DOC:
===is-get-method===
(is-get-method) -> BOOL
MNode* ml_ssl_client_m_serial (MNode* cell, MlEnv* mlenv);
MNode* ml_ssl_client_s_dn (MNode* cell, MlEnv* mlenv);
MNode* ml_ssl_client_i_dn (MNode* cell, MlEnv* mlenv);
+MNode* ml_get_http_header (MNode* cell, MlEnv* mlenv);
MNode* ml_is_get_method (MNode* cell, MlEnv* mlenv);
MNode* ml_is_post_method (MNode* cell, MlEnv* mlenv);
MNode* ml_absolute_url (MNode* cell, MlEnv* mlenv);
}
return ans.release ();
}
+
+/*DOC:
+===to-upper===
+ (to-upper STRING) -> STRING
+
+*/
+//#AFUNC to-upper ml_to_upper
+//#WIKIFUNC to-upper
+MNode* ml_to_upper (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ ustring text;
+
+ if (! arg)
+ throw (uErrorWrongNumber);
+ text = eval_str (arg->car (), mlenv);
+ nextNode (arg);
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ return newMNode_str (new ustring (toUpper (text)));
+}
+
+/*DOC:
+===to-lower===
+ (to-lower STRING) -> STRING
+
+*/
+//#AFUNC to-lower ml_to_lower
+//#WIKIFUNC to-lower
+MNode* ml_to_lower (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ ustring text;
+
+ if (! arg)
+ throw (uErrorWrongNumber);
+ text = eval_str (arg->car (), mlenv);
+ nextNode (arg);
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ return newMNode_str (new ustring (toLower (text)));
+}
MNode* ml_to_sexp (MNode* cell, MlEnv* mlenv);
MNode* ml_is_ascii63 (MNode* cell, MlEnv* mlenv);
MNode* ml_sort_string (MNode* cell, MlEnv* mlenv);
+MNode* ml_to_upper (MNode* cell, MlEnv* mlenv);
+MNode* ml_to_lower (MNode* cell, MlEnv* mlenv);
#endif /* ML_STRING_H */