当前位置: 首页>>代码示例>>C#>>正文


C# MutableString.GetSlice方法代码示例

本文整理汇总了C#中MutableString.GetSlice方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.GetSlice方法的具体用法?C# MutableString.GetSlice怎么用?C# MutableString.GetSlice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MutableString的用法示例。


在下文中一共展示了MutableString.GetSlice方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StripWhitespace

 private static string/*!*/ StripWhitespace(MutableString/*!*/ str) {
     int i = 0;
     while (i < str.Length) {
         char c = str.GetChar(i);
         if (c == ' ' || c == '_' || c == '\t' || c == '\n' || c == '\r') {
             i += 1;
         } else {
             return str.GetSlice(i).ConvertToString().Replace("_", "");
         }
     }
     return str.ConvertToString().Replace("_", "");
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:12,代码来源:MutableStringOps.cs

示例2: ChompTrailingCarriageReturns

 private static MutableString/*!*/ ChompTrailingCarriageReturns(MutableString/*!*/ str, bool removeCarriageReturnsToo) {
     int end = str.Length;
     while (true) {
         if (end > 1) {
             if (str.GetChar(end - 1) == '\n') {
                 end -= str.GetChar(end - 2) == '\r' ? 2 : 1;
             } else if (removeCarriageReturnsToo && str.GetChar(end - 1) == '\r') {
                 end -= 1;
             }
             else {
                 break;
             }
         } else if (end > 0) {
             if (str.GetChar(end - 1) == '\n' || str.GetChar(end - 1) == '\r') {
                 end -= 1;
             }
             break;
         } else {
             break;
         }
     }
     return str.GetSlice(0, end);
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:23,代码来源:MutableStringOps.cs

示例3: ReadString

        /*!*/
        private static MutableString ReadString(MutableString/*!*/ data, int trimMode, int? count, ref int offset)
        {
            int start = offset;
            int e = data.GetByteCount();
            if (count.HasValue) {
                int end = start + count.Value;
                if (end < e) {
                    e = end;
                }
            }

            offset = e;
            byte b;
            switch (trimMode) {
                case 'A':
                    while (--e >= start && ((b = data.GetByte(e)) == 0 || b == ' ')) { }
                    e++;
                    break;

                case 'Z':
                    int i = start;
                    while (i < e && data.GetByte(i) != 0) { i++; }
                    if (!count.HasValue) {
                        offset = i + 1;
                    }
                    e = i;
                    break;
            }

            return data.GetSlice(start, e - start);
        }
开发者ID:TerabyteX,项目名称:main,代码行数:32,代码来源:RubyEncoder.cs

示例4: Strip

 private static MutableString/*!*/ Strip(MutableString/*!*/ str, bool trimLeft, bool trimRight) {
     int left, right;
     GetTrimRange(str, trimLeft, trimRight, out left, out right);
     return str.GetSlice(left, right - left).TaintBy(str);
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:5,代码来源:MutableStringOps.cs

示例5: StartsWith

        public static bool StartsWith(RubyScope/*!*/ scope, MutableString/*!*/ self,
            [DefaultProtocol, Optional]MutableString subString) {

            // TODO: Deal with encodings

            if (subString == null || (self.Length < subString.Length)) {
                return false;
            }
            return self.GetSlice(0, subString.Length).Equals(subString);
        }
开发者ID:,项目名称:,代码行数:10,代码来源:

示例6: GetChar

 public static MutableString GetChar(MutableString/*!*/ self, [DefaultProtocol]int index) {
     return InExclusiveRangeNormalized(self.GetCharCount(), ref index) ? self.GetSlice(index, 1) : null;
 }
开发者ID:,项目名称:,代码行数:3,代码来源:

示例7: ReadLine

        private static MutableString ReadLine(MutableString/*!*/ content, MutableString separator, ref int position) {
            int length = content.GetByteCount();
            if (position >= length) {
                return null;
            }

            int oldPosition = position;

            if (separator == null) {
                position = length;
            } else if (separator.IsEmpty) {
                // skip initial ends of line:
                while (oldPosition < length && content.GetByte(oldPosition) == '\n') {
                    oldPosition++;
                }

                position = content.IndexOf(ParagraphSeparator, oldPosition);
                position = (position != -1) ? position + 1 : length;
            } else {
                position = content.IndexOf(separator, oldPosition);
                position = (position != -1) ? position + separator.Length : length;
            }

            return content.GetSlice(oldPosition, position - oldPosition);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:25,代码来源:StringIO.cs

示例8: CheckOpenPipe

        private static RubyIO CheckOpenPipe(RubyContext/*!*/ context, MutableString path, IOMode mode) {
            string fileName = path.ConvertToString();
            if (fileName.Length > 0 && fileName[0] == '|') {
#if SILVERLIGHT
                throw new NotSupportedException("open cannot create a subprocess");
#else
                if (fileName.Length > 1 && fileName[1] == '-') {
                    throw new NotImplementedError("forking a process is not supported");
                }
                return RubyIOOps.OpenPipe(context, path.GetSlice(1), (IOMode)mode);
#endif
            }
            return null;
        }
开发者ID:yarrow2,项目名称:ironruby,代码行数:14,代码来源:KernelOps.cs

示例9: ExpandPath

        // 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;
            bool raisingRubyException = false;
            try {
                if (path == null || length == 0)
                    return RubyUtils.CanonicalizePath(MutableString.Create(Directory.GetCurrentDirectory()));

                if (path.GetChar(0) == '~') {
                    if (length == 1 || (path.GetChar(1) == Path.DirectorySeparatorChar ||
                                        path.GetChar(1) == Path.AltDirectorySeparatorChar)) {

                        string homeDirectory = pal.GetEnvironmentVariable("HOME");
                        if (homeDirectory == null) {
                            raisingRubyException = true;
                            throw RubyExceptions.CreateArgumentError("couldn't find HOME environment -- expanding `~'");
                        }
                        if (length <= 2) {
                            path = MutableString.Create(homeDirectory);
                        } else {
                            path = MutableString.Create(Path.Combine(homeDirectory, path.GetSlice(2).ConvertToString()));
                        }
                        return RubyUtils.CanonicalizePath(path);
                    } else {
                        return path;
                    }
                } else {
                    string pathStr = path.ConvertToString();
                    MutableString result = RubyUtils.CanonicalizePath(MutableString.Create(Path.GetFullPath(pathStr)));

                    // Path.GetFullPath("c:/winDOWS/foo") returns "c:/winDOWS/foo", but Path.GetFullPath("c:/winDOWS/~") returns "c:/Windows/~".
                    // So we special-case it as this is not the Ruby behavior. Also, the Ruby behavior is very complicated about when it
                    // matches the case of the input argument, and when it matches the case of the file system. It can match the file system case
                    // for part of the result and not the rest. So we restrict the special-case to a very limited scenarios that unblock real-world code.
                    if (pathStr[pathStr.Length - 1] == '~' && String.Compare(pathStr, result.ConvertToString(), true) == 0) {
                        result = path.Clone();
                    }

                    return result;
                }
            } catch (Exception e) {
                if (raisingRubyException) {
                    throw;
                }
                // Re-throw exception as a reasonable Ruby exception
                throw RubyErrno.CreateEINVAL(path.ConvertToString(), e);
            }
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:59,代码来源:FileOps.cs

示例10: TrimTrailingSlashes

 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);
 }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:9,代码来源:FileOps.cs

示例11: ExpandPath

        // 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);
            }
        }
开发者ID:tnachen,项目名称:ironruby,代码行数:32,代码来源:FileOps.cs

示例12: ExpandPath

        // 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;
            bool raisingRubyException = false;
            try {
                if (path == null || length == 0)
                    return Glob.CanonicalizePath(MutableString.Create(Directory.GetCurrentDirectory()));

                if (path.GetChar(0) == '~') {
                    if (length == 1 || (path.GetChar(1) == Path.DirectorySeparatorChar ||
                                        path.GetChar(1) == Path.AltDirectorySeparatorChar)) {

                        string homeDirectory = pal.GetEnvironmentVariable("HOME");
                        if (homeDirectory == null) {
                            raisingRubyException = true;
                            throw RubyExceptions.CreateArgumentError("couldn't find HOME environment -- expanding `~'");
                        }
                        if (length <= 2) {
                            path = MutableString.Create(homeDirectory);
                        } else {
                            path = MutableString.Create(Path.Combine(homeDirectory, path.GetSlice(2).ConvertToString()));
                        }
                        return Glob.CanonicalizePath(path);
                    } else {
                        return path;
                    }
                } else {
                    return Glob.CanonicalizePath(MutableString.Create(Path.GetFullPath(path.ConvertToString())));
                }
            } catch (Exception e) {
                if (raisingRubyException) {
                    throw;
                }
                // Re-throw exception as a reasonable Ruby exception
                throw new Errno.InvalidError(path.ConvertToString(), e);
            }
        }
开发者ID:MiguelMadero,项目名称:ironruby,代码行数:48,代码来源:FileOps.cs

示例13: ExpandPath

        // 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, RubyClass/*!*/ self, MutableString/*!*/ path) {
            if (MutableString.IsNullOrEmpty(path)) {
                return MutableString.Create(RubyUtils.CanonicalizePath(context.DomainManager.Platform.CurrentDirectory));
            }

            int length = path.Length;

            if (path.GetChar(0) == '~') {
                if (length == 1 || (path.GetChar(1) == '/')) {

                    string homeDirectory = context.DomainManager.Platform.GetEnvironmentVariable("HOME");
                    if (homeDirectory == null) {
                        throw RubyExceptions.CreateArgumentError("couldn't find HOME environment -- expanding `~'");
                    }

                    if (length <= 2) {
                        path = MutableString.Create(homeDirectory);
                    } else {
                        path = MutableString.Create(Path.Combine(homeDirectory, path.GetSlice(2).ConvertToString()));
                    }
                    return RubyUtils.CanonicalizePath(path);
                } else {
                    return path;
                }
            } else {
                MutableString currentDirectory = ExpandPath(context, self, null);
                return ExpandPath(context, self, path, currentDirectory);
            }
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:40,代码来源:FileOps.cs


注:本文中的MutableString.GetSlice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。