From 7f30636ecbeb645847f1ad2016722c5dc33f7498 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 26 Mar 2018 19:31:42 -0400 Subject: [PATCH] .ny header can distinguish internal vs visible choice strings... ... Syntax is like: ( "InternalString" (_ "Visible String") ) But none of the shipped .ny headers need this yet. --- src/effects/nyquist/Nyquist.cpp | 34 ++++++++++++++++++++++++++------- src/effects/nyquist/Nyquist.h | 3 ++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index fba042235..92f610def 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -1489,8 +1489,14 @@ std::vector NyquistEffect::ParseChoice(const wxString & te Tokenizer tzer; tzer.Tokenize(text, true, 1, 1); auto &choices = tzer.tokens; - for (auto &choice : choices) - results.push_back( { UnQuote(choice) } ); + wxString extra; + for (auto &choice : choices) { + auto label = UnQuote(choice, true, &extra); + if (extra.empty()) + results.push_back( { label } ); + else + results.push_back( { extra, label } ); + } } else { // Old style: expecting a comma-separated list of @@ -1533,8 +1539,12 @@ void NyquistEffect::Stop() mStop = true; } -wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens) +wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens, + wxString *pExtraString) { + if (pExtraString) + *pExtraString = wxString{}; + int len = s.Length(); if (len >= 2 && s[0] == wxT('\"') && s[len - 1] == wxT('\"')) { auto unquoted = s.Mid(1, len - 2); @@ -1545,10 +1555,20 @@ wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens) Tokenizer tzer; tzer.Tokenize(s, true, 1, 1); auto &tokens = tzer.tokens; - if (tokens.size() > 1) - // Assume the first token was _ -- we don't check that - // And the second is the string, which is internationalized - return UnQuote( tokens[1], false ); + if (tokens.size() > 1) { + if (pExtraString && tokens[1][0] == '(') { + // A choice with a distinct internal string form like + // ("InternalString" (_ "Visible string")) + // Recur to find the two strings + *pExtraString = UnQuote(tokens[0], false); + return UnQuote(tokens[1]); + } + else { + // Assume the first token was _ -- we don't check that + // And the second is the string, which is internationalized + return UnQuote( tokens[1], false ); + } + } else return {}; } diff --git a/src/effects/nyquist/Nyquist.h b/src/effects/nyquist/Nyquist.h index 0836eaf4f..5e1994b82 100644 --- a/src/effects/nyquist/Nyquist.h +++ b/src/effects/nyquist/Nyquist.h @@ -177,7 +177,8 @@ private: }; bool Parse(Tokenizer &tokenizer, const wxString &line, bool eof, bool first); - static wxString UnQuote(const wxString &s, bool allowParens = true); + static wxString UnQuote(const wxString &s, bool allowParens = true, + wxString *pExtraString = nullptr); double GetCtrlValue(const wxString &s); void OnLoad(wxCommandEvent & evt);