convert path to UNIX path

Convert all backward slashes into forward slashes.

Download tounixpath.zip

Synopsis:

tounixpath.cpp


tounixpath.cpp

Synopsis
#include <string>
#include <algorithm>
using namespace std;
#include "utx.h"

string toUnixPath(const string& path)
  {
  struct LocalFunc
    {
    static bool isBackSlash(char c) { return c == '\\'; }
    } ;
  string s = path;
  replace_if(s.begin(), s.end(), LocalFunc::isBackSlash, '/');
  return s;
  }

TEST(tup_identities)
  {
  utxassert(toUnixPath(""), "");
  utxassert(toUnixPath("x"), "x");
  utxassert(toUnixPath("c:/x"), "c:/x");
  }

TEST(tup_1)
  {
  utxassert(toUnixPath("x\\y"), "x/y");
  utxassert(toUnixPath("\\y"), "/y");
  utxassert(toUnixPath("x\\"), "x/");
  utxassert(toUnixPath("c:x\\"), "c:x/");
  utxassert(toUnixPath("\\"), "/");
  }







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