diff --git a/apps/graph/list/storage_list_controller.cpp b/apps/graph/list/storage_list_controller.cpp index 6a4f94827..83b4bcd5a 100644 --- a/apps/graph/list/storage_list_controller.cpp +++ b/apps/graph/list/storage_list_controller.cpp @@ -42,14 +42,16 @@ void StorageListController::renameSelectedFunction() { bool StorageListController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { // Compute the new name size_t textLength = strlen(text); - size_t argumentLength = StorageFunction::k_parenthesedArgumentLength; - constexpr int maxBaseNameSize = StorageFunction::k_maxNameWithArgumentSize; + size_t argumentLength = StorageFunction::k_parenthesedArgumentWithEqualLength; + constexpr int maxBaseNameSize = StorageFunction::k_maxNameWithArgumentAndEqualSize; char baseName[maxBaseNameSize]; if (textLength <= argumentLength) { // The user entered an empty name. Use a default function name. StorageCartesianFunction::DefaultName(baseName, maxBaseNameSize); size_t defaultNameLength = strlen(baseName); + assert(defaultNameLength + Shared::StorageCartesianFunction::k_maxNameWithArgumentAndEqualSize < maxBaseNameSize); strlcpy(baseName + defaultNameLength, StorageFunction::k_parenthesedArgument, maxBaseNameSize - defaultNameLength); + strlcpy(baseName + defaultNameLength + StorageFunction::k_parenthesedArgumentLength, StorageFunction::k_equal, maxBaseNameSize - defaultNameLength - StorageFunction::k_parenthesedArgumentLength); textField->setText(baseName); baseName[defaultNameLength] = 0; } else { @@ -164,7 +166,7 @@ void StorageListController::willDisplayExpressionCellAtIndex(HighlightCell * cel void StorageListController::setFunctionNameInTextField(ExpiringPointer function, TextField * textField) { char bufferName[BufferTextView::k_maxNumberOfChar]; - function->nameWithArgument(bufferName, BufferTextView::k_maxNumberOfChar, modelStore()->symbol()); + function->nameWithArgumentAndEqual(bufferName, BufferTextView::k_maxNumberOfChar, modelStore()->symbol()); textField->setText(bufferName); } diff --git a/apps/graph/list/text_field_function_title_cell.cpp b/apps/graph/list/text_field_function_title_cell.cpp index 4cd6dd5b7..081e921a4 100644 --- a/apps/graph/list/text_field_function_title_cell.cpp +++ b/apps/graph/list/text_field_function_title_cell.cpp @@ -7,7 +7,7 @@ namespace Graph { TextFieldFunctionTitleCell::TextFieldFunctionTitleCell(StorageListController * listController, Orientation orientation, const KDFont * font) : Shared::FunctionTitleCell(orientation), Responder(listController), - m_textField(Shared::StorageFunction::k_parenthesedArgumentLength, this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, listController, false, font, 0.5f, 0.5f) + m_textField(Shared::StorageFunction::k_parenthesedArgumentWithEqualLength, this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, listController, false, font, 0.5f, 0.5f) {} void TextFieldFunctionTitleCell::setHighlighted(bool highlight) { diff --git a/apps/graph/list/text_field_function_title_cell.h b/apps/graph/list/text_field_function_title_cell.h index f719668d6..29cb36a44 100644 --- a/apps/graph/list/text_field_function_title_cell.h +++ b/apps/graph/list/text_field_function_title_cell.h @@ -41,7 +41,7 @@ public: protected: KDRect textFieldFrame() const; private: - constexpr static int k_textFieldBufferSize = Shared::StorageFunction::k_maxNameWithArgumentSize; + constexpr static int k_textFieldBufferSize = Shared::StorageFunction::k_maxNameWithArgumentAndEqualSize; Shared::TextFieldWithExtension m_textField; char m_textFieldBuffer[k_textFieldBufferSize]; }; diff --git a/apps/shared/storage_function.cpp b/apps/shared/storage_function.cpp index afb572634..80f21dc4d 100644 --- a/apps/shared/storage_function.cpp +++ b/apps/shared/storage_function.cpp @@ -10,6 +10,7 @@ using namespace Poincare; namespace Shared { constexpr char StorageFunction::k_parenthesedArgument[]; +constexpr char StorageFunction::k_equal[]; bool StorageFunction::BaseNameCompliant(const char * baseName, NameNotCompliantError * error) { assert(baseName[0] != 0); @@ -63,11 +64,17 @@ void StorageFunction::setActive(bool active) { int StorageFunction::nameWithArgument(char * buffer, size_t bufferSize, char arg) { const char * functionName = fullName(); size_t baseNameLength = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize - k_parenthesedArgumentLength); - int result = baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); if (baseNameLength+1 < bufferSize - 1) { buffer[baseNameLength+1] = arg; } - return result; + return strlen(buffer); +} + +int StorageFunction::nameWithArgumentAndEqual(char * buffer, size_t bufferSize, char arg) { + int numberOfChars = nameWithArgument(buffer, bufferSize, arg); + strlcpy(&buffer[numberOfChars], k_equal, bufferSize-numberOfChars); + return strlen(buffer); } template diff --git a/apps/shared/storage_function.h b/apps/shared/storage_function.h index 853f2a804..834106071 100644 --- a/apps/shared/storage_function.h +++ b/apps/shared/storage_function.h @@ -17,6 +17,9 @@ public: constexpr static int k_parenthesedArgumentLength = 3; static constexpr char k_parenthesedArgument[k_parenthesedArgumentLength+1] = "(x)"; constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedArgumentLength; /* Function name and null-terminating char + "(x)" */; + constexpr static int k_parenthesedArgumentWithEqualLength = k_parenthesedArgumentLength + 1; + static constexpr char k_equal[] = "="; + constexpr static int k_maxNameWithArgumentAndEqualSize = k_maxNameWithArgumentSize + 1; static bool BaseNameCompliant(const char * baseName, NameNotCompliantError * error = nullptr); // Constructors @@ -29,6 +32,7 @@ public: // Name int nameWithArgument(char * buffer, size_t bufferSize, char arg); + int nameWithArgumentAndEqual(char * buffer, size_t bufferSize, char arg); // Evaluation virtual float evaluateAtAbscissa(float x, Poincare::Context * context) const {