diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index 7d52044c0..224673d54 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -67,8 +67,8 @@ bool ListController::textFieldDidFinishEditing(TextField * textField, const char GlobalContext::DestroyRecordsBaseNamedWithoutExtension(baseName, Ion::Storage::funcExtension); // Set the name - Function::NameNotCompliantError nameError = Function::NameNotCompliantError::None; - Ion::Storage::Record::ErrorStatus error = Function::BaseNameCompliant(baseName, &nameError) ? modelStore()->recordAtIndex(m_selectableTableView.selectedRow()).setBaseNameWithExtension(baseName, Ion::Storage::funcExtension) : Ion::Storage::Record::ErrorStatus::NonCompliantName; + Function::NameNotCompliantError nameError = Function::BaseNameCompliant(baseName); + Ion::Storage::Record::ErrorStatus error = nameError == Function::NameNotCompliantError::None ? modelStore()->recordAtIndex(m_selectableTableView.selectedRow()).setBaseNameWithExtension(baseName, Ion::Storage::funcExtension) : Ion::Storage::Record::ErrorStatus::NonCompliantName; // Handle any error if (error == Ion::Storage::Record::ErrorStatus::None) { diff --git a/apps/shared/function.cpp b/apps/shared/function.cpp index ec6989793..31b1e01e0 100644 --- a/apps/shared/function.cpp +++ b/apps/shared/function.cpp @@ -10,40 +10,28 @@ using namespace Poincare; namespace Shared { -bool Function::BaseNameCompliant(const char * baseName, NameNotCompliantError * error) { +Function::NameNotCompliantError Function::BaseNameCompliant(const char * baseName) { assert(baseName[0] != 0); UTF8Decoder decoder(baseName); CodePoint c = decoder.nextCodePoint(); if (c.isDecimalDigit()) { - // The name cannot start with a number - if (error != nullptr) { - *error = NameNotCompliantError::NameCannotStartWithNumber; - } - return false; + return NameNotCompliantError::NameCannotStartWithNumber; } - // The name should only have allowed characters while (c != UCodePointNull) { // FIXME '_' should be accepted but not as first character // TODO Factor this piece of code with similar one in the Parser if (!(c.isDecimalDigit() || c.isLatinLetter()) || c == '_') { - if (error != nullptr) { - *error = NameNotCompliantError::CharacterNotAllowed; - } - return false; + return NameNotCompliantError::CharacterNotAllowed; } c = decoder.nextCodePoint(); } - // The name should not be a reserved name if (Parser::IsReservedName(baseName, strlen(baseName))) { - if (error != nullptr) { - *error = NameNotCompliantError::ReservedName; - } - return false; + return NameNotCompliantError::ReservedName; } - return true; + return NameNotCompliantError::None; } bool Function::isActive() const { diff --git a/apps/shared/function.h b/apps/shared/function.h index 617dba813..52bdff733 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -20,13 +20,14 @@ public: NameCannotStartWithNumber, ReservedName }; + static NameNotCompliantError BaseNameCompliant(const char * baseName); + /* Possible arguments: n, x, t, θ * The CodePoint θ is two char long. */ constexpr static int k_parenthesedArgumentCodePointLength = 3; constexpr static int k_parenthesedThetaArgumentByteLength = 4; constexpr static int k_parenthesedXNTArgumentByteLength = 3; constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedThetaArgumentByteLength; /* Function name and null-terminating char + "(θ)" */; - static bool BaseNameCompliant(const char * baseName, NameNotCompliantError * error = nullptr); // Constructors Function(Ion::Storage::Record record) : ExpressionModelHandle(record){}