mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[Python] Modified the paste effect in script and shell area
When a formula is pasted in a script or in the shell, some symbols are replaced by their equivalent in python : x turns into * ^ turns into ** √ turns into sqrt etc Change-Id: If6f2a22d4f3c148c2655e0892023b0e28058a9a6
This commit is contained in:
committed by
Émilie Feral
parent
4b965a0ff6
commit
8f97a332f6
@@ -1,44 +1,20 @@
|
||||
#include "helpers.h"
|
||||
#include <string.h>
|
||||
#include <ion/unicode/code_point.h>
|
||||
#include <ion.h>
|
||||
#include <escher/clipboard.h>
|
||||
|
||||
namespace Code {
|
||||
namespace Helpers {
|
||||
|
||||
class EventTextPair {
|
||||
public:
|
||||
constexpr EventTextPair(Ion::Events::Event event, const char * text) : m_event(event), m_text(text) {}
|
||||
Ion::Events::Event event() const { return m_event; }
|
||||
const char * text() const { return m_text; }
|
||||
private:
|
||||
const Ion::Events::Event m_event;
|
||||
const char * m_text;
|
||||
};
|
||||
|
||||
static_assert('\x11' == UCodePointEmpty, "Unicode error");
|
||||
static constexpr EventTextPair sEventTextMap[] = {
|
||||
EventTextPair(Ion::Events::XNT, "x"),
|
||||
EventTextPair(Ion::Events::Exp, "exp(\x11)"),
|
||||
EventTextPair(Ion::Events::Ln, "log(\x11)"),
|
||||
EventTextPair(Ion::Events::Log, "log10(\x11)"),
|
||||
EventTextPair(Ion::Events::Imaginary, "1j"),
|
||||
EventTextPair(Ion::Events::Power, "**"),
|
||||
EventTextPair(Ion::Events::Pi, "pi"),
|
||||
EventTextPair(Ion::Events::Sqrt, "sqrt(\x11)"),
|
||||
EventTextPair(Ion::Events::Square, "**2"),
|
||||
EventTextPair(Ion::Events::Multiplication, "*"),
|
||||
EventTextPair(Ion::Events::EE, "e"),
|
||||
};
|
||||
|
||||
const char * PythonTextForEvent(Ion::Events::Event event) {
|
||||
for (size_t i=0; i<sizeof(sEventTextMap)/sizeof(sEventTextMap[0]); i++) {
|
||||
if (event == sEventTextMap[i].event()) {
|
||||
return sEventTextMap[i].text();
|
||||
for (size_t i=0; i<NumberOfPythonTextPairs; i++) {
|
||||
UTF8Helper::TextPair pair = PythonTextPairs[i];
|
||||
if (event.text() == pair.firstString()) {
|
||||
return pair.secondString();
|
||||
}
|
||||
if (event == Ion::Events::XNT) {
|
||||
return "x";
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user