bool endsWith(const LITESQL_String& what, const LITESQL_String& with) { if (what.size() < with.size()) return false; if (what.substr(what.size()-with.size(), what.size()) == with) return true; return false; }
bool startsWith(const LITESQL_String& what, const LITESQL_String& with) { if (what.size() < with.size()) return false; if (what.substr(0, with.size()) == with) return true; return false; }
LITESQL_String lstrip(const LITESQL_String& s) { unsigned int pos = 0; while (1) { if (isspace(s[pos]) && pos < s.size()-1) pos++; else break; } return s.substr(pos, s.size()); }
int hexToInt(const LITESQL_String& s) { int res = 0; for (size_t i = 0; i < s.size(); i++) { int multiplier = 1; int exp = (s.size() - 1 - i); while (exp-- > 0) multiplier *= 16; int ch = s[i]; if (ch >= '0' && ch <= '9') res += multiplier * (ch - '0'); else if (ch >= 'a' && ch <= 'z') res += multiplier * (ch - 'a'); else if (ch >= 'A' && ch <= 'Z') res += multiplier * (ch - 'A'); } return res; }
LITESQL_String rstrip(const LITESQL_String& s) { if (s.empty()) return s; int pos = s.size()-1; while (1) { if (isspace(s[pos]) && pos > 0) pos--; else break; } return s.substr(0, pos+1); }
ODBCBackend::ODBCBackend(const LITESQL_String& connInfo) : /*db(NULL),*/ transaction(false) { Split params(connInfo, LITESQL_L(";")); LITESQL_String database; for (size_t i = 0; i < params.size(); i++) { Split param(params[i], LITESQL_L("=")); if (param.size() == 1) continue; if (param[0] == LITESQL_L("database")) database = param[1]; } if (database.size() == 0) throw DatabaseError(LITESQL_L("no database-param specified")); /* if (ODBCBackend_open(database.c_str(), &db)) { throw DatabaseError(ODBCBackend_errmsg(db)); } */ }
LITESQL_String decapitalize(const LITESQL_String& s) { if (s.empty()) return s; LITESQL_Char buf[2] = {tolower(s[0]), 0}; return LITESQL_String(buf) + s.substr(1, s.size()); }
LITESQL_String toUpper(LITESQL_String s) { for (unsigned int i = 0; i < s.size(); i++) s[i] = toupper(s[i]); return s; }