// Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library filenames;

import 'dart:io';

// For information about how to convert Windows file names to URIs:
// http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx

String nativeToUriPath(String filename) {
  // TODO(ahe): It would be nice to use a Dart library instead.
  if (Platform.isWindows) return filename;
  filename = filename.replaceAll('\\', '/');
  if (filename.length > 2 && filename[1] == ':') {
    filename = "/$filename";
  }
  return filename;
}

String uriPathToNative(String path) {
  // TODO(ahe): It would be nice to use a Dart library instead.
  if (Platform.operatingSystem != 'windows') return path;
  if (path.length > 3 && path[0] == '/' && path[2] == ':') {
    return path.substring(1).replaceAll('/', '\\');
  } else {
    return path.replaceAll('/', '\\');
  }
}

final Uri currentDirectory = new Uri(
    scheme: 'file',
    path: appendSlash(nativeToUriPath(new File('.').fullPathSync())));

String appendSlash(String path) => path.endsWith('/') ? path : '$path/';

// Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library filenames;

import 'dart:io';

// For information about how to convert Windows file names to URIs:
// http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx

String nativeToUriPath(String filename) {
  // TODO(ahe): It would be nice to use a Dart library instead.
  if (!Platform.isWindows) return filename;
  filename = filename.replaceAll('\\', '/');
  if (filename.length > 2 && filename[1] == ':') {
    filename = "/$filename";
  }
  return filename;
}

String uriPathToNative(String path) {
  // TODO(ahe): It would be nice to use a Dart library instead.
  if (!Platform.isWindows) return filename;
  if (path.length > 3 && path[0] == '/' && path[2] == ':') {
    return path.substring(1).replaceAll('/', '\\');
  } else {
    return path.replaceAll('/', '\\');
  }
}

final Uri currentDirectory = new Uri(
    scheme: 'file',
    path: appendSlash(nativeToUriPath(new File('.').fullPathSync())));

String appendSlash(String path) => path.endsWith('/') ? path : '$path/';

Fix bad rewrite of boolean expression
Fix bad rewrite of boolean expression

Review URL: https://codereview.chromium.org//20020003

git-svn-id: c93d8a2297af3b929165606efe145742a534bc71@25402 260f80e4-7a28-3924-810f-c04153c831b5
