mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user