Example #1
0
int MIValue::ParseString(String const &s, int i)
{
	Clear();
	type = MIString;

	if(!expect("ParseString", '"', i, s))
		return s.GetCount();
	i++;
	while(s[i])
	{
		// verbatim if escaped
		if(s[i] == '\\')
			string.Cat(backslash(s, i));
		else if(s[i] == '"')
		{
			i++;
			break;
		}
		else
			string.Cat(s[i]);
		i++;
	}
	if(!expect("ParseString", '"', i-1, s))
		return s.GetCount();

	return i;
}
Example #2
0
int MIValue::ParseAngle(String const &s, int i)
{
	Clear();
	type = MIString;
	int aCount = 0;

	if(!expect("ParseAngle", '<', i, s))
		return s.GetCount();
	string = "<";
	aCount++;
	i++;
	while(s[i])
	{
		// verbatim if escaped
		if(s[i] == '\\')
			string.Cat(backslash(s, i));
		else if(s[i] == '>' && !--aCount)
		{
			i++;
			break;
		}
		else
		{
			string.Cat(s[i]);
			if(s[i] == '<')
				aCount++;
		}
		i++;
	}
	if(!expect("ParseAngle", '>', i-1, s))
		return s.GetCount();
	string.Cat('>');

	return i;
}
Example #3
0
int MIValue::ParseTuple(String const &s, int i)
{
	Clear();
	type = MITuple;
	
	// drop opening delimiter
	if(!expect("ParseTuple", '{', i, s))
		return s.GetCount();
	i++;
	while(s[i] && s[i] != '}')
	{
		while(s[i] && isspace(s[i]))
			i++;
		String name;
		MIValue val;
		i = ParsePair(name, val, s, i);
		tuple.AddPick(name, pick(val));
		while(s[i] && isspace(s[i]))
			i++;
		if(s[i] == '}')
			break;
		if(!expect("ParseTuple", ',', i, s))
			return s.GetCount();
		i++;
	}

	return i + 1;
}
Example #4
0
String MIValue::Dump(int level) const
{
	String spacer(' ', level);
	switch(type)
	{
		case MIString:
			return spacer + MARK_STRING + Dump(string);

		case MITuple:
		{
			String s = spacer + MARK_TUPLE + "{\n";
			level += 4;
			spacer = String(' ', level);
			for(int i = 0; i < tuple.GetCount(); i++)
			{
				String s1 = spacer + tuple.GetKey(i) + "=";
				s += s1;
				MIValue const &val = tuple[i];
				if(val.type == MIString)
					s += val.Dump();
				else
				{
					s += '\n' + val.Dump(level + 4);
					s = s.Left(s.GetCount()-1);
				}
				if(i < tuple.GetCount() - 1)
					s += ',';
				s += '\n';
			}
			level -= 4;
			spacer = String(' ', level);
			s += spacer + "}\n";
			return s;
		}

		case MIArray:
		{
			String s = spacer + MARK_ARRAY + "[ \n";
			level += 4;
			for(int i = 0; i < array.GetCount(); i++)
			{
				MIValue const &val = array[i];
				s += val.Dump(level);
				if(val.type != MIString)
					s = s.Left(s.GetCount()-1);
				if(i < array.GetCount() - 1)
					s += ',';
				s += '\n';
			}
			s += spacer + "]\n";
			return s;
		}
		
		default:
			return spacer + "*UNKNOWN MIVALUE TYPE*";
	}
}
Example #5
0
int MatchWord(const Vector<int>& w, const String& pattern)
{
	const Index<String>& ws = TopicWords();
	for(int i = 0; i < w.GetCount(); i++) {
		String wrd = ws[w[i]];
		if(wrd.GetCount() >= pattern.GetCount() && memcmp(wrd, pattern, pattern.GetCount()) == 0)
			return i;
	}
	return -1;
}
Example #6
0
//задание цвета строки
void AnimeList::RowColor(int row)
{
	Date release;
	Array<CellSeries> array;
	Date today = GetSysDate();
	String xml = listName.Get(row, SeriesRelease);
	String number, date;
	int ep = listName.Get(row, Episodes);
	int ser;
	if(xml.GetCount() > 0)
	{
		int pos;
		while(xml.GetCount() > 0){ 
			pos = xml.Find("-");
			if(pos > 0)
			{
				number = String(xml, pos);
				xml.Remove(0, pos + 1);
				date = String(xml, 10);
				xml.Remove(0, 11);
				series.number = StrInt(number);
				StrToDate(series.release, date);
				array.Add(series);
			}
		}
		release = array[array.GetCount()-1].release;
		if((ep == array[array.GetCount()-1].number) & (today < release))
			ser = array[array.GetCount()-1].number - 1;
		else
			ser = ((today - release) / 7) + array[array.GetCount()-1].number;
	} else
	{
		release = listName.Get(row, Release);
		ser = ((today - release) / 7) + 1;
	}
	int views = listName.Get(row, Views);
	if(views == ep) //полностью просмотрено
		for(int i=0;i<listName.GetColumnCount();i++)
			listName.SetDisplay(row, i, Single<ColumnBlue>());
	else
		if((views < ep) & (views != 0) & (views == ser)) //нет новых серий, в просмотре
			for(int i=0;i<listName.GetColumnCount();i++)
				listName.SetDisplay(row, i, Single<ColumnGreen>());
		else
			if((views < ep) & (views != 0) & (views < ser)) //есть новые серии, в просмотре
				for(int i=0;i<listName.GetColumnCount();i++)
					listName.SetDisplay(row, i, Single<ColumnRed>());
			else
				if(views == 0) //нет просмотренных серий
					for(int i=0;i<listName.GetColumnCount();i++)
						listName.SetDisplay(row, i, Single<ColumnDefault>());
}
Example #7
0
template<> void Jsonize(JsonIO& io, Time& var)
{
	if(io.IsLoading()) {
		const Value& v = io.Get();
		if(IsNull(v)) {
			var = Null;
			return;
		}
		if(IsString(v)) {
			String text = v;
			if(text.GetCount() > 15) {
				Time tm;
				tm.year = ScanInt(text.Left(4));
				tm.month = ScanInt(text.Mid(4, 2));
				tm.day = ScanInt(text.Mid(6, 2));
				tm.hour = ScanInt(text.Mid(9, 2));
				tm.minute = ScanInt(text.Mid(12, 2));
				tm.second = ScanInt(text.Mid(15));
				if(tm.IsValid()) {
					var = tm;
					return;
				}
			}
		}
		throw JsonizeError("string expected for Time value");
	}
	else
		if(IsNull(var))
			io.Set(Null);
		else
			io.Set(Format("%04d%02d%02d`T%02d:%02d:%02d",
				          var.year, var.month, var.day, var.hour, var.minute, var.second));
}
Example #8
0
bool DriveOpenClose(String drive, bool open)
{
	int operation;
	if (open)
		operation = IOCTL_STORAGE_EJECT_MEDIA;
	else
		operation = IOCTL_STORAGE_LOAD_MEDIA;
	if (drive.IsEmpty())
		return false;
	else if (drive.GetCount() == 1)
		drive += ":";
	else {
		drive = drive.Left(2);
		if (drive[1] != ':')
			return false;
	}
	HANDLE hDrive;
	hDrive = CreateFile("\\\\.\\" + drive, GENERIC_READ || GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
	if (hDrive == INVALID_HANDLE_VALUE)
		return false;
	bool ret = false;
	DWORD dummyBytesReturned;
	if (DeviceIoControl(hDrive, operation, 0, 0, 0, 0, &dummyBytesReturned, 0))
		ret = true;
  	CloseHandle(hDrive);
  	return ret;
}
Example #9
0
template<> void Jsonize(JsonIO& io, Date& var)
{
	if(io.IsLoading()) {
		const Value& v = io.Get();
		if(IsNull(v)) {
			var = Null;
			return;
		}
		if(IsString(v)) {
			String text = v;
			if(text.GetCount() > 6) {
				Date d;
				d.year = ScanInt(text.Left(4));
				d.month = ScanInt(text.Mid(4, 2));
				d.day = ScanInt(text.Mid(6));
				if(d.IsValid()) {
					var = d;
					return;
				}
			}
		}
		throw JsonizeError("string expected for Date value");
	}
	else
		if(IsNull(var))
			io.Set(Null);
		else
			io.Set(Format("%04d%02d%02d", var.year, var.month, var.day));
}
Example #10
0
String VisGenDlg::GetName()
{
	String n = layout.name;
	int l = n.GetCount() - 6;
	if(l > 0 && n.Mid(l) == "Layout")
		n = n.Mid(0, l);
	return n + "Dlg";
}
Example #11
0
bool DiffSyntax::IsPattern(const wchar *current, const wchar *end, String pattern) const
{
	bool containing = true;
	
	int i = 0;
	while((current < end) && (i < pattern.GetCount())) {
		if(ToLower(*current) !=  ToLower(pattern[i])) {
			containing = false;
			break;
		}
		
		current++;
		i++;
	}
	
	return (containing && (i == pattern.GetCount()));
}
Example #12
0
// Fix "space" charactes after 1000 in slovak locale. They weren't printable by default
String  fixFuckedLinuxFormating(const String &s) {
	StringBuffer out;
	
	#ifdef PLATFORM_LINUX
	for (int i=0; i<s.GetCount(); i++)
		out.Cat((s[i] == -96) ? ' ' : s[i]);
	#endif
	
	#ifdef PLATFORM_WIN32
	for (int i=0; i<s.GetCount(); i++)
	{
		if (s[i] != -62)
			out.Cat((s[i] == -96) ? ' ' : s[i]);
	}
	#endif
	
	return ~out;
}
Example #13
0
// from complete lib name/path (libXXX.so.ver.minVer) gets the link name (libXXX.so)
String CppBuilder::GetSoLinkName(String libName) const
{
	
	String linkName = GetFileName(libName);
	int soPos = ToLower(linkName).ReverseFind(".so");
	if(soPos < 0)
		soPos = linkName.GetCount();
	else
		soPos += 3;
	return linkName.Left(soPos);
}
Example #14
0
void SelectPackageDlg::OnOK()
{
	Package pkg;
	int f = ~filter;
	String n = GetCurrentName();
	if(n.GetCount() && pkg.Load(PackagePath(n)) &&
	   (!(f & MAIN) || pkg.config.GetCount())) {
		loading = false;
		finished = true;
		AcceptBreak(IDOK);
	}
}
Example #15
0
int MIValue::ParseArray(String const &s, int i)
{
	Clear();
	type = MIArray;
	
	// drop opening delimiter
	if(!expect("ParseArray", '[', i, s))
		return s.GetCount();
	i++;
	while(s[i] && isspace(s[i]))
		i++;
	while(s[i] && s[i] != ']')
	{
		while(s[i] && isspace(s[i]))
			i++;
		String name;
		MIValue val;
		if(s[i] == '[')
			i = val.ParseArray(s, i);
		else if(s[i] == '{')
			i = val.ParseTuple(s, i);
		else if(s[i] == '"')
			i = val.ParseString(s, i);
		else if(s[i] == '<')
			i = val.ParseAngle(s, i);
		else
			i = ParsePair(name, val, s, i);
		array.Add() = pick(val);
		while(s[i] && isspace(s[i]))
			i++;
		if(s[i] == ']')
			break;
		if(!expect("ParseArray", ',', i, s))
			return s.GetCount();
		i++;
	}
	return i + 1;
}
Example #16
0
//выбор в главном массиве
void AnimeList::Change()
{
	if(listName.IsCursor()) {
		infoTab.complete.SetLabel(AsString(listName.Get(Complete)));
		infoTab.name.SetLabel(AsString(listName.Get(Named)));
		infoTab.nameRus.SetLabel(AsString(listName.Get(NamedRus)));
		infoTab.episodes.SetLabel(AsString(listName.Get(Episodes)));
		infoTab.views.SetLabel(AsString(listName.Get(Views)));
		infoTab.dateRelease.SetLabel(AsString(listName.Get(Release)));
		test.testStr.SetText(AsString((listName.Get(SeriesRelease))));
		
		if(parameters.checkSave)
		{
			String text;
			int v = listName.Get(Views);
			v++;
			text = Format(AsString(listName.Get(Named))+ " %d", v);
			copy.SetText(text);
			copy.SelectAll();
			copy.Copy();
		};
		
		seriesArray.Clear();
		test.testList.Clear();
		//заполнение массива релизов серий из поля SeriesRelease главного массива (парсер строки)
		String xml = listName.Get(SeriesRelease);
		String number, date;
		int pos;
		while(xml.GetCount() > 0){ 
			pos = xml.Find("-");
			if(pos > 0)
			{
			number = String(xml, pos);
			xml.Remove(0, pos + 1);
			date = String(xml, 10);
			xml.Remove(0, 11);
			series.number = StrInt(number);
			StrToDate(series.release, date);
			seriesArray.Add(series);
			}
		}
			
		if(listName.Get(Complete) != "Yes")
			AnimeSeries();
		else
			seriesDate.Clear();
	}
}
Example #17
0
void SelectPackageDlg::ScanFolder(const String& path, ArrayMap<String, PkData>& nd,
                                  const String& nest, Index<String>& dir_exists,
                                  const String& prefix)
{
	for(FindFile ff(AppendFileName(path, "*.*")); ff; ff.Next())
		if(ff.IsFolder() && !ff.IsHidden()) {
			dir_exists.Add(ff.GetPath());
			String p = ff.GetPath();
			bool nw = nd.Find(p) < 0; // Do we have any info loaded about this package?
			PkData& d = nd.GetAdd(ff.GetPath());
			d.package = prefix + ff.GetName();
			d.nest = nest;
			if(nw) { // No cached info available about the folder
				d.ispackage = IsLetter(*d.package) && d.package.Find('.') < 0; // First heuristic guess
				d.main = d.ispackage && prefix.GetCount() == 0; // Expect it is main
			}
		}
}
Example #18
0
// from complete lib name/path (libXXX.so.ver.minVer) gets the soname (libXXX.so.ver)
String CppBuilder::GetSoname(String libName) const
{
	
	String soname = GetFileName(libName);
	int soLen = soname.GetCount();
	int soPos = ToLower(soname).ReverseFind(".so");
	if(soPos < 0)
		soPos = soLen;
	else
		soPos += 3;
	if(soname.Mid(soPos, 1) == ".")
	{
		soPos++;
		while(soPos < soLen && IsDigit(soname[soPos]))
			soPos++;
	}
	return soname.Left(soPos);
}
Example #19
0
force_inline
void AString<B>::Replace(const tchar *find, const String& replace)
{
	Replace(find, (int)strlen__(find), ~replace, replace.GetCount());
}
Example #20
0
force_inline
void AString<B>::Replace(const String& find, const tchar *replace)
{
	Replace(~find, find.GetCount(), replace, (int)strlen__(replace));
}
Example #21
0
void AString<B>::Replace(const String& find, const String& replace)
{
	Replace(~find, find.GetCount(), ~replace, replace.GetCount());
}
Example #22
0
bool HttpsClient::ProxyConnect()
{
	if(use_proxy) {
		int start_time = msecs();
		int end_time = msecs() + timeout_msecs;
		while(!socket.PeekWrite(1000)) {
			int time = msecs();
			if(time >= end_time) {
				error = NFormat(t_("%s:%d: connecting to host timed out"), socket_host, socket_port);
				Close();
				return false;
			}
		}
		String host_port = host;
		if(port)
			host_port << ':' << port;
		else
			host_port << ":443";
		String request;
		request << "CONNECT " << host_port << " HTTP/1.1\r\n"
		        << "Host: " << host_port << "\r\n";
		if(!IsNull(proxy_username))
			request << "Proxy-Authorization: Basic "
			        << Base64Encode(proxy_username + ':' + proxy_password) << "\r\n";
		request << "\r\n";
		LLOG(request);
		int written = 0;
		while(msecs() - end_time < 0) {
			int nwrite = socket.WriteWait(request.GetIter(written), min(request.GetLength() - written, 1000), 1000);
			if(socket.IsError()) {
				error = Socket::GetErrorText();
				Close();
				return false;
			}
			if((written += nwrite) >= request.GetLength())
				break;
		}
		if(written < request.GetLength()) {
			error = NFormat(t_("%s:%d: timed out sending request to server"), host, port);
			Close();
			return false;
		}
		String line = ReadUntilProgress('\n', start_time, end_time, false);
		LLOG("P< " << line);
		if(socket.IsError()) {
			error = Socket::GetErrorText();
			Close();
			return false;
		}
		if(!line.StartsWith("HTTP") || line.Find(" 2") < 0) {
			error = "Invalid proxy reply: " + line;
			Close();
			return false;
		}
		while(line.GetCount()) {
			line = ReadUntilProgress('\n', start_time, end_time, false);
			if(*line.Last() == '\r')
				line.Trim(line.GetCount() - 1);
			LLOG("P< " << line << " len " << line.GetCount());
			if(socket.IsError()) {
				error = Socket::GetErrorText();
				Close();
				return false;
			}
		}
		use_proxy = false;
		while(!socket.PeekWrite(1000)) {
			int time = msecs();
			if(time >= end_time) {
				error = NFormat(t_("%s:%d: connecting to host timed out"), socket_host, socket_port);
				Close();
				return false;
			}
		}
	}
	return true;
}