Ejemplo n.º 1
0
// Change text to the next one accrording to dictionary order
// The part that can be changed is between string[min_len] and string[max_len-1]
// Retrun true if succeed, false if the next one doesn't exist
bool next_string( ID& text, int min_len, int max_len ) {
  if ((int)text.size() < max_len) {
    text.append("0");
    return true;
  }

  while (text.back() == 'z') {
    text.pop_back();
    if ((int)text.size() == min_len) {
      return false;
    }
  }

  char c = text.back();
  if (c == '9') {
    text.back() = 'A';
  } else if (c == 'Z') {
    text.back() = 'a';
  } else {
    text.back() += 1;
  }
  return true;
}