diff --git a/apps/shared/function.cpp b/apps/shared/function.cpp index 01f284303..8c0c4336a 100644 --- a/apps/shared/function.cpp +++ b/apps/shared/function.cpp @@ -10,8 +10,6 @@ using namespace Poincare; namespace Shared { -constexpr char Function::k_parenthesedArgument[]; - bool Function::BaseNameCompliant(const char * baseName, NameNotCompliantError * error) { assert(baseName[0] != 0); @@ -64,14 +62,14 @@ void Function::setActive(bool active) { int Function::nameWithArgument(char * buffer, size_t bufferSize) { const char * functionName = fullName(); - size_t baseNameLength = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize - k_parenthesedArgumentLength); - assert(baseNameLength <= bufferSize); - size_t result = baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); - int bufferRemainingSize = bufferSize - (baseNameLength+1); - if (bufferRemainingSize > 0) { - assert(UTF8Decoder::CharSizeOfCodePoint(symbol()) == 1); - UTF8Decoder::CodePointToChars(symbol(), buffer+baseNameLength+1, bufferRemainingSize); - } + size_t result = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize); + assert(result <= bufferSize); + buffer[result++] = '('; + assert(result <= bufferSize); + assert(UTF8Decoder::CharSizeOfCodePoint(symbol()) <= 2); + result += UTF8Decoder::CodePointToChars(symbol(), buffer+result, bufferSize-result); + assert(result <= bufferSize); + result += strlcpy(buffer+result, ")", bufferSize-result); return result; } diff --git a/apps/shared/function.h b/apps/shared/function.h index 9baca7094..c83705811 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -19,8 +19,9 @@ public: NameCannotStartWithNumber, ReservedName }; - constexpr static int k_parenthesedArgumentLength = 3; - static constexpr char k_parenthesedArgument[k_parenthesedArgumentLength+1] = "(x)"; + /* Possible arguments: n, x, t, θ + * The CodePoint θ is two char long. */ + constexpr static int k_parenthesedArgumentLength = 4; constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedArgumentLength; /* Function name and null-terminating char + "(x)" */; static bool BaseNameCompliant(const char * baseName, NameNotCompliantError * error = nullptr);