diff --git a/apps/graph/list/storage_list_controller.cpp b/apps/graph/list/storage_list_controller.cpp index 60048321c..034c5afa0 100644 --- a/apps/graph/list/storage_list_controller.cpp +++ b/apps/graph/list/storage_list_controller.cpp @@ -42,16 +42,14 @@ 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_parenthesedArgumentWithEqualLength; - constexpr int maxBaseNameSize = StorageFunction::k_maxNameWithArgumentAndEqualSize; + size_t argumentLength = StorageFunction::k_parenthesedArgumentLength; + constexpr int maxBaseNameSize = StorageFunction::k_maxNameWithArgumentSize; 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 { @@ -168,7 +166,7 @@ void StorageListController::willDisplayExpressionCellAtIndex(HighlightCell * cel void StorageListController::setFunctionNameInTextField(ExpiringPointer function, TextField * textField) { char bufferName[BufferTextView::k_maxNumberOfChar]; - function->nameWithArgumentAndEqual(bufferName, BufferTextView::k_maxNumberOfChar, modelStore()->symbol()); + function->nameWithArgument(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 017f7b762..accc916ff 100644 --- a/apps/graph/list/text_field_function_title_cell.cpp +++ b/apps/graph/list/text_field_function_title_cell.cpp @@ -10,7 +10,7 @@ static inline float max(float x, float y) { return (x>y ? x : y); } TextFieldFunctionTitleCell::TextFieldFunctionTitleCell(StorageListController * listController, Orientation orientation, const KDFont * font) : Shared::FunctionTitleCell(orientation), Responder(listController), - m_textField(Shared::StorageFunction::k_parenthesedArgumentWithEqualLength, this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, listController, false, font, k_horizontalAlignment, 0.5f) + m_textField(Shared::StorageFunction::k_parenthesedArgumentLength, this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, listController, false, font, k_horizontalAlignment, 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 7dd0ebdbe..f74819086 100644 --- a/apps/graph/list/text_field_function_title_cell.h +++ b/apps/graph/list/text_field_function_title_cell.h @@ -40,7 +40,7 @@ public: void didBecomeFirstResponder() override; private: constexpr static float k_horizontalAlignment = 1.0f; - constexpr static int k_textFieldBufferSize = Shared::StorageFunction::k_maxNameWithArgumentAndEqualSize; + constexpr static int k_textFieldBufferSize = Shared::StorageFunction::k_maxNameWithArgumentSize; Shared::TextFieldWithExtension m_textField; char m_textFieldBuffer[k_textFieldBufferSize]; }; diff --git a/apps/shared/storage_function.cpp b/apps/shared/storage_function.cpp index 80f21dc4d..afb572634 100644 --- a/apps/shared/storage_function.cpp +++ b/apps/shared/storage_function.cpp @@ -10,7 +10,6 @@ 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); @@ -64,17 +63,11 @@ 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); - strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); + int result = baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); if (baseNameLength+1 < bufferSize - 1) { buffer[baseNameLength+1] = arg; } - 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); + return result; } template diff --git a/apps/shared/storage_function.h b/apps/shared/storage_function.h index 834106071..853f2a804 100644 --- a/apps/shared/storage_function.h +++ b/apps/shared/storage_function.h @@ -17,9 +17,6 @@ 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 @@ -32,7 +29,6 @@ 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 {