From 4dbd7583e0fc445bd77d79f12b46b9d2b96e322d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 18 Oct 2018 17:59:27 +0200 Subject: [PATCH] [apps] VariableBoxController: use StorageFunction::nameWithArgument to avoid reimplementing it --- apps/variable_box_controller.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 85739d299..318186ce9 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -1,6 +1,8 @@ #include "variable_box_controller.h" #include "shared/global_context.h" #include "shared/poincare_helpers.h" +#include "shared/storage_function.h" +#include "shared/storage_cartesian_function.h" #include "constant.h" #include #include @@ -81,12 +83,17 @@ void VariableBoxController::willDisplayCellForIndex(HighlightCell * cell, int in } ExpressionTableCellWithExpression * myCell = (ExpressionTableCellWithExpression *)cell; Storage::Record record = recordAtIndex(index); - char truncatedName[SymbolAbstract::k_maxNameSize+k_functionArgLength]; - size_t nameLength = SymbolAbstract::TruncateExtension(truncatedName, record.fullName(), SymbolAbstract::k_maxNameSize); - if (m_currentPage == Page::Function) { - nameLength += strlcpy(truncatedName+nameLength, k_functionArg, k_functionArgLength+1); + assert(Shared::StorageFunction::k_maxNameWithArgumentSize > SymbolAbstract::k_maxNameSize); + char symbolName[Shared::StorageFunction::k_maxNameWithArgumentSize]; + size_t symbolLength = 0; + if (m_currentPage == Page::Expression) { + symbolLength = SymbolAbstract::TruncateExtension(symbolName, record.fullName(), SymbolAbstract::k_maxNameSize); + } else { + assert(m_currentPage == Page::Function); + StorageCartesianFunction f(record); + symbolLength = f.nameWithArgument(symbolName, Shared::StorageFunction::k_maxNameWithArgumentSize, 'x'); } - Layout symbolLayout = LayoutHelper::String(truncatedName, nameLength); + Layout symbolLayout = LayoutHelper::String(symbolName, symbolLength); myCell->setLayout(symbolLayout); myCell->setAccessoryLayout(expressionLayoutForRecord(record, index)); }