本文整理汇总了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("_", "");
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例6: GetChar
public static MutableString GetChar(MutableString/*!*/ self, [DefaultProtocol]int index) {
return InExclusiveRangeNormalized(self.GetCharCount(), ref index) ? self.GetSlice(index, 1) : null;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}