[apps] Create and use StorageFunction::BaseNameCompliant

This commit is contained in:
Léa Saviot
2018-10-19 11:36:15 +02:00
committed by Émilie Feral
parent b2c2ca17c8
commit 9e332b0c2b
9 changed files with 26 additions and 3 deletions

View File

@@ -10,6 +10,24 @@ namespace Shared {
char StorageFunction::k_parenthesedArgument[]("(x)");
bool StorageFunction::BaseNameCompliant(const char * baseName) {
if (baseName[0] == 0 || (baseName[0] >= '0' && baseName[0] <= '9')) {
// The name cannot be empty nor start with a number
return false;
}
const char * currentChar = baseName;
while (*currentChar != 0) {
if (!((*currentChar >= 'A' && *currentChar <= 'Z')
|| (*currentChar >= 'a' && *currentChar <= 'z')
|| (*currentChar >= '0' && *currentChar <= '9')
|| *currentChar == '_')) {
return false;
}
currentChar++;
}
return true;
}
uint32_t StorageFunction::checksum() {
assert(!isNull());
return checksum();