mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[apps/shared/function] BaseNameCompliant returns a NameNotCompliantError
instead of a boolean
This commit is contained in:
committed by
Léa Saviot
parent
ce5f8236a9
commit
b54d5a31ba
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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){}
|
||||
|
||||
Reference in New Issue
Block a user