private static MutableString /*!*/ TrimTrailingSlashes(MutableString /*!*/ path) { int offset = path.Length - 1; while (offset > 0) { if (path.GetChar(offset) != '/' && path.GetChar(offset) != '\\') { break; } --offset; } return(path.GetSlice(0, offset + 1)); }
public MutableString /*!*/ GetSlice(int start) { return(_string.GetSlice(start)); }
// Expand directory path - these cases exist: // // 1. Empty string or nil means return current directory // 2. ~ with non-existent HOME directory throws exception // 3. ~, ~/ or ~\ which expands to HOME // 4. ~foo is left unexpanded // 5. Expand to full path if path is a relative path // // No attempt is made to determine whether the path is valid or not // Returned path is always canonicalized to forward slashes private static MutableString /*!*/ ExpandPath(RubyContext /*!*/ context, MutableString /*!*/ path) { PlatformAdaptationLayer pal = context.DomainManager.Platform; int length = path.Length; try { if (path == null || length == 0) { return(Glob.CanonicalizePath(MutableString.Create(Directory.GetCurrentDirectory()))); } if (length == 1 && path.GetChar(0) == '~') { return(Glob.CanonicalizePath(MutableString.Create(Path.GetFullPath(pal.GetEnvironmentVariable("HOME"))))); } if (path.GetChar(0) == '~' && (path.GetChar(1) == Path.DirectorySeparatorChar || path.GetChar(1) == Path.AltDirectorySeparatorChar)) { string homeDirectory = pal.GetEnvironmentVariable("HOME"); return(Glob.CanonicalizePath(length < 3 ? MutableString.Create(homeDirectory) : MutableString.Create(Path.Combine(homeDirectory, path.GetSlice(2).ConvertToString())))); } else { return(Glob.CanonicalizePath(MutableString.Create(Path.GetFullPath(path.ConvertToString())))); } } catch (Exception e) { // Re-throw exception as a reasonable Ruby exception throw new Errno.InvalidError(path.ConvertToString(), e); } }
public MutableString GetValue() { return(_match.Success ? _originalString.GetSlice(Index, Length).TaintBy(this) : null); }