setcase

A cli tool to transform text to uppercase and lowercase.


setcase

/

src

/

setcase.cc

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include "setcase.hh"

#include <string>

namespace OB
{

Setcase::Setcase(std::string const& str):
  str_ {str}
{
}

std::string Setcase::get(Setcase::ctype type)
{
  std::string out;

  if (type == Setcase::Lower)
  {
    out = to_lower(str_);
  }
  else
  {
    out = to_upper(str_);
  }

  return out;
}

char Setcase::to_lower(char c) const
{
  if (c >= 'A' && c <= 'Z')
  {
    c += 'a' - 'A';
  }
  return c;
}

char Setcase::to_upper(char c) const
{
  if (c >= 'a' && c <= 'z')
  {
    c += 'A' - 'a';
  }
  return c;
}

std::string Setcase::to_lower(std::string s) const
{
  for (char &c : s)
  {
    c = to_lower(c);
  }
  return s;
}

std::string Setcase::to_upper(std::string s) const
{
  for (char &c : s)
  {
    c = to_upper(c);
  }
  return s;
}

} // namespace OB
Back to Top