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; }
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; }
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; }
dword String::LEqual(const String& s) const { #ifdef CPU_64 int l = GetCount(); if(s.GetCount() != l) return 1; const qword *qa = (const qword *)Begin(); const qword *qb = (const qword *)s.Begin(); while(l >= 8) { if(*qa++ != *qb++) return 1; l -= 8; } const dword *da = (const dword *)qa; const dword *db = (const dword *)qb; if((l & 4) && *da++ != *db++) return 1; #else int l = GetCount(); if(s.GetCount() != l) return 1; const dword *da = (const dword *)Begin(); const dword *db = (const dword *)s.Begin(); while(l >= 4) { if(*da++ != *db++) return 1; l -= 4; } #endif const word *wa = (const word *)da; const word *wb = (const word *)db; if((l & 2) && *wa++ != *wb++) return 1; return (l & 1) ? *(const char *)wa != *(const char *)wb : 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*"; } }
int GetMatchLen(const String& x) const { if(*x == '<') return 0; String h = PackagePath(x); for(int i = 0; i < mainpath.GetCount(); i++) if(mainpath[i] != h[i]) return i; return mainpath.GetCount(); }
NewPackageFileWindow::NewPackageFileWindow() { CtrlLayoutOKCancel(*this, "New package file"); type.SetLineCy(max(Zy(16), Draw::GetStdFontCy())); type.SetDropLines(20); Type("cpp", "C++ source file"); Type("h", "C++ header file"); type.AddSeparator(); Type("lay", "Layout file (dialog templates)"); Type("iml", "Image file (icons)"); Type("icpp", "Initialization C++ source file"); Type("usc", "Escape script file (scripting TheIDE)"); Type("witz", "Skylark template file (web framework files)"); Type("qtf", "U++ rich text file"); type.AddSeparator(); Type("json", "JSON file"); Type("xml", "XML file"); Type("html", "HTML file"); Type("css", "CSS file"); type.AddSeparator(); Type("sch", "SQL schema file"); Type("ddl", "SQL DDL script file"); Type("sql", "SQL script file"); type.AddSeparator(); Type("java", "Java"); Type("js", "JavaScript"); Type("py", "Python"); type.AddSeparator(); Type("", "Other"); name << [=] { String ext = GetFileExt(~~name); if(ext.GetCount()) { ext = ext.Mid(1); type <<= type.HasKey(ext) ? ext : Null; } Sync(); }; name <<= ".cpp"; type <<= "cpp"; type << [=] { String ext = ~type; if(ext.GetCount()) { String h = ~name; name <<= ForceExt(h, "." + ext); int q = GetFileTitle(h).GetCount(); name.SetSelection(q, q); } Sync(); }; Sync(); }
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; }
//задание цвета строки 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>()); }
String Apk::FindBadgeTagValue(const String& badge, const String& tag) const { String tagValue; String tagBeginning = tag + "='"; int pos = badge.Find(tagBeginning); if(pos >= 0) { for(int i = pos + tagBeginning.GetCount(); i < badge.GetCount(); i++) { if(badge[i] == '\'') break; tagValue += badge[i]; } } return tagValue; }
bool Ide::EditorTip(CodeEditor::MouseTip& mt) { if(!debugger) return false; DR_LOG("EditorTip"); int pos = mt.pos; String e; String sep; while(pos >= 0) { String b = editor.ReadIdBackPos(pos, false); if(b.GetCount() == 0) break; e = b + sep + e; sep = "."; while(pos > 0 && editor.GetChar(pos - 1) == ' ') pos--; if(pos > 0 && editor.GetChar(pos - 1) == '.') --pos; else if(pos >= 2 && editor.GetChar(pos - 1) == ':' && editor.GetChar(pos - 2) == ':') { pos -= 2; sep = "::"; } else if(pos >= 2 && editor.GetChar(pos - 1) == '>' && editor.GetChar(pos - 2) == '-') pos -= 2; else break; while(pos > 0 && editor.GetChar(pos - 1) == ' ') pos--; } DR_LOG("debugger->Tip"); return debugger->Tip(e, mt); }
String ChangeTopicLanguage(const String &topic, int lang) { int pos = topic.ReverseFind('$'); if (pos < 0) return ""; String langtxt = ToLower(LNGAsText(lang)); return topic.Left(pos+1) + langtxt + topic.Mid(pos+1+langtxt.GetCount()); }
void OutMode::CmdOptions() { const Workspace& wspc = ide.IdeWorkspace(); int pi = wspc.GetCount() > 0 ? 0 : -1; if (pi < 0) { PromptOK("No main package"); return; } VectorMap<String, String> bm = ide.GetMethodVars(~method); if (bm.GetCount() == 0) { PromptOK("Invalid build method"); return; } One<Host> host = ide.CreateHost(false); One<Builder> b = ide.CreateBuilder(~host); const String& p = wspc[pi]; String output = NativePath(ide.OutDir(ide.PackageConfig(wspc, pi, bm, ~config, *host, *b), p, bm, true)); if (output.Right(1) == ".") output = output.Left(output.GetCount() - 1); const ModePane& pane = ~mode == 0 ? debug : release; int blitzpackage = pane.package.Get(0, 2); bool blitzbuild = !wspc.package[pi].noblitz && pane.blitz && (IsNull(blitzpackage) ? true : blitzpackage); CmdBuildOptionsWindow window(p, ~method, ~config, output, ~mode, ide.hydra1_threads, pane.linkmode, blitzbuild, pane.map, ide.console.verbosebuild); LoadFromGlobal(window, "CmdBuildOptionsWindow"); window.GenerateCmd(); window.Run(); StoreToGlobal(window, "CmdBuildOptionsWindow"); }
String GetExeFileTypeAssociation(const String ext) { String buff = GetWinRegString("", GetWinRegString("", ext, HKEY_CLASSES_ROOT) + String("\\Shell\\Open\\Command"), HKEY_CLASSES_ROOT); buff = buff.Left(buff.Find(".exe")+4); if(buff.Left(1) == "\"") return buff.Right(buff.GetCount() - 1); else return buff; }
void Ide::Licenses() { Progress pi; const Workspace& wspc = IdeWorkspace(); pi.SetTotal(wspc.GetCount()); VectorMap<String, String> license_package; for(int i = 0; i < wspc.GetCount(); i++) { String n = wspc[i]; pi.SetText(n); if(pi.StepCanceled()) return; String l = LoadFile(SourcePath(n, "Copying")); if(l.GetCount()) MergeWith(license_package.GetAdd(l), ", ", n); } if(license_package.GetCount() == 0) { Exclamation("No license files ('Copying') have been found."); return; } String qtf; for(int i = 0; i < license_package.GetCount(); i++) { bool m = license_package[i].Find(',') >= 0; qtf << (m ? "Packages [* \1" : "Package [* \1") << license_package[i] << (m ? "\1] have" : "\1] has") << " following licence notice:&" << "{{@Y [C1 " << DeQtf(license_package.GetKey(i)) << "]}}&&"; } ShowQTF(qtf, "Licenses"); }
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)); }
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)); }
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; }
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; }
void Navigator::NavGroup(bool local) { for(int i = 0; i < nitem.GetCount(); i++) { NavItem& m = nitem[i]; String g = m.nest; if(m.kind == TYPEDEF) g.Trim(max(g.ReverseFind("::"), 0)); if(IsNull(g) || CodeBase().namespaces.Find(m.nest) >= 0) { if(g.GetCount()) // We want to show the namespace g << '\xff'; else g.Clear(); g << GetSourceFilePath(m.decl_file); g = '\xff' + g; } if(!local) g = (char)(m.pass + 10) + g; if(local) if(gitem.GetCount() && gitem.TopKey() == g) gitem.Top().Add(&m); else gitem.Add(g).Add(&m); else gitem.GetAdd(g).Add(&m); } }
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; }
Image GetImage(PasteClip& clip) { GuiLock __; Image m; if(Accept<Image>(clip)) { LoadFromString(m, ~clip); if(!m.IsEmpty()) return m; } if(clip.Accept("dib")) { String data = ~clip; if((unsigned)data.GetCount() < sizeof(BITMAPINFO)) return Null; BITMAPINFO *lpBI = (BITMAPINFO *)~data; BITMAPINFOHEADER& hdr = lpBI->bmiHeader; byte *bits = (byte *)lpBI + hdr.biSize; if(hdr.biBitCount <= 8) bits += (hdr.biClrUsed ? hdr.biClrUsed : 1 << hdr.biBitCount) * sizeof(RGBQUAD); if(hdr.biBitCount >= 16 || hdr.biBitCount == 32) { if(hdr.biCompression == 3) bits += 12; if(hdr.biClrUsed != 0) bits += hdr.biClrUsed * sizeof(RGBQUAD); } int h = abs((int)hdr.biHeight); ImageDraw iw(hdr.biWidth, h); ::StretchDIBits(iw.GetHandle(), 0, 0, hdr.biWidth, h, 0, 0, hdr.biWidth, h, bits, lpBI, DIB_RGB_COLORS, SRCCOPY); return iw; } return Null; }
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())); }
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"; }
int GetEditWidth(const String str) { Font font = StdFont(); int ret = 0; for (int i = 0; i < str.GetCount(); ++i) ret += font.GetWidth(str[i]); return ret; }
String RemoveQuote(const String &str) { if(str.Left(1) == "\"" && str.Right(1) == "\"") { if(str.GetCount() == 2) return String(""); return str.Mid(1, str.GetLength()-2); } return str; }
static void sMergeWith(String& dest, const char *delim, const String& s) { if(s.GetLength()) { if(dest.GetCount()) dest.Cat(delim); dest.Cat(s); } }
void CodeBrowser::Load() { String find = ToUpper((String)~search); String match = ToUpper((String)~search_scope); String pm = GetPm(); Vector<String> txt; Vector<Value> ndx; Index<int> fi; Index<String> fs; for(int i = 0; i < CodeBase().GetCount(); i++) { String s = CodeBase().GetKey(i); const Array<CppItem>& n = CodeBase()[i]; if(s.GetCount()) if(MatchCib(s, match) && (MatchCib(s, find) || HasItem(n, find)) && MatchPm(n, pm)) { txt.Add(s); ndx.Add(s); } for(int i = 0; i < n.GetCount(); i++) { int f = n[i].file; if(fi.Find(f) < 0) { String s = GetFileText(GetSourceFilePath(f)); if(s.StartsWith(pm) && MatchCib(s, match) && (IsNull(find) || MatchCib(s, find) || n[i].uname.StartsWith(find))) { txt.Add(s); ndx.Add(f); fs.Add(s); fi.Add(f); } } } } const Workspace& wspc = GetIdeWorkspace(); for(int i = 0; i < wspc.GetCount(); i++) { String pn = wspc[i]; const Package& p = wspc.GetPackage(i); String pp = PackageDirectory(pn); for(int j = 0; j < p.GetCount(); j++) if(!p[j].separator) { String fn = AppendFileName(pp, p[j]); String s = GetFileText(AppendFileName(pn, p[j])); if(fs.Find(s) < 0 && (IsNull(find) || MatchCib(s, find)) && MatchCib(s, match) && MatchPm(fn, pm)) { int f = GetSourceFileIndex(SourcePath(pn, p[j])); txt.Add(s); ndx.Add(f); fs.Add(s); } } } IndexSort(txt, ndx, ScopeLess()); Value key = scope.GetKey(); int sc = scope.GetCursorSc(); scope.Clear(); for(int i = 0; i < txt.GetCount(); i++) scope.Add(IsString(ndx[i]) ? ndx[i] : Null, txt[i], ndx[i]); if(scope.FindSetCursor(key)) scope.ScCursor(sc); // clear.Enable(IsSearch()); }
// 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; }
void Pdb::DropWatch(PasteClip& clip) { String s = StringStream(GetString(clip)).GetLine(); if(s.GetCount()) { watches.Add(s); clip.SetAction(DND_COPY); Data(); } }