[apps/shared/function] BaseNameCompliant returns a NameNotCompliantError

instead of a boolean
This commit is contained in:
Ruben Dashyan
2020-02-06 18:16:33 +01:00
committed by Léa Saviot
parent ce5f8236a9
commit b54d5a31ba
3 changed files with 9 additions and 20 deletions

View File

@@ -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 {