diff --git a/lib/main/code/picodeparser.cpp b/lib/main/code/picodeparser.cpp index 8d26d1fe..d4301feb 100644 --- a/lib/main/code/picodeparser.cpp +++ b/lib/main/code/picodeparser.cpp @@ -24,7 +24,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const { PIStringList arg_vals; while (!args_.isEmpty()) { - int ci = args_.find(","), bi = args_.find("("); + int ci = args_.find(','), bi = args_.find('('); if (ci < 0) { arg_vals << args_; break; @@ -33,7 +33,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const { if (bi >= 0 && bi < ci) { ca = args_.left(args_.takeLeft(bi).toInt()); ci -= ca.size_s(); bi -= ca.size_s(); - ca += "(" + args_.takeRange("(", ")") + ")"; + ca += '(' + args_.takeRange('(', ')') + ')'; } else { ca = args_.takeLeft(ci); } @@ -41,7 +41,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const { args_.trim(); args_.takeLeft(1); args_.trim(); } if (args.size() != arg_vals.size()) { - piCout << ("Error: in expansion of macro \"" + name + "(" + args.join(", ") + ")\": expect") + piCout << ("Error: in expansion of macro \"" + name + '(' + args.join(", ") + ")\": expect") << args.size() << "arguments but takes" << arg_vals.size() << "!"; if (ok != 0) *ok = false; return PIString(); @@ -57,7 +57,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const { if (ind + an.size_s() < ret.size_s()) nc = ret.mid(ind + an.size_s(),1)[0]; if (ppc != '#' && pc == '#' && !_isCChar(nc)) { // to chars ind--; - ret.replace(ind, an.size_s() + 1, "\"" + av + "\""); + ret.replace(ind, an.size_s() + 1, '\"' + av + '\"'); ind -= an.size_s() - av.size_s() - 1; continue; } @@ -66,7 +66,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const { ind -= an.size_s() - av.size_s(); } } - ret.replaceAll("##", ""); + ret.replaceAll(PIStringAscii("##"), ""); if (ok != 0) *ok = true; return ret; } @@ -99,20 +99,20 @@ void PICodeParser::parseFile(const PIString & file, bool follow_includes) { } piCout << "\n\nDefines:"; piForeachC (Define & m, defines) - piCout << "define" << m.first << m.second; + piCout << PIStringAscii("define") << m.first << m.second; piCout << "\n\nMacros:"; piForeachC (Macro & m, macros) piCout << "Macro:" << m.name << m.args << m.value; piCout << "\n\nClasses:"; piCout << "\n\nEnums:"; piForeachC (Enum & c, enums) { - piCout << "enum" << c.name << c.meta; + piCout << PIStringAscii("enum") << c.name << c.meta; piForeachC (EnumeratorInfo & e, c.members) piCout << " " << e.name << "=" << e.value << e.meta; } piCout << "\n\nTypedefs:"; piForeachC (Typedef & c, typedefs) - piCout << "typedef" << c;*/ + piCout << PIStringAscii("typedef") << c;*/ } @@ -122,19 +122,19 @@ void PICodeParser::parseFiles(const PIStringList & files, bool follow_includes) parseFileInternal(f, follow_includes); /*piCout << "\n\nDefines:"; piForeachC (Define & m, defines) - piCout << "define" << m.first << m.second; + piCout << PIStringAscii("define") << m.first << m.second; piCout << "\n\nMacros:"; piForeachC (Macro & m, macros) piCout << "Macro:" << m.name << m.args << m.value; piCout << "\n\nClasses:"; piForeachC (Entity * c, entities) - piCout << "class" << c->name << c->parents; + piCout << PIStringAscii("class") << c->name << c->parents; piCout << "\n\nEnums:"; piForeachC (Enum & c, enums) - piCout << "enum" << c.name << c.members; + piCout << PIStringAscii("enum") << c.name << c.members; piCout << "\n\nTypedefs:"; piForeachC (Typedef & c, typedefs) - piCout << "typedef" << c;*/ + piCout << PIStringAscii("typedef") << c;*/ } @@ -153,7 +153,7 @@ bool PICodeParser::parseFileInternal(const PIString & file, bool follow_includes PIFile f(file, PIIODevice::ReadOnly); int ii = 0; while (!f.isOpened() && ii < (includes.size_s() - 1)) { - f.setPath(includes[++ii] + "/" + file); + f.setPath(includes[++ii] + '/' + file); //piCout << "try" << f.path(); f.open(PIIODevice::ReadOnly); } @@ -186,7 +186,7 @@ void PICodeParser::clear() { evaluator.clearCustomVariables(); cur_def_vis = Global; anon_num = 0; - defines << Define("PICODE", "") << custom_defines; + defines << Define(PIStringAscii("PICODE"), "") << custom_defines; } @@ -197,9 +197,9 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) { PIString pfc, line, ccmn, tmp; PIMap cchars; - /// Remove comments, join multiline "*" and replace "*" to $n (cchars) - fc.replaceAll("\r\n", "\n"); - fc.replaceAll("\r", "\n"); + /// Remove comments, join multiline '*' and replace '*' to $n (cchars) + fc.replaceAll("\r\n", '\n'); + fc.replaceAll('\r', '\n'); for (int i = 0; i < fc.size_s() - 1; ++i) { if (fc[i].unicode16Code() >= 255) continue; if (i > 0) pc = c; @@ -256,7 +256,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) { if (ind + m.name.size_s() < pfc.size_s()) nc = pfc.mid(ind + m.name.size_s(),1)[0]; if (_isCChar(pc) || _isCChar(nc) || nc.isDigit()) continue; PIString ret, range; bool ok(false); - range = pfc.mid(ind + m.name.size_s()).takeRange("(", ")"); + range = pfc.mid(ind + m.name.size_s()).takeRange('(', ')'); ret = m.expand(range, &ok); if (!ok) return false; int rlen = pfc.find(range, ind + m.name.size_s()) + range.size_s() + 1 - ind; @@ -275,20 +275,20 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) { if (pl == nl) break; pl = nl; if (pfc.left(9) == "namespace") { - pfc.cutLeft(pfc.find("{") + 1); + pfc.cutLeft(pfc.find('{') + 1); continue; } if (pfc.left(8) == "template") { pfc.cutLeft(8); - pfc.takeRange("<", ">"); + pfc.takeRange('<', '>'); bool def = !isDeclaration(pfc, 0, &end); pfc.cutLeft(end); - if (def) pfc.takeRange("{", "}"); + if (def) pfc.takeRange('{', '}'); else pfc.takeSymbol(); continue; } - if (pfc.left(5) == "class" || pfc.left(6) == "struct" || pfc.left(5) == "union") { - int dind = pfc.find("{", 0), find = pfc.find(";", 0); + if (pfc.left(5) == PIStringAscii("class") || pfc.left(6) == "struct" || pfc.left(5) == "union") { + int dind = pfc.find('{', 0), find = pfc.find(';', 0); if (dind < 0 && find < 0) {pfc.cutLeft(6); continue;} if (dind < 0 || find < dind) {pfc.cutLeft(6); continue;} ccmn = pfc.left(dind) + "{\n" + pfc.mid(dind).takeRange('{', '}') + "\n}\n"; @@ -296,24 +296,24 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) { parseClass(0, ccmn); continue; } - if (pfc.left(4) == "enum") { + if (pfc.left(4) == PIStringAscii("enum")) { pfc.cutLeft(4); tmp = pfc.takeCWord(); pfc.trim(); MetaMap meta = maybeMeta(pfc); - parseEnum(0, cur_namespace + tmp, pfc.takeRange("{", "}"), meta); + parseEnum(0, cur_namespace + tmp, pfc.takeRange('{', '}'), meta); pfc.takeSymbol(); continue; } - if (pfc.left(7) == "typedef") { + if (pfc.left(7) == PIStringAscii("typedef")) { pfc.cutLeft(7); - typedefs << parseTypedef(pfc.takeLeft(pfc.find(";"))); + typedefs << parseTypedef(pfc.takeLeft(pfc.find(';'))); if (typedefs.back().first.isEmpty()) typedefs.pop_back(); else root_.typedefs << typedefs.back(); pfc.takeSymbol(); continue; } - int sci = pfc.find(";", 0), obi = pfc.find("{", 0); + int sci = pfc.find(';', 0), obi = pfc.find('{', 0); if (sci < 0 && obi < 0) { pfc.takeLeft(1); continue; @@ -323,7 +323,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) { str = pfc.takeLeft(sci + 1); } else { str = pfc.takeLeft(obi); - pfc.cutLeft(pfc.takeRange("{", "}").toInt()); + pfc.cutLeft(pfc.takeRange('{', '}').toInt()); } parseMember(&root_, str); } @@ -333,22 +333,22 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) { PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc) { - PIString cd = fc.trimmed().removeAll('\n').replaceAll("\t", " ").replaceAll(" ", " "), pn; + PIString cd = fc.trimmed().removeAll('\n').replaceAll('\t', ' ').replaceAll(PIStringAscii(" "), ' '), pn; MetaMap meta; - int ind = cd.find("$M"); + int ind = cd.find(PIStringAscii("$M")); if (ind >= 0) { meta = tmp_meta.value(cd.takeMid(ind, 5)); - cd.replaceAll(" ", " "); + cd.replaceAll(PIStringAscii(" "), ' '); } //piCout << "found class <****\n" << cd << "\n****>"; - ind = cd.find(":"); + ind = cd.find(':'); PIVector parents; if (ind > 0) { - PIStringList pl = cd.takeMid(ind + 1).trim().split(","); + PIStringList pl = cd.takeMid(ind + 1).trim().split(','); cd.cutRight(1); Entity * pe = 0; piForeachC (PIString & p, pl) { - if (p.contains(" ")) pn = p.mid(p.find(" ") + 1); + if (p.contains(' ')) pn = p.mid(p.find(' ') + 1); else pn = p; pe = findEntityByName(pn); if (pe == 0) ;//{piCout << "Error: can`t find" << pn;} @@ -356,11 +356,11 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc) } } PIString typename_ = cd.left(6).trim(); - bool is_class = typename_ == "class"; + bool is_class = typename_ == PIStringAscii("class"); cur_def_vis = (is_class ? Private : Public); PIString cn = cd.mid(6).trim(); bool has_name = !cn.isEmpty(); - if (cn.isEmpty()) cn = ""; + if (cn.isEmpty()) cn = "'; //piCout << "found " << typename_ << cn; if (cn.isEmpty()) return 0; Entity * e = new Entity(); @@ -377,7 +377,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc) PIString PICodeParser::parseClass(Entity * parent, PIString & fc) { Visibility prev_vis = cur_def_vis; - int dind = fc.find("{"), find = fc.find(";"), end = 0; + int dind = fc.find('{'), find = fc.find(';'), end = 0; if (dind < 0 && find < 0) return PIString(); if (dind < 0 || find < dind) return fc.left(find); //piCout << "parse class <****\n" << fc.left(20) << "\n****>"; @@ -396,37 +396,37 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) { while (!fc.isEmpty()) { PIString cw = fc.takeCWord(), tmp; //piCout << "\ntaked word" << cw; - if (cw == "public") {cur_def_vis = Public; fc.cutLeft(1); continue;} - if (cw == "protected") {cur_def_vis = Protected; fc.cutLeft(1); continue;} - if (cw == "private") {cur_def_vis = Private; fc.cutLeft(1); continue;} - if (cw == "class" || cw == "struct" || cw == "union") { + if (cw == PIStringAscii("public" )) {cur_def_vis = Public; fc.cutLeft(1); continue;} + if (cw == PIStringAscii("protected")) {cur_def_vis = Protected; fc.cutLeft(1); continue;} + if (cw == PIStringAscii("private" )) {cur_def_vis = Private; fc.cutLeft(1); continue;} + if (cw == PIStringAscii("class") || cw == PIStringAscii("struct") || cw == PIStringAscii("union")) { if (isDeclaration(fc, 0, &end)) { fc.cutLeft(end); fc.takeSymbol(); continue; } - tmp = fc.takeLeft(fc.find("{")); - stmp = fc.takeRange("{", "}"); + tmp = fc.takeLeft(fc.find('{')); + stmp = fc.takeRange('{', '}'); fc.takeSymbol(); - stmp = cw + " " + tmp + "{" + stmp + "}"; + stmp = cw + ' ' + tmp + '{' + stmp + '}'; parseClass(ce, stmp); continue; } - if (cw == "enum") { + if (cw == PIStringAscii("enum")) { tmp = fc.takeCWord(); fc.trim(); MetaMap meta = maybeMeta(fc); - parseEnum(ce, cur_namespace + tmp, fc.takeRange("{", "}"), meta); + parseEnum(ce, cur_namespace + tmp, fc.takeRange('{', '}'), meta); fc.takeSymbol(); continue; } - if (cw == "friend") {fc.cutLeft(fc.find(";") + 1); continue;} - if (cw == "typedef") {ce->typedefs << parseTypedef(fc.takeLeft(fc.find(";"))); typedefs << ce->typedefs.back(); typedefs.back().first.insert(0, cur_namespace); if (ce->typedefs.back().first.isEmpty()) ce->typedefs.pop_back(); fc.takeSymbol(); continue;} + if (cw == PIStringAscii("friend")) {fc.cutLeft(fc.find(';') + 1); continue;} + if (cw == PIStringAscii("typedef")) {ce->typedefs << parseTypedef(fc.takeLeft(fc.find(';'))); typedefs << ce->typedefs.back(); typedefs.back().first.insert(0, cur_namespace); if (ce->typedefs.back().first.isEmpty()) ce->typedefs.pop_back(); fc.takeSymbol(); continue;} if (cw == "template") { - fc.takeRange("<", ">"); + fc.takeRange('<', '>'); def = !isDeclaration(fc, 0, &end); fc.cutLeft(end); - if (def) fc.takeRange("{", "}"); + if (def) fc.takeRange('{', '}'); else fc.takeSymbol(); continue; } @@ -434,7 +434,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) { tmp = (cw + fc.takeLeft(end)).trim(); if (!tmp.isEmpty()) parseMember(ce, tmp); - if (def) fc.takeRange("{", "}"); + if (def) fc.takeRange('{', '}'); else fc.takeSymbol(); if (ps == fc.size_s()) {fc.cutLeft(1);} ps = fc.size_s(); @@ -448,13 +448,13 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) { PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) { PICodeParser::MetaMap ret; if (fc.isEmpty()) return ret; - PIStringList ml = fc.split(","); + PIStringList ml = fc.split(','); piForeachC (PIString & m, ml) { int i = m.find("="); if (i < 0) continue; PIString mv = m.mid(i + 1).trim(); - if (mv.startsWith("\"")) mv.cutLeft(1); - if (mv.endsWith("\"")) mv.cutRight(1); + if (mv.startsWith('\"')) mv.cutLeft(1); + if (mv.endsWith('\"')) mv.cutRight(1); ret[m.left(i).trim()] = mv; } //piCout << ms << ret; @@ -463,18 +463,18 @@ PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) { bool PICodeParser::parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta) { - //piCout << "enum" << name << fc; + //piCout << PIStringAscii("enum") << name << fc; Enum e(name); e.meta = meta; - PIStringList vl(fc.split(",")); + PIStringList vl(fc.split(',')); PIString vn; int cv = -1, ind = 0; piForeach (PIString & v, vl) { MetaMap meta; - int mi = v.find("$M"); + int mi = v.find(PIStringAscii("$M")); if (mi >= 0) { meta = tmp_meta.value(v.takeMid(mi, 5)); - v.replaceAll(" ", " "); + v.replaceAll(" ", ' '); } vn = v; ind = v.find("="); if (ind > 0) {cv = v.right(v.size_s() - ind - 1).toInt(); vn = v.left(ind);} @@ -492,15 +492,15 @@ bool PICodeParser::parseEnum(Entity * parent, const PIString & name, PIString fc PICodeParser::Typedef PICodeParser::parseTypedef(PIString fc) { //piCout << "parse typedef" << fc; Typedef td; - fc.replaceAll("\t", " "); + fc.replaceAll('\t', ' '); - if (fc.contains("(")) { - int start = fc.find("("), end = fc.find(")"); + if (fc.contains('(')) { + int start = fc.find('('), end = fc.find(')'); td.first = fc.takeMid(start + 1, end - start - 1).trim(); - if (td.first.left(1) == "*") {td.first.cutLeft(1).trim(); fc.insert(start + 1, "*");} + if (td.first.left(1) == PIChar('*')) {td.first.cutLeft(1).trim(); fc.insert(start + 1, '*');} td.second = fc.trim(); } else { - td.first = fc.takeMid(fc.findLast(" ")).trim(); + td.first = fc.takeMid(fc.findLast(' ')).trim(); td.second = fc.trim(); } //piCout << "found typedef" << td; @@ -513,30 +513,30 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) { if (fc.find("operator") >= 0) return true; tmp_temp.clear(); //piCout << "parse member" << fc; - int ts = fc.find("<"), te = 0; + int ts = fc.find('<'), te = 0; PIString ctemp, crepl; while (ts >= 0) { - ctemp = fc.mid(ts).takeRange("<", ">"); - if (ctemp.isEmpty()) {te = ts + 1; ts = fc.find("<", te); continue;} - crepl = "$T" + PIString::fromNumber(tmp_temp.size_s()).expandLeftTo(3, "0"); + ctemp = fc.mid(ts).takeRange('<', '>'); + if (ctemp.isEmpty()) {te = ts + 1; ts = fc.find('<', te); continue;} + crepl = PIStringAscii("$T") + PIString::fromNumber(tmp_temp.size_s()).expandLeftTo(3, '0'); fc.replace(ts, ctemp.size_s() + 2, crepl); - tmp_temp[crepl] = "<" + ctemp + ">"; - ts = fc.find("<", te); + tmp_temp[crepl] = '<' + ctemp + '>'; + ts = fc.find('<', te); } - fc.replaceAll("\n", " ").replaceAll("\t", " ").replaceAll(" ", " ").replaceAll(", ", ",").replaceAll(" (", "(").replaceAll(" $M", "$M"); + fc.replaceAll('\n', ' ').replaceAll('\t', ' ').replaceAll(" ", ' ').replaceAll(", ", ',').replaceAll(PIStringAscii(" ("), '(').replaceAll(PIStringAscii(" $M"), PIStringAscii("$M")); //piCout << "parse member" << fc; PIStringList tl, al; Member me; //piCout << fc; - if (fc.contains("(")) { + if (fc.contains('(')) { MetaMap meta; - int ind = fc.find("$M"); + int ind = fc.find(PIStringAscii("$M")); if (ind >= 0) { meta = tmp_meta.value(fc.takeMid(ind, 5)); - fc.replaceAll(" ", " ").replaceAll(" (", "("); + fc.replaceAll(PIStringAscii(" "), ' ').replaceAll(PIStringAscii(" ("), '('); } - fc.cutRight(fc.size_s() - fc.findLast(")") - 1); - te = fc.find("("); + fc.cutRight(fc.size_s() - fc.findLast(')') - 1); + te = fc.find('('); //piCout << fc; for (ts = te - 1; ts >= 0; --ts) if (!_isCChar(fc[ts]) && !(fc[ts].isDigit())) break; @@ -544,20 +544,20 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) { me.meta = meta; me.name = fc.takeMid(ts + 1, te - ts - 1); if (me.name == parent->name) return true; - me.arguments_full = fc.takeMid(ts + 2).cutRight(1).split(","); + me.arguments_full = fc.takeMid(ts + 2).cutRight(1).split(','); me.type = fc.cutRight(1).trim(); me.visibility = cur_def_vis; - if (me.type.find("inline ") >= 0) { + if (me.type.find(PIStringAscii("inline ")) >= 0) { me.attributes |= Inline; - me.type.removeAll("inline "); + me.type.removeAll(PIStringAscii("inline ")); } - if (me.type.find("static ") >= 0) { + if (me.type.find(PIStringAscii("static ")) >= 0) { me.attributes |= Static; - me.type.removeAll("static "); + me.type.removeAll(PIStringAscii("static ")); } - if (me.type.find("virtual ") >= 0) { + if (me.type.find(PIStringAscii("virtual ")) >= 0) { me.attributes |= Virtual; - me.type.removeAll("virtual "); + me.type.removeAll(PIStringAscii("virtual ")); } normalizeEntityNamespace(me.type); int i = 0; @@ -566,15 +566,15 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) { if ((i = a.find("=")) > 0) a.cutRight(a.size_s() - i).trim(); for (int j = 0; j < me.arguments_full.size_s(); ++j) - if (me.arguments_full[j] == "void") { + if (me.arguments_full[j] == PIStringAscii("void")) { me.arguments_full.remove(j); --j; } me.arguments_type = me.arguments_full; piForeach (PIString & a, me.arguments_type) { crepl.clear(); - if (a.contains("[")) - crepl = a.takeMid(a.find("["), a.findLast("]") - a.find("[") + 1); + if (a.contains('[')) + crepl = a.takeMid(a.find('['), a.findLast(']') - a.find('[') + 1); for (ts = a.size_s() - 1; ts >= 0; --ts) if (!_isCChar(a[ts]) && !(a[ts].isDigit())) break; a.cutRight(a.size_s() - ts - 1); @@ -586,18 +586,18 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) { //piCout << "func" << me.type << me.name << me.arguments_full << me.arguments_type; parent->functions << me; } else { - if (fc.endsWith(";")) fc.cutRight(1); - if (fc.startsWith("using") || !(fc.contains(' ') || fc.contains('\t') || fc.contains('\n'))) return true; + if (fc.endsWith(';')) fc.cutRight(1); + if (fc.startsWith(PIStringAscii("using")) || !(fc.contains(' ') || fc.contains('\t') || fc.contains('\n'))) return true; int bits = extractMemberBits(fc); - tl = fc.split(","); + tl = fc.split(','); //piCout << "member" << fc << tl; //piCout << "member after eb" << fc << ", bits =" << bits; if (tl.isEmpty()) return true; bool vn = true; ctemp = tl.front().trim(); PIString meta_t; - if (ctemp.contains("$M")) - meta_t = ctemp.takeMid(ctemp.find("$M")); + if (ctemp.contains(PIStringAscii("$M"))) + meta_t = ctemp.takeMid(ctemp.find(PIStringAscii("$M"))); for (ts = ctemp.size_s() - 1; ts > 0; --ts) { if (vn) {if (!_isCChar(ctemp[ts]) && !ctemp[ts].isDigit() && ctemp[ts] != '[' && ctemp[ts] != ']') vn = false;} else {if (_isCChar(ctemp[ts]) || ctemp[ts].isDigit()) break;} @@ -606,26 +606,26 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) { me.visibility = cur_def_vis; ctemp += meta_t; restoreTmpTemp(&me); - PIString type = " " + me.type; - if (type.find(" const ") >= 0) { + PIString type = PIStringAscii(" ") + me.type; + if (type.find(PIStringAscii(" const ")) >= 0) { me.attributes |= Const; - type.replaceAll(" const ", " "); + type.replaceAll(PIStringAscii(" const "), ' '); } - if (type.find(" static ") >= 0) { + if (type.find(PIStringAscii(" static ")) >= 0) { me.attributes |= Static; - type.replaceAll(" static ", " "); + type.replaceAll(PIStringAscii(" static "), ' '); } - if (type.find(" mutable ") >= 0) { + if (type.find(PIStringAscii(" mutable ")) >= 0) { me.attributes |= Mutable; - type.replaceAll(" mutable ", " "); + type.replaceAll(PIStringAscii(" mutable "), ' '); } - if (type.find(" volatile ") >= 0) { + if (type.find(PIStringAscii(" volatile ")) >= 0) { me.attributes |= Volatile; - type.replaceAll(" volatile ", " "); + type.replaceAll(PIStringAscii(" volatile "), ' '); } - if (type.find(" extern ") >= 0) { + if (type.find(PIStringAscii(" extern ")) >= 0) { me.attributes |= Extern; - type.replaceAll(" extern ", " "); + type.replaceAll(PIStringAscii(" extern "), ' '); } type.trim(); normalizeEntityNamespace(type); @@ -637,15 +637,15 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) { me.type = type; restoreTmpMeta(&me); if (me.name.isEmpty()) continue; - if (me.name.contains("[")) - crepl = me.name.takeMid(me.name.find("["), me.name.findLast("]") - me.name.find("[") + 1); + if (me.name.contains('[')) + crepl = me.name.takeMid(me.name.find('['), me.name.findLast(']') - me.name.find('[') + 1); while (!me.name.isEmpty()) { - if (me.name.front() == "*" || me.name.front() == "&") { + if (me.name.front() == PIChar('*') || me.name.front() == PIChar('&')) { me.type += me.name.takeLeft(1); me.name.trim(); } else break; } - me.is_type_ptr = (me.type.right(1) == "]" || me.type.right(1) == "*"); + me.is_type_ptr = (me.type.right(1) == PIChar(']') || me.type.right(1) == PIChar('*')); me.type += crepl; me.bits = bits; while (!crepl.isEmpty()) { @@ -664,7 +664,7 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) { int PICodeParser::extractMemberBits(PIString & fc) { - int i = fc.findLast(":"); + int i = fc.findLast(':'); if (i <= 0) return -1; if (fc[i - 1].toAscii() == ':') return -1; PIString bs = fc.takeMid(i).mid(1).trim(); @@ -681,11 +681,11 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) { n.cutRight(suff.size_s()); break; } - n.push_front(" "); - if (n.find(" static ") >= 0) {n.replaceAll(" static ", ""); pref += "static ";} - if (n.find(" const ") >= 0) {n.replaceAll(" const ", ""); pref += "const ";} - if (n.find(" mutable ") >= 0) {n.replaceAll(" mutable ", ""); pref += "mutable ";} - if (n.find(" volatile ") >= 0) {n.replaceAll(" volatile ", ""); pref += "volatile ";} + n.push_front(' '); + if (n.find(PIStringAscii(" static ")) >= 0) {n.replaceAll(PIStringAscii(" static "), ""); pref += PIStringAscii("static ");} + if (n.find(PIStringAscii(" const ")) >= 0) {n.replaceAll(PIStringAscii(" const "), ""); pref += PIStringAscii("const ");} + if (n.find(PIStringAscii(" mutable ")) >= 0) {n.replaceAll(PIStringAscii(" mutable "), ""); pref += PIStringAscii("mutable ");} + if (n.find(PIStringAscii(" volatile ")) >= 0) {n.replaceAll(PIStringAscii(" volatile "), ""); pref += PIStringAscii("volatile ");} n.trim(); int f = 0; piForeachC (Entity * e, entities) { @@ -694,7 +694,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) { return; } if ((f = e->name.find(n)) >= 0) - if (e->name.mid(f - 1, 1) == ":") + if (e->name.mid(f - 1, 1) == PIChar(':')) if (e->name.find(cur_namespace) >= 0) { n = pref + e->name + suff; return; @@ -702,7 +702,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) { } piForeachC (Enum & e, enums) if ((f = e.name.find(n)) >= 0) - if (e.name.mid(f - 1, 1) == ":") + if (e.name.mid(f - 1, 1) == PIChar(':')) if (e.name.find(cur_namespace) >= 0) { //piCout << "change" << n << "to" << e.name + suff; n = pref + e.name + suff; @@ -710,7 +710,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) { } piForeachC (Typedef & e, typedefs) if ((f = e.first.find(n)) >= 0) - if (e.first.mid(f - 1, 1) == ":") + if (e.first.mid(f - 1, 1) == PIChar(':')) if (e.first.find(cur_namespace) >= 0) { //piCout << "change" << n << "to" << e.name + suff; n = pref + e.first + suff; @@ -723,20 +723,20 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) { void PICodeParser::restoreTmpTemp(Member * e) { int i = 0; piForeach (PIString & a, e->arguments_full) { - while ((i = a.find("$T")) >= 0) + while ((i = a.find(PIStringAscii("$T"))) >= 0) a.replace(i, 5, tmp_temp[a.mid(i, 5)]); } piForeach (PIString & a, e->arguments_type) { - while ((i = a.find("$T")) >= 0) + while ((i = a.find(PIStringAscii("$T"))) >= 0) a.replace(i, 5, tmp_temp[a.mid(i, 5)]); } - while ((i = e->type.find("$T")) >= 0) + while ((i = e->type.find(PIStringAscii("$T"))) >= 0) e->type.replace(i, 5, tmp_temp[e->type.mid(i, 5)]); } void PICodeParser::restoreTmpMeta(PICodeParser::Member * e) { - int i = e->name.find("$M"); + int i = e->name.find(PIStringAscii("$M")); if (i < 0) return; e->meta = tmp_meta[e->name.takeMid(i, 5)]; } @@ -744,7 +744,7 @@ void PICodeParser::restoreTmpMeta(PICodeParser::Member * e) { PICodeParser::MetaMap PICodeParser::maybeMeta(PIString & fc) { PICodeParser::MetaMap ret; - if (fc.left(2) == "$M") { + if (fc.left(2) == PIStringAscii("$M")) { ret = tmp_meta.value(fc.takeLeft(5)); fc.trim(); } @@ -754,10 +754,10 @@ PICodeParser::MetaMap PICodeParser::maybeMeta(PIString & fc) { bool PICodeParser::macroCondition(const PIString & mif, PIString mifcond) { //piCout << "macroCondition" << mif << mifcond; - if (mif == "ifdef") return isDefineExists(mifcond); - if (mif == "ifndef") return !isDefineExists(mifcond); - if (mif == "if" || mif == "elif") { - mifcond.removeAll(" ").removeAll("\t"); + if (mif == PIStringAscii("ifdef")) return isDefineExists(mifcond); + if (mif == PIStringAscii("ifndef")) return !isDefineExists(mifcond); + if (mif == PIStringAscii("if") || mif == PIStringAscii("elif")) { + mifcond.removeAll(' ').removeAll('\t'); return procMacrosCond(mifcond) > 0.; } return false; @@ -770,7 +770,7 @@ double PICodeParser::procMacrosCond(PIString fc) { int oper = 0, ps = -1; char cc, nc; PIString ce; - fc.removeAll("defined"); + fc.removeAll(PIStringAscii("defined")); //piCout << "procMacrosCond" << fc; while (!fc.isEmpty()) { cc = fc[0].toAscii(); @@ -825,17 +825,17 @@ double PICodeParser::defineValue(const PIString & dn) { void PICodeParser::replaceMeta(PIString & dn) { tmp_meta.clear(); if (dn.isEmpty()) return; - int s = dn.find("PIMETA"); + int s = dn.find(PIStringAscii("PIMETA")); while (s >= 0) { int ms = 0, ml = 0; ms = dn.findRange('(', ')', '\\', s + 6, &ml); if (ms < 0) return; PIString meta = dn.mid(ms, ml).trim(); - PIString rm = "$M" + PIString::fromNumber(tmp_meta.size_s()).expandLeftTo(3, "0"); + PIString rm = PIStringAscii("$M") + PIString::fromNumber(tmp_meta.size_s()).expandLeftTo(3, '0'); dn.replace(s, ms + ml + 1 - s, rm); - //piCout << "FOUND META \"" << meta << "\""; + //piCout << "FOUND META \"" << meta << '\"'; tmp_meta[rm] = parseMeta(meta); - s = dn.find("PIMETA"); + s = dn.find(PIStringAscii("PIMETA")); } } @@ -849,7 +849,7 @@ PICodeParser::Entity * PICodeParser::findEntityByName(const PIString & en) { bool PICodeParser::isDeclaration(const PIString & fc, int start, int * end) { - int dind = fc.find("{", start), find = fc.find(";", start); + int dind = fc.find('{', start), find = fc.find(';', start); //piCout << "isDeclaration" << dind << find << fc.left(10); if (dind < 0 && find < 0) {if (end) *end = -1; return true;} if (dind < 0 || find < dind) {if (end) *end = find; return true;} @@ -866,11 +866,11 @@ bool PICodeParser::isMainFile(const PIString & fc) { if (csi < 0) csi = fc.find("\nmain", si); if (csi < 0) return false; si = csi; - int fi = fc.find("(", si + 5); + int fi = fc.find('(', si + 5); if (fi < 0) return false; if (fi - si < 10) { PIString ms(fc.mid(si, fi - si + 1)); - ms.removeAll(" ").removeAll("\t").removeAll("\n"); + ms.removeAll(' ').removeAll('\t').removeAll('\n'); if (ms == "main(") return true; } si += 5; @@ -885,17 +885,17 @@ PIString PICodeParser::procMacros(PIString fc) { bool grab = false, skip = false, cond_ok = false; PIString pfc, nfc, line, mif, mifcond; //piCout << "procMacros\n<******" << fc << "\n******>"; - fc += "\n"; + fc += '\n'; while (!fc.isEmpty()) { line = fc.takeLine().trimmed(); - if (line.left(1) == "#") { + if (line.left(1) == PIChar('#')) { mifcond = line.mid(1); mif = mifcond.takeCWord(); //piCout << mif; //piCout << "mif mifcond" << mif << mifcond << ifcnt; if (skip || grab) { - if (mif.left(2) == "if") ifcnt++; - if (mif.left(5) == "endif") { + if (mif.left(2) == PIStringAscii("if")) ifcnt++; + if (mif.left(5) == PIStringAscii("endif")) { if (ifcnt > 0) ifcnt--; else { //piCout << "main endif" << skip << grab; @@ -904,7 +904,7 @@ PIString PICodeParser::procMacros(PIString fc) { continue; } } - if (mif.left(4) == "elif" && ifcnt == 0) { + if (mif.left(4) == PIStringAscii("elif") && ifcnt == 0) { //piCout << "main elif" << skip << grab << cond_ok; if (cond_ok) { if (grab) { @@ -929,10 +929,10 @@ PIString PICodeParser::procMacros(PIString fc) { else {skip = true; grab = false;} continue; } - if (grab) nfc << line << "\n"; + if (grab) nfc << line << '\n'; continue; } - if (mif.left(2) == "if") { + if (mif.left(2) == PIStringAscii("if")) { //piCout << "main if"; skip = grab = cond_ok = false; if (macroCondition(mif, mifcond.trimmed())) grab = cond_ok = true; @@ -944,8 +944,8 @@ PIString PICodeParser::procMacros(PIString fc) { //return false; /// WARNING: now skip errors } } else { - if (grab) nfc << line << "\n"; - else if (!skip) pfc << line << "\n"; + if (grab) nfc << line << '\n'; + else if (!skip) pfc << line << '\n'; } } return pfc; @@ -957,20 +957,20 @@ bool PICodeParser::parseDirective(PIString d) { PIString dname = d.takeCWord(); //piCout << "parseDirective" << d; if (dname == "include") { - d.replaceAll("<", "\"").replaceAll(">", "\""); - PIString cf = cur_file, ifc = d.takeRange("\"", "\""); + d.replaceAll('<', '\"').replaceAll('>', '\"'); + PIString cf = cur_file, ifc = d.takeRange('\"', '\"'); if (with_includes) { bool ret = parseFileInternal(ifc, with_includes); cur_file = cf; return ret; } } - if (dname == "define") { + if (dname == PIStringAscii("define")) { PIString mname = d.takeCWord(); //piCout << mname; - if (mname == "PIMETA") return true; - if (d.left(1) == "(") { // macro - PIStringList args = d.takeRange("(", ")").split(",").trim(); + if (mname == PIStringAscii("PIMETA")) return true; + if (d.left(1) == PIChar('(')) { // macro + PIStringList args = d.takeRange('(', ')').split(',').trim(); macros << Macro(mname, d.trim(), args); } else { // define d.trim(); diff --git a/lib/main/core/pistring.cpp b/lib/main/core/pistring.cpp index 4cd27fab..508fd126 100644 --- a/lib/main/core/pistring.cpp +++ b/lib/main/core/pistring.cpp @@ -173,7 +173,7 @@ PIString PIString::dtos(const double num, char format, int precision) { PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) { - if (value == 0LL) return PIString("0"); + if (value == 0LL) return PIString('0'); if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();} if (ok != 0) *ok = true; if (base == 10) return lltos(value); @@ -192,7 +192,7 @@ PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) { } PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) { - if (value == 0ULL) return PIString("0"); + if (value == 0ULL) return PIString('0'); if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();} if (ok != 0) *ok = true; if (base == 10) return ulltos(value); @@ -211,9 +211,10 @@ PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) { llong PIString::toNumberBase(const PIString & value, int base, bool * ok) { + static const PIString s_0x = PIStringAscii("0x"); PIString v = value.trimmed(); if (base < 0) { - int ind = v.find("0x"); + int ind = v.find(s_0x); if (ind == 0 || ind == 1) {v.remove(ind, 2); base = 16;} else base = 10; } else @@ -254,6 +255,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { int sz = ucnv_toUChars(cc, ucs, s, c, s, &e); //printf("appendFromChars %d -> %d\n", s, sz); //printf("PIString %d -> %d\n", c[0], ucs[0]); + reserve(size_s() + sz); for (int i = 0; i < sz; ++i) push_back(PIChar(ucs[i])); delete[] ucs; @@ -264,11 +266,9 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { # ifdef WINDOWS sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0); if (sz <= 0) return; - wchar_t * buffer = new wchar_t[sz]; - MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, buffer, sz); - for (int i = 0; i < sz; ++i) - push_back(PIChar((ushort)buffer[i])); - delete[] buffer; + int old_sz = size_s(); + enlarge(sz); + MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)PIDeque::data(old_sz), sz); return; //printf("request %d\n", sz); # else @@ -330,9 +330,14 @@ PIString PIString::fromAscii(const char * s) { PIString ret; int l = 0; while (s[l] != '\0') { - ret.push_back(PIChar(short(s[l]))); + ret.push_back(PIChar(s[l])); ++l; } + /*while (s[l] != '\0') ++l; + PIString ret; + ret.resize(l); + for (int i = 0; i < l; ++i) + ret[i] = s[i];*/ return ret; } @@ -369,6 +374,7 @@ void PIString::buildData(const char * cp) const { UConverter * cc = ucnv_open(cp, &e); if (cc) { char uc[8]; + data_.reserve(size_s()); for (int i = 0; i < size_s(); ++i) { if (at(i).isAscii()) data_.push_back(uchar(at(i).unicode16Code())); @@ -605,16 +611,18 @@ PIString PIString::trimmed() const { PIString & PIString::replace(int from, int count, const PIString & with) { - if (count < length() - from) remove(from, count); - else remove(from, length() - from); - uint c = with.length(); - for (uint i = 0; i < c; ++i) insert(from + i, with[i]); + count = piMini(count, length() - from); + if (count == with.size_s()) + memcpy(&(at(from)), &(with.at(0)), count * sizeof(PIChar)); + else { + remove(from, count); + PIDeque::insert(from, with); + } return *this; } PIString & PIString::replace(const PIString & what, const PIString & with, bool * ok) { - //piCout << "replace" << what << with; if (what.isEmpty()) { if (ok != 0) *ok = false; return *this; @@ -628,8 +636,53 @@ PIString & PIString::replace(const PIString & what, const PIString & with, bool PIString & PIString::replaceAll(const PIString & what, const PIString & with) { if (what.isEmpty() || what == with) return *this; - bool ok = true; - while (ok) replace(what, with, &ok); + if (with.isEmpty()) removeAll(what); + else { + int l = what.length(), dl = with.length() - what.length(); + for (int i = 0; i < length() - l + 1; ++i) { + bool match = true; + for (int j = 0; j < l; ++j) { + if (at(j + i) != what[j]) { + match = false; + break; + } + } + if (!match) continue; + if (dl > 0) PIDeque::insert(i, PIDeque((size_t)dl)); + if (dl < 0) PIDeque::remove(i, -dl); + memcpy(PIDeque::data(i), &(with.at(0)), with.length() * sizeof(PIChar)); + //i -= l; + } + } + return *this; +} + + +PIString & PIString::replaceAll(const char what, const char with) { + int l = length(); + for (int i = 0; i < l; ++i) { + if (at(i) == what) + at(i) = with; + } + return *this; +} + + +PIString & PIString::removeAll(const PIString & str) { + if (str.isEmpty()) return *this; + int l = str.length(); + for (int i = 0; i < length() - l + 1; ++i) { + bool match = true; + for (int j = 0; j < l; ++j) { + if (at(j + i) != str[j]) { + match = false; + break; + } + } + if (!match) continue; + PIDeque::remove(i, l); + i -= l; + } return *this; } @@ -641,16 +694,17 @@ PIString & PIString::insert(int index, const PIString & str) { PIString & PIString::elide(int size, float pos) { + static const PIString s_dotdot = PIStringAscii(".."); if (length() <= size) return *this; if (length() <= 2) { - fill("."); + fill('.'); return *this; } pos = piClampf(pos, 0.f, 1.f); int ns = size - 2; int ls = piRoundf(ns * pos); remove(ls, length() - ns); - insert(ls, ".."); + insert(ls, s_dotdot); return *this; } @@ -670,9 +724,9 @@ PIStringList PIString::split(const PIString & delim) const { } -int PIString::find(const char str, const int start) const { +int PIString::find(const char c, const int start) const { for (int i = start; i < length(); ++i) - if (at(i) == str) + if (at(i) == c) return i; return -1; } @@ -687,9 +741,9 @@ int PIString::find(const PIString & str, const int start) const { } -int PIString::findLast(const char str, const int start) const { +int PIString::findLast(const char c, const int start) const { for (int i = length() - 1; i >= start; --i) - if (at(i) == str) + if (at(i) == c) return i; return -1; } @@ -730,7 +784,7 @@ int PIString::findCWord(const PIString & word, const int start) const { } -int PIString::findRange(const PIChar & start, const PIChar & end, const PIChar & shield, const int start_index, int * len) const { +int PIString::findRange(const PIChar start, const PIChar end, const PIChar shield, const int start_index, int * len) const { if (len) *len = 0; bool trim_ = (start != ' ' && start != '\t' && start != '\n' && start != '\r'), eq = (start == end); int sz = size_s(), ls = -1, le = -1, cnt = 0; @@ -783,7 +837,7 @@ int PIString::findAnyLast(const PIString & str, const int start) const { } -int PIString::entries(const PIChar & c) const { +int PIString::entries(const PIChar c) const { int sz = size_s(), ret = 0; for (int i = 0; i < sz; ++i) if (at(i) == c) ++ret; @@ -804,9 +858,14 @@ bool PIString::endsWith(const PIString & str) const { bool PIString::toBool() const { + static const PIString s_true = PIStringAscii("true"); + static const PIString s_yes = PIStringAscii("yes" ); + static const PIString s_on = PIStringAscii("on" ); + static const PIString s_ok = PIStringAscii("ok" ); PIString s(*this); s = s.trimmed().toLowerCase(); - if ( atof(s.toNativeDecimalPoints().data()) > 0. || s == "true" || s == "yes" || s == "on" || s == "ok") return true; + if (s == s_true || s == s_yes || s == s_on || s == s_ok) return true; + if (atof(s.toNativeDecimalPoints().data()) > 0.) return true; return false; } @@ -953,7 +1012,7 @@ PIString PIString::takeNumber() { } -PIString PIString::takeRange(const PIChar & start, const PIChar & end, const PIChar & shield) { +PIString PIString::takeRange(const PIChar start, const PIChar end, const PIChar shield) { PIString ret; bool trim_ = (start != ' ' && start != '\t' && start != '\n' && start != '\r'), eq = (start == end); int sz = size_s(), ls = -1, le = -1, cnt = 0; @@ -991,7 +1050,7 @@ PIString PIString::takeRange(const PIChar & start, const PIChar & end, const PIC } -PIString PIString::inBrackets(const PIChar &start, const PIChar &end) const { +PIString PIString::inBrackets(const PIChar start, const PIChar end) const { int slen = length(); int st = -1, bcnt = 0; PIChar cc; @@ -1030,9 +1089,9 @@ PIString PIString::toNativeDecimalPoints() const { #ifdef HAS_LOCALE PIString s(*this); if (currentLocale == 0) return s; - return s.replaceAll(".", currentLocale->decimal_point).replaceAll(",", currentLocale->decimal_point); + return s.replaceAll('.', currentLocale->decimal_point).replaceAll(',', currentLocale->decimal_point); #else - return PIString(*this).replaceAll(",", "."); + return PIString(*this).replaceAll(',', '.'); #endif } @@ -1062,27 +1121,27 @@ ldouble PIString::toLDouble() const { PIString & PIString::setReadableSize(llong bytes) { clear(); - if (bytes < 1024) {*this += (PIString::fromNumber(bytes) + " B"); return *this;} + if (bytes < 1024) {*this += (PIString::fromNumber(bytes) + PIStringAscii(" B")); return *this;} double fres = bytes / 1024.; llong res = bytes / 1024; fres -= res; - if (res < 1024) {*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " kB"); return *this;} + if (res < 1024) {*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" kB")); return *this;} fres = res / 1024.; res /= 1024; fres -= res; - if (res < 1024) {*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " MB"); return *this;} + if (res < 1024) {*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" MB")); return *this;} fres = res / 1024.; res /= 1024; fres -= res; - if (res < 1024) {*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " GB"); return *this;} + if (res < 1024) {*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" GB")); return *this;} fres = res / 1024.; res /= 1024; fres -= res; - if (res < 1024) {*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " TB"); return *this;} + if (res < 1024) {*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" TB")); return *this;} fres = res / 1024.; res /= 1024; fres -= res; - *this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " PB"); + *this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" PB")); return *this; } @@ -1110,14 +1169,14 @@ void parseVersion(PIString s, PIVector & codes, PIStringList & strs) { } int mccnt = 2 - s.entries('.'); if (mccnt > 0) { - int ind = s.findLast(".") + 1; + int ind = s.findLast('.') + 1; while (!_versionDelims_.contains(s[ind])) { ++ind; if (ind > s.size_s() - 1) break; } for (int i = 0; i < mccnt; ++i) - s.insert(ind, ".0"); + s.insert(ind, PIStringAscii(".0")); } PIStringList comps; while (!s.isEmpty()) { @@ -1132,7 +1191,7 @@ void parseVersion(PIString s, PIVector & codes, PIStringList & strs) { } for (int i = 0; i < comps.size_s(); ++i) { if (comps[i].isEmpty()) - comps[i] = "0"; + comps[i] = '0'; bool ok = false; int val = comps[i].toInt(-1, &ok); if (ok) { @@ -1148,20 +1207,20 @@ void parseVersion(PIString s, PIVector & codes, PIStringList & strs) { int versionLabelValue(PIString s) { int ret = -10000; if (s.isEmpty()) return 0; - if (s.startsWith("pre")) { + if (s.startsWith(PIStringAscii("pre"))) { s.cutLeft(3); ret -= 1; } - if (s.startsWith("rc")) { + if (s.startsWith(PIStringAscii("rc"))) { s.cutLeft(2); ret += s.toInt(); } - if (s.startsWith("r")) { + if (s.startsWith(PIStringAscii("r"))) { s.cutLeft(1); ret += 10000 + s.toInt(); } - if (s == "alpha") ret -= 4; - if (s == "beta" ) ret -= 2; + if (s == PIStringAscii("alpha")) ret -= 4; + if (s == PIStringAscii("beta" )) ret -= 2; return ret; } @@ -1200,13 +1259,13 @@ PIString versionNormalize(const PIString & v) { PIString ret; for (int i = 0; i < codes.size_s(); ++i) { if (i > 0) { - if (i < 3) ret += "."; - else ret += "-"; + if (i < 3) ret += '.'; + else ret += '-'; } ret += PIString::fromNumber(codes[i]); } for (int i = 0; i < strs.size_s(); ++i) { - ret += "_"; + ret += '_'; ret += strs[i]; } return ret; diff --git a/lib/main/core/pistring.h b/lib/main/core/pistring.h index 0fb7bedd..e73d73bf 100644 --- a/lib/main/core/pistring.h +++ b/lib/main/core/pistring.h @@ -43,7 +43,8 @@ public: static const float ElideCenter; static const float ElideRight ; - PIString & operator +=(const PIChar & c) {push_back(c); return *this;} + PIString & operator +=(const PIChar c) {push_back(c); return *this;} + PIString & operator +=(const char c) {push_back(PIChar(c)); return *this;} PIString & operator +=(const char * str); PIString & operator +=(const wchar_t * str); PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;} @@ -55,7 +56,7 @@ public: //! Contructs string with single symbol "c" - PIString(const PIChar & c): PIDeque() {*this += c;} + PIString(const PIChar c): PIDeque() {*this += c;} PIString(const char c): PIDeque() {*this += PIChar(c);} /*! \brief Contructs string from c-string "str" @@ -84,7 +85,7 @@ public: /*! \brief Contructs string as sequence of symbols "c" of buffer with length "len" * \details Example: \snippet pistring.cpp PIString(int, PIChar) */ - PIString(const int len, const PIChar & c): PIDeque() {for (int i = 0; i < len; ++i) push_back(c);} + PIString(const int len, const PIChar c): PIDeque() {for (int i = 0; i < len; ++i) push_back(c);} ~PIString() {} @@ -110,7 +111,7 @@ public: bool operator ==(const PIString & str) const; //! Compare operator - bool operator ==(const PIChar c) const {return *this == PIString(c);} + bool operator ==(const PIChar c) const {if (size_s() != 1) return false; return at(0) == c;} //! Compare operator bool operator ==(const char * str) const {return *this == PIString(str);} @@ -119,7 +120,7 @@ public: bool operator !=(const PIString & str) const; //! Compare operator - bool operator !=(const PIChar c) const {return *this != PIString(c);} + bool operator !=(const PIChar c) const {if (size_s() != 1) return true; return at(0) != c;} //! Compare operator bool operator !=(const char * str) const {return *this != PIString(str);} @@ -128,7 +129,7 @@ public: bool operator <(const PIString & str) const; //! Compare operator - bool operator <(const PIChar c) const {return *this < PIString(c);} + bool operator <(const PIChar c) const {if (size_s() != 1) return size_s() < 1; return at(0) < c;} //! Compare operator bool operator <(const char * str) const {return *this < PIString(str);} @@ -137,7 +138,7 @@ public: bool operator >(const PIString & str) const; //! Compare operator - bool operator >(const PIChar c) const {return *this > PIString(c);} + bool operator >(const PIChar c) const {if (size_s() != 1) return size_s() > 1; return at(0) > c;} //! Compare operator bool operator >(const char * str) const {return *this > PIString(str);} @@ -146,7 +147,7 @@ public: bool operator <=(const PIString & str) const {return !(*this > str);} //! Compare operator - bool operator <=(const PIChar c) const {return *this <= PIString(c);} + bool operator <=(const PIChar c) const {return !(*this > c);} //! Compare operator bool operator <=(const char * str) const {return *this <= PIString(str);} @@ -155,7 +156,7 @@ public: bool operator >=(const PIString & str) const {return !(*this < str);} //! Compare operator - bool operator >=(const PIChar c) const {return *this >= PIString(c);} + bool operator >=(const PIChar c) const {return !(*this < c);} //! Compare operator bool operator >=(const char * str) const {return *this >= PIString(str);} @@ -166,7 +167,11 @@ public: /*! \brief Append symbol "c" at the end of string * \details Example: \snippet pistring.cpp PIString::<<(PIChar) */ - PIString & operator <<(const PIChar & c) {*this += c; return *this;} + PIString & operator <<(const PIChar c) {*this += c; return *this;} + + /*! \brief Append symbol "c" at the end of string + * \details Example: \snippet pistring.cpp PIString::<<(PIChar) */ + PIString & operator <<(const char c) {*this += PIChar(c); return *this;} /*! \brief Append c-string "str" at the end of string * \details Example: \snippet pistring.cpp PIString::<<(char * ) */ @@ -181,11 +186,6 @@ public: PIString & operator <<(const int & num) {*this += PIString::fromNumber(num); return *this;} PIString & operator <<(const uint & num) {*this += PIString::fromNumber(num); return *this;} - /*! \brief Append string representation of "num" at the end of string - * \details Example: \snippet pistring.cpp PIString::<<(int) */ - PIString & operator <<(const short & num) {*this += PIString::fromNumber(num); return *this;} - PIString & operator <<(const ushort & num) {*this += PIString::fromNumber(num); return *this;} - /*! \brief Append string representation of "num" at the end of string * \details Example: \snippet pistring.cpp PIString::<<(int) */ PIString & operator <<(const long & num) {*this += PIString::fromNumber(num); return *this;} @@ -282,8 +282,20 @@ public: * \details Example: \snippet pistring.cpp PIString::replaceAll * \sa \a replace(), \a replaced() */ PIString & replaceAll(const PIString & what, const PIString & with); - PIString replaceAll(const PIString & what, const PIString & with) const {PIString str(*this); str.replaceAll(what, with); return str;} - + + /*! \brief Replace all founded symbols "what" with symbol "with" and return this string + * \details Example: \snippet pistring.cpp PIString::replaceAll + * \sa \a replace(), \a replaced() */ + PIString & replaceAll(const char what, const char with); + + PIString replacedAll(const PIString & what, const PIString & with) const {PIString str(*this); str.replaceAll(what, with); return str;} + + PIString replacedAll(const char what, const char with) const {PIString str(*this); str.replaceAll(what, with); return str;} + + PIString & removeAll(const PIString & str); + + PIString & removeAll(char c) {PIDeque::removeAll(PIChar(c)); return *this;} + /*! \brief Repeat content of string "times" times and return this string * \details Example: \snippet pistring.cpp PIString::repeat */ PIString & repeat(int times) {PIString ss(*this); times--; piForTimes (times) *this += ss; return *this;} @@ -294,11 +306,11 @@ public: /*! \brief Insert symbol "c" after index "index" and return this string * \details Example: \snippet pistring.cpp PIString::insert_0 */ - PIString & insert(const int index, const PIChar & c) {PIDeque::insert(index, c); return *this;} + PIString & insert(const int index, const PIChar c) {PIDeque::insert(index, c); return *this;} /*! \brief Insert symbol "c" after index "index" and return this string * \details Example: \snippet pistring.cpp PIString::insert_1 */ - PIString & insert(const int index, const char & c) {return insert(index, PIChar(c));} + PIString & insert(const int index, const char c) {return insert(index, PIChar(c));} /*! \brief Insert string "str" after index "index" and return this string * \details Example: \snippet pistring.cpp PIString::insert_2 */ @@ -312,13 +324,13 @@ public: * "c" at the end of string, and return this string * \details Example: \snippet pistring.cpp PIString::expandRightTo * \sa \a expandLeftTo() */ - PIString & expandRightTo(const int len, const PIChar & c) {if (len > length()) resize(len, c); return *this;} + PIString & expandRightTo(const int len, const PIChar c) {if (len > length()) resize(len, c); return *this;} /*! \brief Enlarge string to length "len" by addition sequence of symbols * "c" at the beginning of string, and return this string * \details Example: \snippet pistring.cpp PIString::expandLeftTo * \sa \a expandRightTo() */ - PIString & expandLeftTo(const int len, const PIChar & c) {if (len > length()) insert(0, PIString(len - length(), c)); return *this;} + PIString & expandLeftTo(const int len, const PIChar c) {if (len > length()) insert(0, PIString(len - length(), c)); return *this;} /*! \brief Add "c" symbols at the beginning and end of the string, and return this string * \sa \a quoted() */ @@ -331,7 +343,7 @@ public: /*! \brief Reverse string and return this string * \details Example: \snippet pistring.cpp PIString::reverse * \sa \a reversed() */ - PIString & reverse() {PIString str(*this); clear(); piForeachR (const PIChar & c, str) push_back(c); return *this;} + PIString & reverse() {PIString str(*this); clear(); piForeachCR (PIChar c, str) push_back(c); return *this;} /*! \brief Reverse copy of this string and return it * \details Example: \snippet pistring.cpp PIString::reversed @@ -394,13 +406,13 @@ public: * \details "Shield" symbol prevent analysis of the next symbol. * Example: \snippet pistring.cpp PIString::takeRange * \sa \a takeSymbol(), \a takeWord(), \a takeLine(), \a takeNumber() */ - PIString takeRange(const PIChar & start, const PIChar & end, const PIChar & shield = '\\'); + PIString takeRange(const PIChar start, const PIChar end, const PIChar shield = '\\'); /*! \brief Return a string in brackets "start" and "end" symbols from the begin of this * string and return it. * \details Example: string = "a(b(c)d)e"; inBrackets('(', ')') = "b(c)d"; */ - PIString inBrackets(const PIChar & start, const PIChar & end) const; + PIString inBrackets(const PIChar start, const PIChar end) const; /*! \brief Return real bytes count of this string * \details It`s equivalent length of char sequence @@ -467,11 +479,8 @@ public: PIString toNativeDecimalPoints() const; - //! \brief Returns if string contains "str" - bool contains(const char str) const {return contains(PIString(str));} - - //! \brief Returns if string contains "str" - bool contains(const PIChar str) const {return contains(PIString(str));} + //! \brief Returns if string contains "c" + bool contains(const char c) const {return PIDeque::contains(PIChar(c));} //! \brief Returns if string contains "str" bool contains(const char * str) const {return contains(PIString(str));} @@ -480,9 +489,9 @@ public: bool contains(const PIString & str) const {return find(str) >= 0;} - //! \brief Search substring "str" from symbol at index "start" and return first occur position + //! \brief Search symbol "c" from symbol at index "start" and return first occur position //! \details Example: \snippet pistring.cpp PIString::find - int find(const char str, const int start = 0) const; + int find(const char c, const int start = 0) const; //! \brief Search substring "str" from symbol at index "start" and return first occur position //! \details Example: \snippet pistring.cpp PIString::find @@ -492,9 +501,9 @@ public: //! \details Example: \snippet pistring.cpp PIString::find int find(const char * str, const int start = 0) const {return find(PIString(str), start);} - //! \brief Search substring "str" from symbol at index "start" and return last occur position + //! \brief Search symbol "c" from symbol at index "start" and return last occur position //! \details Example: \snippet pistring.cpp PIString::findLast - int findLast(const char str, const int start = 0) const; + int findLast(const char c, const int start = 0) const; //! \brief Search substring "str" from symbol at index "start" and return last occur position //! \details Example: \snippet pistring.cpp PIString::findLast @@ -514,7 +523,7 @@ public: //! \brief Search range between "start" and "end" symbols at index "start_index" and return first occur position. //! \details Example: \snippet pistring.cpp PIString::findRange - int findRange(const PIChar & start, const PIChar & end, const PIChar & shield = '\\', const int start_index = 0, int * len = 0) const; + int findRange(const PIChar start, const PIChar end, const PIChar shield = '\\', const int start_index = 0, int * len = 0) const; //! \brief Search any symbol of "str" from symbol at index "start" and return first occur position //! \details Example: \snippet pistring.cpp PIString::findAny @@ -533,7 +542,7 @@ public: int findAnyLast(const char * str, const int start = 0) const {return findAnyLast(PIString(str), start);} //! \brief Returns number of occurrences of symbol "c" - int entries(const PIChar & c) const; + int entries(const PIChar c) const; //! \brief Returns number of occurrences of symbol "c" int entries(char c) const {return entries(PIChar(c));} @@ -718,9 +727,6 @@ public: //! \details Example: \snippet pistring.cpp PIString::readableSize static PIString readableSize(llong bytes); - PIString & removeAll(char v) {replaceAll(v, ""); return *this;} - PIString & removeAll(const PIString & v) {replaceAll(v, ""); return *this;} - private: static const char toBaseN[]; static const int fromBaseN[]; @@ -763,6 +769,12 @@ inline PIString operator +(const PIString & f, const char * str) {PIString s(f); //! \relatesalso PIString \brief Return concatenated string inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;} +//! \relatesalso PIString \brief Return concatenated string +inline PIString operator +(const char c, const PIString & f) {return PIChar(c) + f;} + +//! \relatesalso PIString \brief Return concatenated string +inline PIString operator +(const PIString & f, const char c) {return f + PIChar(c);} + inline char chrUpr(char c); inline char chrLwr(char c); diff --git a/lib/main/io_devices/pifile.cpp b/lib/main/io_devices/pifile.cpp index cc9d0d9c..065cc635 100644 --- a/lib/main/io_devices/pifile.cpp +++ b/lib/main/io_devices/pifile.cpp @@ -593,7 +593,7 @@ void PIFile::setDefaultCharset(const char * c) { PIFile::FileInfo PIFile::fileInfo(const PIString & path) { FileInfo ret; if (path.isEmpty()) return ret; - ret.path = path.replaceAll("\\", PIDir::separator); + ret.path = path.replacedAll("\\", PIDir::separator); PIString n = ret.name(); //piCout << "open" << path; #ifdef WINDOWS diff --git a/lib/main/io_devices/piiodevice.cpp b/lib/main/io_devices/piiodevice.cpp index f4919052..ec54085b 100644 --- a/lib/main/io_devices/piiodevice.cpp +++ b/lib/main/io_devices/piiodevice.cpp @@ -382,7 +382,7 @@ void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * int dm = 0; DeviceOptions op = 0; if (fpwm.find("(") > 0 && fpwm.find(")") > 0) { - PIString dms(fpwm.right(fpwm.length() - fpwm.findLast("(")).takeRange("(", ")").trim().toLowerCase().removeAll(" ")); + PIString dms(fpwm.right(fpwm.length() - fpwm.findLast("(")).takeRange("(", ")").trim().toLowerCase().removeAll(' ')); PIStringList opts(dms.split(",")); piForeachC (PIString & o, opts) { //piCout << dms; diff --git a/main.cpp b/main.cpp index 923d74ee..f0613273 100644 --- a/main.cpp +++ b/main.cpp @@ -34,36 +34,25 @@ int main() { class db { public: db() { - for (int i=0; i<1000; ++i) + for (int i=0; i<10000; ++i) x << sin(double(i)/180.0); - printf("jkfkhg\n"); + //printf("jkfkhg\n"); } -// db(const db & d) {x = d.x;} -// db(db && o) {x.swap(o.x);} private: PIVector x; }; #include "picodeparser.h" int main() { + /*PIString s(" 324 654 sf 5fdwg sdfsdf sdfefg"); + piCout << s; + piCout << s.replaceAll(' ', '1');*/ piDebug = false; - printf("==============\n"); double min = -1, max = -1, mean = 0; for (int i = 0; i < 50; ++i) { + PICodeParser cp; PITimeMeasurer tm; - /*PICodeParser cp; - cp.parseFile("SH_plugin_base.h");*/ - PIVector sl; - sl.reserve(10000); - db d; - for (int i = 0; i < 10000; ++i) { -// db b(d); -// db c(b); -// c = b; -// sl << c; - sl << db(d); -// sl << std::move(d); - } + cp.parseFile("SH_plugin_base.h"); double ms = tm.elapsed_m(); if (min < 0) min = ms; if (max < 0) max = ms; diff --git a/utils/code_model_generator/main.cpp b/utils/code_model_generator/main.cpp index 7bff7667..cb42eaac 100755 --- a/utils/code_model_generator/main.cpp +++ b/utils/code_model_generator/main.cpp @@ -331,13 +331,13 @@ void makeGetterValue(PIFile & f, const PICodeParser::Entity * e) { void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool meta, bool enums, bool streams, bool texts, bool getters) { PIVector ventities; PIString defname = out - .replaceAll(".", "_") - .replaceAll("/", "_") - .replaceAll(":", "_") - .replaceAll("-", "_") - .replaceAll("@", "_") - .replaceAll("\\", "_") - .removeAll(" ") + .replacedAll('.', '_') + .replaceAll('/', '_') + .replaceAll(':', '_') + .replaceAll('-', '_') + .replaceAll('@', '_') + .replaceAll('\\', '_') + .removeAll(' ') .toUpperCase() + "_H"; bool inc_h, inc_cpp;