Limitat el nom a tres caracters
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
// Constructor
|
||||
EnterName::EnterName()
|
||||
: character_list_(" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()"),
|
||||
: character_list_(" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789."),
|
||||
character_index_{0} {}
|
||||
|
||||
// Inicializa el objeto
|
||||
@@ -22,7 +22,7 @@ void EnterName::init(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
position_ = name_.length();
|
||||
position_overflow_ = position_ >= MAX_NAME_LENGHT ? true : false;
|
||||
position_overflow_ = position_ >= NAME_SIZE ? true : false;
|
||||
}
|
||||
|
||||
// Inicializa el vector de indices con el nombre y espacios
|
||||
@@ -40,10 +40,10 @@ void EnterName::incPosition()
|
||||
|
||||
++position_;
|
||||
|
||||
if (position_ >= MAX_NAME_LENGHT)
|
||||
if (position_ >= NAME_SIZE)
|
||||
{
|
||||
position_ = MAX_NAME_LENGHT; // Mantenemos en el índice máximo válido.
|
||||
position_overflow_ = true; // Activamos el flag de overflow.
|
||||
position_ = NAME_SIZE; // Mantenemos en el índice máximo válido.
|
||||
position_overflow_ = true; // Activamos el flag de overflow.
|
||||
}
|
||||
else if (position_ > 0) // No es necesario verificar position_ < MAX_NAME_LENGHT
|
||||
{
|
||||
@@ -59,7 +59,6 @@ void EnterName::incPosition()
|
||||
updateNameFromCharacterIndex();
|
||||
}
|
||||
|
||||
|
||||
// Decrementa la posición
|
||||
void EnterName::decPosition()
|
||||
{
|
||||
@@ -67,7 +66,7 @@ void EnterName::decPosition()
|
||||
{
|
||||
// Si estaba en overflow, lo desactivamos y mantenemos position_ en el máximo.
|
||||
position_overflow_ = false;
|
||||
position_ = MAX_NAME_LENGHT - 1;
|
||||
position_ = NAME_SIZE - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -76,7 +75,7 @@ void EnterName::decPosition()
|
||||
--position_;
|
||||
|
||||
// Limpiamos el carácter siguiente si el índice es válido.
|
||||
if (position_ + 1 < MAX_NAME_LENGHT)
|
||||
if (position_ + 1 < NAME_SIZE)
|
||||
{
|
||||
character_index_[position_ + 1] = 0;
|
||||
}
|
||||
@@ -89,7 +88,7 @@ void EnterName::decPosition()
|
||||
}
|
||||
|
||||
// Si position_ es menor que NAME_LENGHT, aseguramos que el overflow esté desactivado.
|
||||
if (position_ < MAX_NAME_LENGHT)
|
||||
if (position_ < NAME_SIZE)
|
||||
{
|
||||
position_overflow_ = false;
|
||||
}
|
||||
@@ -134,7 +133,7 @@ void EnterName::decIndex()
|
||||
void EnterName::updateNameFromCharacterIndex()
|
||||
{
|
||||
name_.clear();
|
||||
for (int i = 0; i < MAX_NAME_LENGHT; ++i)
|
||||
for (int i = 0; i < NAME_SIZE; ++i)
|
||||
{
|
||||
name_.push_back(character_list_[character_index_[i]]);
|
||||
}
|
||||
@@ -145,13 +144,13 @@ void EnterName::updateNameFromCharacterIndex()
|
||||
void EnterName::initCharacterIndex(const std::string &name)
|
||||
{
|
||||
// Rellena de espacios
|
||||
for (size_t i = 0; i < MAX_NAME_LENGHT; ++i)
|
||||
for (size_t i = 0; i < NAME_SIZE; ++i)
|
||||
{
|
||||
character_index_[i] = 0;
|
||||
}
|
||||
|
||||
// Coloca los índices en función de los caracteres que forman el nombre
|
||||
for (size_t i = 0; i < name.substr(0, MAX_NAME_LENGHT).size(); ++i)
|
||||
for (size_t i = 0; i < name.substr(0, NAME_SIZE).size(); ++i)
|
||||
{
|
||||
character_index_[i] = findIndex(name.at(i));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user