void LispyCommandMessageTarget::AddItem(const wxString &value, const wxString &name){ wxString Padding; if( name.empty() ) Update( wxString::Format( "%s%s\"%s\"", (mCounts.back()>0)?" ":"", Padding, Escaped(value))); else Update( wxString::Format( "%s%s(%s \"%s\")", (mCounts.back()>0)?" ":"", Padding, name, Escaped(value))); mCounts.back() += 1; }
bool Escaped(string content, unsigned int index){ if((index == 0) || (content[index-1] != *"%")){ return false; } else{ return !(Escaped(content,index-1)); } }
void CommandMessageTarget::AddItem(const wxString &value, const wxString &name){ wxString Padding; Padding.Pad( mCounts.size() *2 -2); Padding = (( value.length() < 15 ) || (mCounts.back()<=0)) ? "" : wxString("\n") + Padding; if( name.empty() ) Update( wxString::Format( "%s%s\"%s\"", (mCounts.back()>0)?", ":"", Padding, Escaped(value))); else Update( wxString::Format( "%s%s\"%s\":\"%s\"", (mCounts.back()>0)?", ":"", Padding, name, Escaped(value))); mCounts.back() += 1; }
vector<string> Split_get(string start,string token){ vector<string> result; string buffer = start; string::size_type token_index; unsigned int pos = 0; while((token_index = buffer.find(token,pos)) != string::npos){ if (Escaped(buffer,token_index)){ if (token_index+1 < buffer.size()){ break; } pos = token_index+1; continue; } if (token_index != 0){ result.push_back(buffer.substr(0, token_index)); } buffer = buffer.substr(token_index + 1); } result.push_back(buffer); return result; }
void BriefCommandMessageTarget::AddItem(const wxString &value, const wxString &WXUNUSED(name)){ if( mCounts.size() <= 3 ) Update( wxString::Format( "%s\"%s\"", (mCounts.back()>0)?" ":"",Escaped(value))); mCounts.back() += 1; }
/* RETranslate - translate a pattern string and match structure into an * output string. During pattern search-and-replace, RETranslate is used * to generate an output string based on an input match pattern and a template * that directs the output. * * The input match is any patType returned from RECompile that has been passed * to fREMatch and that causes fREMatch to return TRUE. The template string * is any set of ascii chars. The $ character leads in arguments: * * $$ is replaced with $ * $0 is replaced with the entire match string * $1-$9 is replaced with the corresponding tagged (by {}) item from * the match. * * An alternative method is to specify the argument as: * * $([w,]a) where a is the argument number (0-9) and w is an optional field * width that will be used in a printf %ws format. * * buf pattern matched * src template for the match * dst destination of the translation * * Returns: TRUE if translation was successful, FALSE otherwise */ flagType RETranslate (struct patType *buf, register char *src, register char *dst) { int i, w; char *work; char chArg = (char) (buf->fUnix ? '\\' : '$'); work = REmalloc (MAXLINELEN); if (work == NULL) return FALSE; *dst = '\0'; while (*src != '\0') { /* Process tagged substitutions first */ if (*src == chArg && (isdigit (src[1]) || src[1] == '(')) { /* presume 0-width field */ w = 0; /* skip $ and char */ src += 2; /* if we saw $n */ if (isdigit (src[-1])) i = src[-1] - '0'; /* else we saw $( */ else { /* get tagged expr number */ i = atoi (src); /* skip over number */ if (*src == '-') src++; src = strbskip (src, digits); /* was there a comma? */ if (*src == ',') { /* We saw field width, parse off expr number */ w = i; i = atoi (++src); src = strbskip (src, digits); } /* We MUST end with a close paren */ if (*src++ != ')') { free (work); return FALSE; } } /* w is field width * i is selected argument */ if (!REGetArg (buf, i, work)) { free (work); return FALSE; } sprintf (dst, "%*s", w, work); dst += strlen (dst); } else /* process escaped characters */ if (*src == '\\') { src++; if (!*src) { free (work); return FALSE; } *dst++ = Escaped (*src++); } else /* chArg quotes itself */ if (*src == chArg && src[1] == chArg) { *dst++ = chArg; src += 2; } else if (IsDBCSLeadByte(*src) && *(src+1)) { *dst++ = *src++; *dst++ = *src++; } else *dst++ = *src++; } *dst = '\0'; free (work); return TRUE; }
static string_view ProcessMetasymbol(string_view const CurStr, subst_data& SubstData, string& Out) { const auto append_with_escape = [EscapeAmpersands = SubstData.EscapeAmpersands](string& Destination, string_view const Str) { if (EscapeAmpersands && contains(Str, L"&"sv)) { string Escaped(Str); replace(Escaped, L"&"sv, L"&&"sv); append(Destination, Escaped); } else { append(Destination, Str); } }; if (const auto Tail = tokens::skip(CurStr, tokens::passive_panel)) { SubstData.PassivePanel = true; return Tail; } if (const auto Tail = tokens::skip(CurStr, tokens::active_panel)) { SubstData.PassivePanel = false; return Tail; } if (const auto Tail = tokens::skip(CurStr, tokens::exclamation)) { if (!starts_with(Tail, L'?')) { Out.push_back(L'!'); return Tail; } } if (const auto Tail = tokens::skip(CurStr, tokens::name_extension)) { if (!starts_with(Tail, L'?')) { append_with_escape(Out, SubstData.Default().Normal.Name); return Tail; } } if (const auto Tail = tokens::skip(CurStr, tokens::short_name)) { append_with_escape(Out, SubstData.Default().Short.NameOnly); return Tail; } const auto GetExtension = [](string_view const Name) { const auto Extension = PointToExt(Name); return Extension.empty()? Extension : Extension.substr(1); }; if (const auto Tail = tokens::skip(CurStr, tokens::short_extension)) { append_with_escape(Out, GetExtension(SubstData.Default().Short.Name)); return Tail; } if (const auto Tail = tokens::skip(CurStr, tokens::extension)) { append_with_escape(Out, GetExtension(SubstData.Default().Normal.Name)); return Tail; } const auto CollectNames = [&SubstData, &append_with_escape](string& Str, auto const Selector) { append_with_escape(Str, join(select(SubstData.Default().Panel->enum_selected(), Selector), L" "sv)); }; if (const auto Tail = tokens::skip(CurStr, tokens::short_list)) { if (!starts_with(Tail, L'?')) { CollectNames(Out, &os::fs::find_data::AlternateFileName); return Tail; } } if (const auto Tail = tokens::skip(CurStr, tokens::list)) { if (!starts_with(Tail, L'?')) { CollectNames(Out, [](const os::fs::find_data& Data) { return quote_space(Data.FileName); }); return Tail; } } const auto GetListName = [&Out, &append_with_escape](string_view const Tail, subst_data& Data, bool Short) { const auto ExclPos = Tail.find(L'!'); if (ExclPos == Tail.npos || starts_with(Tail.substr(ExclPos + 1), L'?')) return size_t{}; const auto Modifiers = Tail.substr(0, ExclPos); if (Data.ListNames) { string Str; if (Data.Default().Panel->MakeListFile(Str, Short, Modifiers)) { if (Short) Str = ConvertNameToShort(Str); append_with_escape(Out, Str); Data.ListNames->add(std::move(Str)); } } else { append(Out, L'!', Short? L'$' : L'@', Modifiers, L'!'); } return Modifiers.size() + 1; }; if (const auto Tail = tokens::skip(CurStr, tokens::list_file)) { if (const auto Offset = GetListName(Tail, SubstData, false)) return string_view(Tail).substr(Offset); } if (const auto Tail = tokens::skip(CurStr, tokens::short_list_file)) { if (const auto Offset = GetListName(Tail, SubstData, true)) return string_view(Tail).substr(Offset); } if (const auto Tail = tokens::skip(CurStr, tokens::short_name_extension)) { if (!starts_with(Tail, L'?')) { append_with_escape(Out, SubstData.Default().Short.Name); return Tail; } } if (const auto Tail = tokens::skip(CurStr, tokens::short_name_extension_safe)) { if (!starts_with(Tail, L'?')) { append_with_escape(Out, SubstData.Default().Short.Name); SubstData.PreserveLFN = true; return Tail; } } if (const auto Tail = tokens::skip(CurStr, tokens::current_drive)) { const auto CurDir = IsAbsolutePath(SubstData.This.Normal.Name)? SubstData.This.Normal.Name : SubstData.PassivePanel? SubstData.Another.Panel->GetCurDir() : SubstData.CmdDir; auto RootDir = GetPathRoot(CurDir); DeleteEndSlash(RootDir); append_with_escape(Out, RootDir); return Tail; } if (const auto Tail = tokens::skip(CurStr, tokens::description)) { Out += SubstData.Default().GetDescription(); return Tail; } const auto GetPath = [](string_view const Tail, const subst_data& Data, bool Short, bool Real) { // TODO: paths on plugin panels are ambiguous auto CurDir = Data.PassivePanel? Data.Another.Panel->GetCurDir() : Data.CmdDir; if (Real) CurDir = ConvertNameToReal(CurDir); if (Short) CurDir = ConvertNameToShort(CurDir); AddEndSlash(CurDir); return CurDir; }; if (const auto Tail = tokens::skip(CurStr, tokens::path)) { Out += GetPath(Tail, SubstData, false, false); return Tail; } if (const auto Tail = tokens::skip(CurStr, tokens::short_path)) { Out += GetPath(Tail, SubstData, true, false); return Tail; } if (const auto Tail = tokens::skip(CurStr, tokens::real_path)) { Out += GetPath(Tail, SubstData, false, true); return Tail; } if (const auto Tail = tokens::skip(CurStr, tokens::real_short_path)) { Out += GetPath(Tail, SubstData, true, true); return Tail; } // !?<title>?<init>! if (const auto Tail = tokens::skip(CurStr, tokens::input)) { auto SkipSize = SkipInputToken(CurStr); // if bad format string skip 1 char if (!SkipSize) SkipSize = 1; Out.append(CurStr.data(), SkipSize); return CurStr.substr(SkipSize); } if (const auto Tail = tokens::skip(CurStr, tokens::name)) { append(Out, PointToName(SubstData.Default().Normal.NameOnly)); return Tail; } return CurStr; }