[apps/shared/function] nameWithArgument handles 2-char-long argument CodePoints

This commit is contained in:
Ruben Dashyan
2019-08-20 17:10:41 +02:00
committed by Léa Saviot
parent 56c6bb9e19
commit 27b9ede90b
2 changed files with 11 additions and 12 deletions

View File

@@ -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;
}

View File

@@ -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);