Beispiel #1
0
static String VFKParsePolvz(const char *text)
{
	for(; *text; text++)
		if(text[0] == 'P' && text[1] == 'O' && text[2] == 'L' && text[3] == 'V' && text[4] == 'Z' && text[5] == ':') {
			text += 6;
			while(*text && (byte)*text <= ' ')
				text++;
			const char *b = text;
			bool slash = false;
			while(*text && (byte)*text > ' ')
				if(*text++ == '/')
					slash = true;
			String out;
			int len = text - b;
			if(slash || len <= 4)
				out = String(b, text);
			else {
				out.Cat(b, len - 4);
				out.Cat('/');
				out.Cat(text - 4, 4);
			}
			return out;
		}
	return Null;
}
Beispiel #2
0
void TextSettings::Load(const char *filename)
{
	FileIn in(filename);
	int themei = 0;
	settings.Add("");
	while(!in.IsEof()) {
		String ln = in.GetLine();
		const char *s = ln;
		if(*s == '[') {
			s++;
			String theme;
			while(*s && *s != ']')
				theme.Cat(*s++);
			themei = settings.FindAdd(theme);
		}
		else {
			if(themei >= 0) {
				String key;
				while(*s && *s != '=') {
					key.Cat(*s++);
				}
				if(*s == '=') s++;
				String value;
				while(*s) {
					value.Cat(*s++);
				}
				if(!IsEmpty(key))
					settings[themei].GetAdd(TrimBoth(key)) = TrimBoth(value);
			}
		}
	}
}
Beispiel #3
0
bool   ODBCPerformScript(const String& text, StatementExecutor& executor, Gate2<int, int> progress_canceled)
{
	const char *p = text;
	while(*p) {
		String cmd;
		while(*p && *p != ';')
			if(*p == '\'') {
				const char *s = p;
				while(*++p && (*p != '\'' || *++p == '\''))
					;
				cmd.Cat(s, int(p - s));
			}
			else {
				if(*p > ' ')
					cmd.Cat(*p);
				else if(!cmd.IsEmpty() && *cmd.Last() != ' ')
					cmd.Cat(' ');
				p++;
			}
		if(progress_canceled(int(p - text.Begin()), text.GetLength()))
			return false;
		if(!IsNull(cmd) && !executor.Execute(cmd))
			return false;
		if(*p == ';')
			p++;
	}
	return true;
}
Beispiel #4
0
void BenchNTL(const char *file, Stream& out) {
	FileIn in(file);
	if (!in) {
		out << "Cannot open input file.\n";
		return;
	}

	C map;
	
	for(;;) {
		int c = in.Get();
		if(c < 0) break;
		if(IsAlpha(c) || c == '_') {
			String id;
			id.Cat(c);
			c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '_')) {
				id.Cat(c);
				c = in.Get();
			}
			map.GetAdd(id, 0)++;
		}
		else
		if(IsDigit(c))
			do c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '.'));
	}

	for(int i = 0; i < map.GetCount(); i++)
		out << ~map.GetKey(i) << ": " << map[i] << '\n';
}
Beispiel #5
0
String DocDir::GetAddFileName(const String& package, const DocKey& key, int type)
{
	Entry& w = dir.GetAdd(package).GetAdd(key);
	String& fn = w.text;
	w.type = type;
	if(!IsEmpty(fn)) return fn;
	String nm = key.nameing + '_' + key.nesting + '_' + key.item;
	String n;
	const char *s = nm;
	while(*s && n.GetLength() < 30)
		if(iscid(*s))
			n.Cat(*s++);
		else {
			n.Cat('_');
			while(*s && !iscid(*s))
				s++;
		}
	n << '_' << LNGAsText(key.lang);
	int i = 0;
	for(;;) {
		fn = n + FormatIntAlpha(i) + ".dpp";
		if(!FindFile(DocFile(package, fn)))
			return fn;
		i++;
	}
}
Beispiel #6
0
void BenchNTL2(const char *file, Stream& out) {
	FileIn in(file);
	if (!in) {
		out << "Cannot open input file.\n";
		return;
	}

	VectorMap<String, int> map;
	
	for(;;) {
		int c = in.Get();
		if(c < 0) break;
		if(IsAlpha(c) || c == '_') {
			String id;
			id.Cat(c);
			c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '_')) {
				id.Cat(c);
				c = in.Get();
			}
			map.GetAdd(id, 0)++;
		}
		else
		if(IsDigit(c))
			do c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '.'));
	}

	Vector<int> order = GetSortOrder(map.GetKeys());
	for(int i = 0; i < order.GetCount(); i++)
		out << ~map.GetKey(order[i]) << ": " << map[order[i]] << '\n';
}
Beispiel #7
0
// we can hava a non-quoted string... so we read up
// to terminator, which can be '}', ']' or ','
int MIValue::ParseUnquotedString(String const &s, int i)
{
	String valStr;
	int aCount = 0;
	bool inQuote = false;

	while(s[i] && ((s[i] != '=' && s[i] != '}' && s[i] != ']' && !comma(s, i)) || inQuote || aCount))
	{
		valStr.Cat(s[i]);
		if(s[i] == '\\')
		{
			i++;
			if(s[i])
				valStr.Cat(s[i++]);
			continue;
		}
		if(s[i] == '<' && !inQuote)
			aCount++;
		else if(s[i] == '>' && !inQuote)
			aCount--;
		else if(s[i] == '"' && !aCount)
			inQuote = !inQuote;
		i++;
	}
	type = MIString;
	string = valStr;

	return i;
}
Beispiel #8
0
String DeAmp(const char *s)
{
	String out;
	for(; *s; out.Cat(*s++))
		if(*s == '&')
			out.Cat('&');
	return out;
}
Beispiel #9
0
static void sMergeWith(String& dest, const char *delim, const String& s)
{
	if(s.GetLength()) {
		if(dest.GetCount())
			dest.Cat(delim);
		dest.Cat(s);
	}
}
Beispiel #10
0
String QualifyIds(ScopeInfo& nf, const String& k, const String& usings, bool all)
{
	LTIMING("QualifyIds");
	String r;
	const char *s = k;
	Vector<String> empty;
	while(*s) {
		int c = *s;
		if(c == ':') {
			const char *b = s++;
			while(*s == ':' || iscid(*s)) s++;
/*			if(all) {
				if(iscid(*r.Last()))
					r << ' ';
				ScopeInfo nnf(nf.GetScope(), nf.base);
				Qualify(r, nnf, b, s, usings);
			}
			else*/
				r.Cat(b, s);
		}
		else
		if(iscid(c)) {
			if(iscid(*r.Last()))
				r << ' ';
			if(s[0] == 'c' && s[1] == 'o' && s[2] == 'n' && s[3] == 's' && s[4] == 't' && !iscid(s[5])) {
				r << s_const;
				s += 5;
			}
			else
			if(s[0] == 'm' && s[1] == 'u' && s[2] == 't' && s[3] == 'a' && s[4] == 'b' && s[5] == 'l' && s[6] == 'e' && !iscid(s[7])) {
				r << "mutable";
				s += 7;
			}
			else
			if(s[0] == 'v' && s[1] == 'o' && s[2] == 'l' && s[3] == 'a' && s[4] == 't' && s[5] == 'i' && s[6] == 'l' && s[7] == 'e' && !iscid(s[8])) {
				r << "volatile";
				s += 8;
			}
			else {
				const char *b = s++;
				while(*s == ':' || iscid(*s)) s++;
				if(all)
					Qualify(r, nf, b, s, usings);
				else
					r.Cat(b, s);
			}
		}
		else {
			if(c == '(')
				all = true;
			if(c != ' ')
				r.Cat(c);
			s++;
		}
	}
	return r;
}
Beispiel #11
0
String Gather(const Array<OptItem>& set, const Vector<String>& conf, bool nospace) {
	String s;
	for(int i = 0; i < set.GetCount(); i++)
		if(MatchWhen(set[i].when, conf)) {
			if(!nospace && !s.IsEmpty()) s.Cat(' ');
			s.Cat(set[i].text);
		}
	return s;
}
Beispiel #12
0
String AlphaToRLE(const Image& aa)
{
	String result;
	for(int y = 0; y < aa.GetHeight(); y++) {
		result.Cat(PackRLE(aa[y], aa.GetWidth()));
		result.Cat(0x80);
	}
	return result;
}
Beispiel #13
0
bool WinMetaFileDraw::Create(HDC hdc, int cx, int cy, const char *app, const char *name, const char *file) {
	if(handle) Close();

	String s;
	if(app) s.Cat(app);
	s.Cat('\0');
	if(name) s.Cat(name);
	s.Cat('\0');

	bool del = false;
	if(!hdc) {
		hdc = ::GetWindowDC((HWND) NULL);
		del = true;
	}
	size = Size(iscale(cx, 2540, 600), iscale(cy, 2540, 600));

	Rect r = size;

	HDC mfdc = ::CreateEnhMetaFile(hdc, file, r, name || app ? (const char *)s : NULL);
	if(!mfdc)
		return false;
	Size px(max(1, ::GetDeviceCaps(mfdc, HORZRES)),  max(1, ::GetDeviceCaps(mfdc, VERTRES)));
	Size mm(max(1, ::GetDeviceCaps(mfdc, HORZSIZE)), max(1, ::GetDeviceCaps(mfdc, VERTSIZE)));
	Attach(mfdc);

	Init();

	pixels = false;

	::SetMapMode(handle, MM_ANISOTROPIC);
	::SetWindowOrgEx(handle, 0, 0, 0);
	::SetWindowExtEx(handle, 600, 600, 0);
	::SetViewportOrgEx(handle, 0, 0, 0);
	::SetViewportExtEx(handle, px.cx * 254 / (10 * mm.cx), px.cy * 254 / (10 * mm.cy), 0);
	::SelectClipRgn(mfdc, NULL);
	::IntersectClipRect(mfdc, 0, 0, cx, cy);

	if(del) {
		::ReleaseDC((HWND) NULL, hdc);
		hdc = NULL;
	}

	actual_offset = Point(0, 0);

	printer = false;
	pixels = false;
	actual_offset = Point(0, 0);
	device = -1;
	aborted = false;
	palette = false;
	backdraw = true;

	return true;
}
Beispiel #14
0
String CatAnyPath(String path, const char *more)
{
	if(!more || !*more)
		return path;
	if(!path.IsEmpty() && *path.Last() != '\\' && *path.Last() != '/' &&
	*more != '\\' && *more != '/')
#ifdef PLATFORM_WIN32
		path.Cat('\\');
#else
		path.Cat('/');
#endif
	path.Cat(more);
	return path;
}
Beispiel #15
0
String NormalizePath(const char *path, const char *currdir)
{
	String join_path;
	if(!IsFullPath(path))
		path = join_path = AppendFileName(currdir, path);
	String out;
	if(*path && path[1] == ':') {
		out << path[0] << ":\\";
		path += 3;
	}
	else
	if(path[0] == '\\' && path[1] == '\\') {
		out = "\\\\";
		path += 2;
	}
	else
	if(sDirSep(*path)) {
		if(*currdir)
			out << *currdir << ':';
		out.Cat(DIR_SEP);
		path++;
	}
	int outstart = out.GetLength();
	while(*path) {
		if(sDirSep(*path)) {
			while(sDirSep(*path))
				path++;
			if(*path == '\0')
				break;
			if(out.IsEmpty() || *out.Last() != DIR_SEP)
				out.Cat(DIR_SEP);
		}
		const char *b = path;
		while(*path && !sDirSep(*path))
			path++;
		if(path - b == 1 && *b == '.')
			; //no-op
		else if(path - b == 2 && *b == '.' && b[1] == '.') {
			const char *ob = ~out + outstart, *oe = out.End();
			if(oe - 1 > ob && oe[-1] == DIR_SEP)
				oe--;
			while(oe > ob && oe[-1] != DIR_SEP)
				oe--;
			out.Trim((int)(oe - out.Begin()));
		}
		else
			out.Cat(b, (int)(path - b));
	}
	return out;
}
Beispiel #16
0
String  DocReport::HFormat(const char *s) {
	String result;
	while(*s) {
		if(s[0] == '$' && s[1] == '$') {
			if(s[2] == 'P')
				result.Cat(Format("%d", pageno));
			if(s[2] == 'D')
				result.Cat(Format(GetSysDate()));
			s += 3;
		}
		result.Cat(*s++);
	}
	return result;
}
Beispiel #17
0
void AppendFiles(VectorMap<String, ClipData>& clip, const Vector<String>& files)
{
	WString wfiles;
	for(int i = 0; i < files.GetCount(); i++)
		wfiles << files[i].ToWString() << "\0";
	sDROPFILES h;
	h.unicode = true;
	h.offset = sizeof(h);
    GetCursorPos(&h.pt);
    h.nc = TRUE;
    String data;
	data.Cat((byte *)&h, sizeof(h));
	data.Cat((byte *)~wfiles, 2 * (wfiles.GetCount() + 1));
	clip.GetAdd("files") = ClipData(data);
}
Beispiel #18
0
void MyApp::LeftDrag(Point p, dword keyflags)
{
	String bin;
	bin.Cat((byte *)&data.color, sizeof(data.color));
	bin.Cat(data.text);
	VectorMap<String, ClipData> d;
	d.Add("MyAppData", bin);
	Append(d, data.text);
	Size sz(128, 64);
	ImageDraw iw(sz);
	iw.DrawRect(sz, Black());
	iw.Alpha().DrawRect(sz, Black());
	iw.Alpha().DrawText(0, 0, data.text, Courier(14), White());
	DoDragAndDrop(d, iw);
}
Beispiel #19
0
// read data, requested amount, blocks 'timeout' milliseconds
// if reqSize == 0 just read all available data, waiting for 'timeout' if != 0
String Serial::Read(size_t reqSize, uint32_t timeout)
{
	char buf[1001];
	buf[1000] = 0;
	String data;

	size_t n;
	uint32_t tim = msecs() + timeout;
	if(reqSize)
	{
		n = min(reqSize, (size_t)1000);
		while(reqSize)
		{
			n = read(fd, buf, n);
			if(!n)
			{
				if((uint32_t)msecs() > tim)
					break;
				n = min(reqSize, (size_t)1000);
				continue;
			}
			tim = msecs() + timeout;
			if(n)
			{
				reqSize -= n;
				data.Cat(buf, n);
			}
			n = min(reqSize, (size_t)1000);
		}
	}
	else
	{
		for(;;)
		{
			n = read(fd, buf, 1000);
			if(!n)
			{
				if((uint32_t)msecs() > tim)
					break;
				continue;
			}
			tim = msecs() + timeout;
			if(n)
				data.Cat(buf, n);
		}
	}
	return data;	
}
Beispiel #20
0
String GetProperty(Window w, Atom property, Atom rtype)
{
	GuiLock __; 
	LLOG("GetProperty");
	String result;
	int format;
	unsigned long nitems, after = 1;
	long offset = 0;
	Atom type = None;
	unsigned char *data;
	long rsize = minmax((long)(XMaxRequestSize(Xdisplay) - 100), (long)256, (long)65536);
	while(after > 0) {
		if(XGetWindowProperty(Xdisplay, w, property, offset, rsize, XFalse,
	                          rtype, &type, &format, &nitems, &after, &data) != Success)
	    	break;
	    if(type == None)
	        break;
		if(data) {
			int len = format == 32 ? sizeof(unsigned long) * nitems : nitems * (format >> 3);
			result.Cat(data, len);
			XFree((char *)data);
			offset += nitems / (32 / format);
		}
		else
			break;
	}
Beispiel #21
0
bool Sqlite3PerformScript(const String& txt, StatementExecutor& se, Gate2<int, int> progress_canceled) {
	const char *text = txt;
	for(;;) {
		String stmt;
		while(*text <= 32 && *text > 0) text++;
		if(*text == '\0') break;
		for(;;) {
			if(*text == '\0')
				break;
			if(*text == ';')
				break;
			else
			if(*text == '\'')
				text = Sqlite3ReadString(text, stmt);
			else
			if(*text == '\"')
				text = Sqlite3ReadString(text, stmt);
			else
				stmt.Cat(*text++);
		}
		if(progress_canceled(text - txt.Begin(), txt.GetLength()))
			return false;
		if(!se.Execute(stmt))
			return false;
		if(*text) text++;
	}
	return true;
}
Beispiel #22
0
void AString<B>::Replace(const tchar *find, int findlen, const tchar *replace, int replacelen)
{
	String r;
	int i = 0;
	const tchar *p = B::Begin();
	for(;;) {
		int j = Find(findlen, find, i);
		if(j < 0)
			break;
		r.Cat(p + i, j - i);
		r.Cat(replace, replacelen);
		i = j + findlen;
	}
	r.Cat(p + i, B::GetCount() - i);
	*this = r;
}
Beispiel #23
0
String RichPara::Number::AsText(const RichPara::NumberFormat& format) const
{
	String result;
	for(int i = 0; i < 8; i++)
		if(format.number[i]) {
			if(result.GetLength())
				result.Cat('.');
			int q = n[i];
			switch(format.number[i]) {
			case NUMBER_1:
				result << AsString(q);
				break;
			case NUMBER_0:
				result << AsString(q - 1);
				break;
			case NUMBER_a:
				result << FormatIntAlpha(q, false);
				break;
			case NUMBER_A:
				result << FormatIntAlpha(q, true);
				break;
			case NUMBER_i:
				result << FormatIntRoman(q, false);
				break;
			case NUMBER_I:
				result << FormatIntRoman(q, true);
				break;
			}
		}
	return format.before_number + result + format.after_number;
}
Beispiel #24
0
String GetIncludePath0(const char *s, const char *filedir)
{
	LTIMING("GetIncludePath0");
	while(IsSpace(*s))
		s++;
	int type = *s;
	if(type == '<' || type == '\"' || type == '?') {
		s++;
		String name;
		if(type == '<') type = '>';
		while(*s != '\r' && *s != '\n') {
			if(*s == type) {
				if(type == '\"') {
					String fn = NormalizeSourcePath(name, filedir);
					if(FileExists(fn))
						return fn;
				}
				String p = GetFileOnPath(name, GetIncludePath(), false);
				if(p.GetCount())
					return NormalizeSourcePath(p);
				return Null;
			}
			name.Cat(*s++);
		}
	}
	return Null;
}
Beispiel #25
0
NAMESPACE_UPP

#define LAYOUTFILE <TCtrlLib/Help/DlgShot.lay>
#include <CtrlCore/lay.h>

// Smart Text Formatting
// '\n' - left aligned line
// '\t' - left align, dont leave line
// '\r' - right aligned line
// '\2' - right align, dont leave line
// '\v' - centered line
// '\1' - center align, dont leave line
// '\a' - underline switch
// '\b' - bold switch
// '\f' - italic switch

String StripSmartText(const char *smart)
{
    String out;
    for(; *smart; smart++)
        if(*smart != '\n' && *smart != '\t' && *smart != '\r' && *smart != '\2'
                && *smart != '\v' && *smart != '\1' && *smart != '\a' && *smart != '\b' && *smart != '\f')
            out.Cat(*smart);
    return out;
}
Beispiel #26
0
bool LoadVarFile(const char *name, VectorMap<String, String>& _var)
{
	try {
		VectorMap<String, String> var;
		String env = LoadFile(name);
		CParser p(env);
		while(!p.IsEof()) {
			String v = p.ReadId();
			p.Char('=');
			if(p.IsString())
				var.GetAdd(v) = p.ReadString();
			else {
				String ln;
				while(p.PeekChar() != '\r' && p.PeekChar() != '\n' && p.PeekChar() != ';')
					ln.Cat(p.GetChar());
				var.GetAdd(v) = ln;
				p.Spaces();
			}
			p.Char(';');
		}
		_var = pick(var);
		return true;
	}
	catch(...) {
		return false;
	}
}
Beispiel #27
0
void WStringTutorial()
{
	/// .WString

	/// String works with 8 bit characters. For 16-bit character encoding use `WString`. Both
	/// classes are closely related and share most of interface methods. U++ also provides
	/// conversions between `String` and `WString` and you can also use 8 bit string literals with
	/// `WString`. Conversion is ruled by current default character set. Default value of default
	/// character set is `CHARSET_UTF8`. This conversion is also used in `WString::ToString`,
	/// e.g. when putting `WString` to log:

	WString x = "characters 280-300: "; // you can assign 8-bit character literal to WString
	for(int i = 280; i < 300; i++)
		x.Cat(i);
	
	DUMP(x);
	
	/// `ToString` converts `WString` to `String`:

	String y = x.ToString();
	DUMP(y);

	/// `ToWString` converts `String` to `WString`:

	y.Cat(" (appended)"); // you can use 8-bit character literals in most WString operations
	x = y.ToWString();
	
	DUMP(x);
	
	///
}
Beispiel #28
0
Vector<String> GetClipFiles(const String& data)
{
	GuiLock __;
	Vector<String> f;
	if((unsigned)data.GetCount() < sizeof(sDROPFILES) + 2)
		return f;
	const sDROPFILES *df = (const sDROPFILES *)~data;
	const char *s = ((const char *)df + df->offset);
	if(df->unicode) {
		const wchar *ws = (wchar *)s;
		while(*ws) {
			WString fn;
			while(*ws)
				fn.Cat(*ws++);
			f.Add(fn.ToString());
			ws++;
		}
	}
	else
		while(*s) {
			String fn;
			while(*s)
				fn.Cat(*s++);
			f.Add(fn.ToString());
			s++;
		}
	return f;
}
Beispiel #29
0
String RandomString(int n)
{
	String h;
	while(n-- > 0)
		h.Cat((byte)Random());
	return h;
}
Beispiel #30
0
String NormalizePath(const char *path, const char *currdir) {
	Vector<String> si = Split(path, CharFilterTextTest(sDirSep));
	Vector<String> p;
	int i = 0;
	String out;
	if(path[0] == '~') {
		out = GetHomeDirectory();
		i++;
	}
	else
	if(sDirSep(path[0]))
		out = (sDirSep(path[1]) ? "//" : "/");
	else {
		out = (sDirSep(currdir[0]) && sDirSep(currdir[1]) ? "//" : "/");
		p = Split(currdir, CharFilterTextTest(sDirSep));
	}
	for(; i < si.GetCount(); i++) {
		String s = si[i];
		if(s != "." && !s.IsEmpty())
			if(s[0] == '.' && s[1] == '.') {
				if(!p.IsEmpty()) p.Drop();
			}
			else
				p.Add(s);
	}
	out.Cat(Join(p, DIR_SEPS));
	return out;
}