#define UTIL_STRING_H
#include "ustring.h"
-#include "utf16.h"
+#include "util_regex.h"
+#include <time.h>
+#include "iconv_glue.h"
+#include <iconv.h>
#include <vector>
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/lexical_cast.hpp>
-class Splitter {
+class UIConv {
public:
- uregex* re;
- uiterator b;
- uiterator t;
- uiterator u;
- uiterator e;
- umatch m;
+ iconv_t cd;
- Splitter (const ustring& text, uregex& r) {
- b = t = u = text.begin ();
- e = text.end ();
- re = &r;
- };
- Splitter (uiterator pb, uiterator pe, uregex& r) {
- b = t = u = pb;
- e = pe;
- re = &r;
- };
- virtual ~Splitter () {};
- virtual void init (uiterator pb, uiterator pe) {
- b = t = u = pb;
- e = pe;
- };
- virtual bool isEnd () {
- return b == e;
- };
- virtual bool next () {
- b = u;
- if (b != e) {
- if (usearch (b, e, m, *re)) {
- t = m[0].first;
- u = m[0].second;
- } else {
- t = e;
- u = e;
- }
- return true;
- } else {
- return false;
- }
- };
- virtual bool nextSep () {
- b = u;
- if (b != e) {
- if (usearch (b, e, m, *re)) {
- t = m[0].first;
- u = m[0].second;
- return true;
- } else {
- t = e;
- u = e;
- return false;
- }
- } else {
- return false;
- }
- };
- virtual uiterator begin () {
- return b;
- };
- virtual uiterator end () {
- return t;
- };
- virtual ustring cur () {
- return ustring (b, t);
- };
- virtual bool match (int index) {
- return (t != u && m[index].matched);
- }
- virtual uiterator matchBegin () {
- return t;
- };
- virtual uiterator matchBegin (int index) {
- return m[index].first;
- };
- virtual uiterator matchEnd () {
- return u;
- };
- virtual uiterator matchEnd (int index) {
- return m[index].second;
- };
- virtual uiterator eol () {
- return e;
- };
- virtual void rewind (int i) {
- int n = u - t;
- if (n > i) {
- u -= i;
- } else {
- u -= n;
+ UIConv (const char* in, const char* out);
+ virtual ~UIConv () {
+ if (cd != ICONV_ERR) {
+ iconv_close (cd);
+ cd = ICONV_ERR;
}
};
-};
-
-class WSplitter {
- public:
- boost::wregex* re;
- std::wstring::const_iterator b, t, u, e;
- boost::wsmatch m;
-
- WSplitter (const std::wstring& text, boost::wregex& r) {
- b = t = u = text.begin ();
- e = text.end ();
- re = &r;
- };
- virtual ~WSplitter () {};
- virtual bool next () {
- b = u;
- if (b != e) {
- if (regex_search (b, e, m, *re, boost::regex_constants::match_single_line)) {
- t = m[0].first;
- u = m[0].second;
- } else {
- t = e;
- u = e;
- }
- return true;
- } else {
- return false;
- }
- };
- virtual ustring cur () {
- std::wstring x (b, t);
- return wtou (x);
- };
+ virtual ustring cv (const ustring& text, bool flush = false);
};
ustring c3 (const ustring& str);
+ustring to_ustring (int32_t v);
+ustring to_ustring (uint32_t v);
+ustring to_ustring (long int v);
+ustring to_ustring (unsigned long int v);
+ustring to_ustring (long long int v);
+ustring to_ustring (unsigned long long int v);
+ustring to_ustring (double val);
+int32_t to_int32 (const ustring& v);
+uint32_t to_uint32 (const ustring& v);
+uint64_t to_uint64 (const ustring& v);
+ustring percentHEX (int c);
ustring urldecode_nonul (const ustring& str);
ustring omitCtrl (const ustring& str);
+ustring omitCtrlX (const ustring& str);
+ustring omitNul (const ustring& str);
ustring omitNL (const ustring& str);
ustring omitNonAscii (const ustring& str);
ustring omitNonAsciiWord (const ustring& str);
-bool to_bool (const ustring& v);
-ustring urlEncode (const ustring& url);
-ustring cookieEncode (const ustring& text);
-ustring cookieDecode (const ustring& text);
+ustring percentEncode (uiterator b, uiterator e);
+inline ustring percentEncode (const ustring& str) {
+ return percentEncode (str.begin (), str.end ());
+}
+ustring percentEncode_path (uiterator b, uiterator e);
+inline ustring percentEncode_path (const ustring& str) {
+ return percentEncode_path (str.begin (), str.end ());
+}
+ustring percentDecode (const ustring& str);
+ustring cookieencode (const ustring& text);
+ustring cookiedecode (const ustring& text);
ustring clipColon (const ustring& text);
-ustring dirPart (char* path);
-ustring filePartOSSafe (const ustring& path);
+ustring dirPart (const ustring& path);
+ustring filePart_osSafe (const ustring& path);
void split (uiterator b, uiterator e, uregex& re, std::vector<ustring>& ans);
-//bool splitChar (uiterator& b, uiterator& e, uiterator::value_type ch, uiterator& m1, uiterator& m2);
-ustring base64encode (uiterator b, uiterator e);
+void split (uiterator b, uiterator e, int ch, std::vector<ustring>& ans);
+void splitE (uiterator b, uiterator e, uregex& re, std::vector<ustring>& ans);
+void splitE (uiterator b, uiterator e, int ch, std::vector<ustring>& ans);
+bool splitChar (uiterator b, uiterator e, uiterator::value_type ch, uiterator& m1);
ustring filenameEncode (const ustring& text);
+ustring filenameDecode (const ustring& text);
ustring escape_re (const ustring& text);
ustring slashEncode (const ustring& text);
ustring slashDecode (const ustring& text);
unsigned long strtoul (const ustring& str);
unsigned long strtoul (const uiterator& b);
+double strtod (const ustring& str);
long strtol (const ustring& str);
bool passMatch (const ustring& pass, const ustring& cpass);
-ustring passCrypt (const ustring& pass);
-size_t strlength (const ustring& src);
+typedef enum {
+ FORMAT_MD5,
+ FORMAT_BF,
+ FORMAT_SHA256,
+ FORMAT_SHA512,
+} passCryptFormat;
+ustring passCrypt (const ustring& pass, passCryptFormat format);
+size_t strLength (const ustring& src);
void substring (const ustring& src, size_t idx, size_t len, int flen, ustring& ans);
-ustring utf16Encode (const ustring& str);
+ustring jsEncode (const ustring& str);
bool matchSkip (uiterator& b, uiterator e, const char* t, size_t s);
bool matchHead (uiterator& b, uiterator e, const char* t, size_t s);
+bool matchHead (const ustring& str, const char* t, size_t s);
+bool matchHead (const ustring& str, const ustring& head);
bool match (uiterator b, uiterator e, const char* t, size_t s);
bool match (const ustring& str, const char* t, size_t s);
bool match (uiterator b, uiterator e, const ustring& str);
+bool match (const ustring& str, const char* t, size_t s, const char* t2, size_t s2);
ustring clipWhite (uiterator b, uiterator e);
+ustring clipWhite (const ustring& str);
ustring getenvString (const char* key);
ustring zeroPad (int n, const ustring& src);
-bool wsearch (const ustring& text, boost::wsmatch& m, const ustring& reg, boost::wregex::flag_type reg_flags = boost::regex_constants::normal, boost::match_flag_type search_flags = boost::regex_constants::match_single_line);
-ustring uiconv (const ustring& src, const char* tocode, const char* fromcode);
ustring padEmpty (const ustring& name);
+uint32_t hextoul (uiterator b, uiterator e);
+double hextod (uiterator b, uiterator e, int base = 16);
+ustring dtohex (double e, int pad = 0, int base = 16, bool upcase = false);
+ustring toCRLF (const ustring& str);
+void skipChar (uiterator& b, uiterator e, int ch);
+inline void skipSpace (uiterator& b, uiterator e) {skipChar (b, e, ' ');}
+void skipNextToChar (uiterator& b, uiterator e, int ch);
+ustring toLower (uiterator b, uiterator e);
+
+ustring formatDateString (const ustring& format, struct tm& v);
+ustring toLower (const ustring& str);
+ustring toUpper (const ustring& str);
+ustring hexEncode (const ustring& data, bool upcase = false);
+ustring hexDecode (const ustring& data);
+int octchar (uiterator b);
+ustring octchar (int c);
+
+bool findNL (uiterator& b, uiterator e, uiterator& u);
+bool findNLb (uiterator& b, uiterator e);
+bool findChar (uiterator& b, uiterator e, int ch);
+bool findChars (uiterator& b, uiterator e, const ustring& pattern);
+bool findCharFn (uiterator& b, uiterator e, bool (*fn)(int));
+bool findSepColon (uiterator& b, uiterator e, uiterator& u);
+bool matchHeadFn (uiterator& b, uiterator e, bool (*fn)(int));
+bool matchWordTbl (uiterator b, uiterator e, char* tbl);
+bool matchWordFn (uiterator b, uiterator e, bool (*fn)(int));
#endif /* UTIL_STRING_H */