Esempio n. 1
0
String Path::Combine(RCString path1, RCString path2) {
	if (path2.IsEmpty())
		return path1;
	if (path1.IsEmpty() || IsPathRooted(path2))
		return path2;
	return AddDirSeparator(path1)+path2;
}
Esempio n. 2
0
void XmlTextWriter::WriteCData(RCString text) {
	if (strstr(text.c_str(), "]]"))
		throw logic_error("Not allowed \"]]\" in CDATA"); //!!! XmlException
	CloseElement(false);
	m_os << "<![CDATA[" << text << "]]>";
	m_bEoled = false;
}
Esempio n. 3
0
IPAddress IPAddress::Parse(RCString ipString) {
	byte buf[16];
	if (CCheck(::inet_pton(AF_INET, ipString, buf)))
		return IPAddress(ConstBuf(buf, 4));
	if (CCheck(::inet_pton(AF_INET6, ipString, buf)))
		return IPAddress(ConstBuf(buf, 16));
#if UCFG_USE_REGEX
#	if UCFG_WIN32
	if (regex_search(ipString, *s_reDomainName)) {
#	else
	if (regex_search(ipString.c_str(), s_reDomainName)) {
#	endif
		IPAddress r;
		r.AddressFamily = Ext::AddressFamily(AF_DOMAIN_NAME);
		r.m_domainname = ipString;
		return r;
	}
#endif
	Throw(HRESULT_FROM_WIN32(DNS_ERROR_INVALID_IP_ADDRESS));
}

bool IPAddress::TryParse(RCString s, IPAddress& ip) {
	byte buf[16];
	if (CCheck(::inet_pton(AF_INET, s, buf))) {
		ip = IPAddress(ConstBuf(buf, 4));
		return true;
	}
	if (CCheck(::inet_pton(AF_INET6, s, buf))) {
		ip = IPAddress(ConstBuf(buf, 16));
		return true;
	}
	return false;
}
Esempio n. 4
0
void SqliteConnection::ExecuteNonQuery(RCString sql) {
    String s = sql.TrimEnd();
    if (s.Length > 1 && s[s.Length-1] != ';')
        s += ";";

#if UCFG_USE_SQLITE==3
    for (const void *tail=(const Char16*)s; SqliteIsComplete16(tail);) {
        SqliteCommand cmd(_self);
        SqliteCheck(_self, ::sqlite3_prepare16_v2(_self, tail, -1, &cmd.m_stmt, &tail));
#else
    Blob utf = Encoding::UTF8.GetBytes(s);
    for (const char *tail=(const char*)utf.constData(); SqliteIsComplete(tail);) {
        SqliteCommand cmd(_self);
        SqliteCheck(_self, ::sqlite_prepare(_self, tail, -1, &cmd.m_stmt, &tail));
#endif
        cmd.ExecuteNonQuery();
    }
}

Int64 SqliteConnection::get_LastInsertRowId() {
    return sqlite_last_insert_rowid(m_db);
}

pair<int, int> SqliteConnection::Checkpoint(int eMode) {
#if UCFG_USE_SQLITE==3
    int log, ckpt;
    SqliteCheck(_self, ::sqlite3_wal_checkpoint_v2(_self, 0, eMode, &log, &ckpt));
    return make_pair(log, ckpt);
#else
    ExecuteNonQuery("PRAGMA lsm_checkpoint");
    return make_pair(0, 0);							//!!!?
#endif
}
Esempio n. 5
0
	String GetCurrencySymbol(RCString s) {
		String x = s.ToUpper();
		if (x.Right(4) == "COIN")
			x = s.substr(0, s.length() - 4);
		if (x == "BIT")
			return "BTC";
		if (x == "LITE")
			return "LTC";
		if (x == "GROESTL")
			return "GRS";
		if (x == "PEER" || x == "PP")
			return "PPC";
		if (x == "PRIME")
			return "XPM";
		if (x == "BTC" || x=="LTC" || x=="GRS" || x=="PPC" || x=="XPM")
			return x;
		Throw(E_NOTIMPL);
	}
Esempio n. 6
0
void XmlTextWriter::WriteStartElement(RCString name) {
	CloseElement();
	if (!m_bEoled)
		Eol();
	Indent();
	m_os << '<' << name;
	m_elements.push(name.c_str()); //!!!
	m_bOpenedElement = true;
	m_bEoled = false;
}
Esempio n. 7
0
Version::Version(RCString s) {
	cmatch m;
	if (regex_search(s.c_str(), m, *s_reVersion)) {
		Major = atoi(String(m[1]));
		Minor = atoi(String(m[2]));
		Build = m[4].matched ? atoi(String(m[4])) : -1;
		Revision = m[6].matched ? atoi(String(m[6])) : -1;
	} else
		Throw(E_INVALIDARG);
}
Esempio n. 8
0
Version::Version(RCString s) {
	cmatch m;
	if (regex_search(s.c_str(), m, *s_reVersion)) {
		Major = atoi(String(m[1]));
		Minor = atoi(String(m[2]));
		Build = m[4].matched ? atoi(String(m[4])) : -1;
		Revision = m[6].matched ? atoi(String(m[6])) : -1;
	} else
		Throw(errc::invalid_argument);
}
Esempio n. 9
0
DirectoryInfo Directory::CreateDirectory(RCString path) {
	vector<String> ar = path.Split(String(Path::DirectorySeparatorChar)+String(Path::AltDirectorySeparatorChar));
	String dir;
	bool b = true;
	for (int i=0; i<ar.size(); i++) {
		dir = AddDirSeparator(dir+ar[i]);
#if UCFG_USE_POSIX
		if (::mkdir(dir, 0777) < 00 && errno!=EEXIST && errno!=EISDIR)
			CCheck(-1);
	}
#else
		b = ::CreateDirectory(dir, 0);
	}
Esempio n. 10
0
	void SubmitBlock(const ConstBuf& data, RCString workid) override {
		String sdata = EXT_STR(data);
		if (HasSubmitBlockMethod) {
			try {
				DBG_LOCAL_IGNORE_CONDITION(ExtErr::JSON_RPC_MethodNotFound);
				VarValue par;
				if (!workid.empty())
					par.Set("workid", workid);
				ProcessSubmitResult(Call("submitblock", sdata, par));
				return;
			} catch (const system_error& ex) {
				if (ex.code() != json_rpc_errc::MethodNotFound) {
					TRC(1, ex.what());
					throw;
				}
				HasSubmitBlockMethod = false;
			}
		}
		if (!HasSubmitBlockMethod) {
			VarValue par;
			par.Set("data", sdata);
			ProcessSubmitResult(Call("getblocktemplate", par));
		}
	}
Esempio n. 11
0
String AFXAPI Path::GetDirectoryName(RCString path) {
	if (path.IsEmpty())
		return nullptr;
	CSplitPath sp = SplitPath(path);  
	return RemoveDirSeparator(sp.m_drive+sp.m_dir, true);
}
Esempio n. 12
0
XmlTextReader::XmlTextReader(RCString uri) {
	Init(xmlReaderForFile(uri.c_str(), 0, XML_PARSE_NOBLANKS));
}
Esempio n. 13
0
void IrcClient::OnPing(RCString server1, RCString server2) {
	String s = "PONG "+server1;
	if (!server2.empty())
		s += " " + server2;
	Send(s);
}
Esempio n. 14
0
CP CLispEng::CreateString(RCString s) {
	size_t size = s.length();
	CArrayValue *av = CreateVector(size, ELTYPE_CHARACTER);
	memcpy(av->m_pData, (const String::value_type*)s, size*sizeof(String::value_type));
	return FromSValue(av);
}