diff --git a/apps/graph/list/storage_list_controller.cpp b/apps/graph/list/storage_list_controller.cpp index f92b369d5..f92b24705 100644 --- a/apps/graph/list/storage_list_controller.cpp +++ b/apps/graph/list/storage_list_controller.cpp @@ -40,7 +40,7 @@ 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 = strlen("(x)"); //TODO + size_t argumentLength = StorageFunction::k_parenthesedArgumentLength; constexpr int maxBaseNameSize = StorageFunction::k_maxNameWithArgumentSize; char baseName[maxBaseNameSize]; if (textLength <= argumentLength) { diff --git a/apps/shared/storage_function.cpp b/apps/shared/storage_function.cpp index c4e61318b..36610b5c6 100644 --- a/apps/shared/storage_function.cpp +++ b/apps/shared/storage_function.cpp @@ -8,6 +8,8 @@ using namespace Poincare; namespace Shared { +char StorageFunction::k_parenthesedArgument[]("(x)"); + uint32_t StorageFunction::checksum() { assert(!isNull()); return checksum(); @@ -28,16 +30,15 @@ void StorageFunction::setActive(bool active) { int StorageFunction::nameWithArgument(char * buffer, size_t bufferSize, char arg) { const char * functionName = fullName(); size_t index = 0; - const char ofXSring[4] = {'(',arg,')', 0}; - size_t ofXSringLength = strlen(ofXSring); + k_parenthesedArgument[1] = arg; while (*functionName != Ion::Storage::k_dotChar - && index < bufferSize - ofXSringLength - 1) + && index < bufferSize - k_parenthesedArgumentLength - 1) { // We keep room to write the final "(x)" //TODO should we? assert(functionName < fullName() + strlen(fullName())); buffer[index++] = *functionName++; } - return index + strlcpy(&buffer[index], ofXSring, bufferSize-index); + return index + strlcpy(&buffer[index], k_parenthesedArgument, bufferSize-index); } template diff --git a/apps/shared/storage_function.h b/apps/shared/storage_function.h index aaaf0d535..78dceb8e0 100644 --- a/apps/shared/storage_function.h +++ b/apps/shared/storage_function.h @@ -9,7 +9,9 @@ namespace Shared { class StorageFunction : public StorageExpressionModel { public: - constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + 4; /* Function name and null-terminating char + "(x)" */; + constexpr static int k_parenthesedArgumentLength = 3; + constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedArgumentLength; /* Function name and null-terminating char + "(x)" */; + // Constructors StorageFunction(Ion::Storage::Record record) : StorageExpressionModel(record){} @@ -44,6 +46,7 @@ protected: bool m_active; }; private: + static char k_parenthesedArgument[k_parenthesedArgumentLength+1]; template T templatedApproximateAtAbscissa(T x, Poincare::Context * context) const; FunctionRecordData * recordData() const; };