/*
 * Stairs
 * Copyright 2017 (c) Mark van Renswoude
 *
 * https://git.x2software.net/pub/Stairs
*/
#include "./charproperties.h"
#include <cstddef>
#include <string.h>
#include "./debug.h"

void assignChar(char** field, const char* newValue)
{
  if (*field != nullptr)
    delete *field;

  if (newValue != nullptr)
  {
    // Include the terminating null character
    size_t length = strlen(newValue) + 1;

    if (length > 0)
    {
      *field = new char[length];
      strncpy(*field, newValue, length);
    }
    else
      *field = nullptr;
  }
  else
    *field = nullptr;
}


bool sameStr(const char* value1, const char* value2)
{
  if ((value1 == nullptr) != (value2 == nullptr))
    return true;

  if (value1 == nullptr)
    return false;

  return strcmp(value1, value2) == 0;
}