string to upper case

No locale is used. Strictly English conversion

Download touppercase.zip

Synopsis:

touppercase.cpp


touppercase.cpp

Synopsis
#include <string>
#include <algorithm>
using namespace std;

#include "utx.h"

string toUpperCase(const string& s)
  {
  string s1 = s;
  transform(s1.begin(), s1.end(), s1.begin(), toupper);
  return s1;
  }

void toUpperCaseInPlace(string& s)
  {
  transform(s.begin(), s.end(), s.begin(), toupper);
  }

TEST(uppercase)
  {
  string s = "aBc";
  utxassert(toUpperCase(s), "ABC");
  utxassert(toUpperCase(string("CDE")), "CDE");
  }

TEST(uppercaseInPlace)
  {
  string s = "aBc";
  toUpperCaseInPlace(s);
  utxassert(s, "ABC");
  s = "CDE";
  toUpperCaseInPlace(s);
  utxassert(s, "CDE");
  }






Contact me about content on this page using john_web-at-arrizza-dot-com
For Web Master or site problems contact: webadmin-at-arrizza-dot-com
Copyright John Arrizza (c) 2001-2010