本文整理汇总了C#中MutableString.GetChar方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.GetChar方法的具体用法?C# MutableString.GetChar怎么用?C# MutableString.GetChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.GetChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendEscapeForwardSlash
internal static MutableString/*!*/ AppendEscapeForwardSlash(MutableString/*!*/ result, MutableString/*!*/ pattern) {
int first = 0;
int i = SkipToUnescapedForwardSlash(pattern, 0);
while (i >= 0) {
Debug.Assert(i < pattern.Length);
Debug.Assert(pattern.GetChar(i) == '/' && (i == 0 || pattern.GetChar(i - 1) != '\\'));
result.Append(pattern, first, i - first);
result.Append('\\');
first = i; // include forward slash in the next append
i = SkipToUnescapedForwardSlash(pattern, i + 1);
}
result.Append(pattern, first, pattern.Length - first);
return result;
}
示例2: InternalChomp
private static MutableString InternalChomp(MutableString/*!*/ self, MutableString separator) {
if (separator == null) {
return self.Clone();
}
// Remove multiple trailing CR/LFs
if (separator.Length == 0) {
return ChompTrailingCarriageReturns(self, false).TaintBy(self);
}
// Remove single trailing CR/LFs
MutableString result = self.Clone();
int length = result.Length;
if (separator.Length == 1 && separator.GetChar(0) == '\n') {
if (length > 1 && result.GetChar(length - 2) == '\r' && result.GetChar(length - 1) == '\n') {
result.Remove(length - 2, 2);
} else if (length > 0 && (self.GetChar(length - 1) == '\n' || result.GetChar(length - 1) == '\r')) {
result.Remove(length - 1, 1);
}
} else if (EndsWith(result, separator)) {
result.Remove(length - separator.Length, separator.Length);
}
return result;
}
示例3: Create
public static CharacterMap/*!*/ Create(MutableString/*!*/ from, MutableString/*!*/ to) {
Debug.Assert(!from.IsEmpty);
int fromLength = from.GetCharCount();
bool complemental = from.StartsWith('^') && fromLength > 1;
// TODO: kcodings
// TODO: surrogates
// TODO: max - min > threshold
int min, max;
if (from.IsBinaryEncoded || from.IsAscii()) {
min = 0;
max = 255;
} else {
min = Int32.MaxValue;
max = -1;
for (int i = (complemental ? 1 : 0); i < fromLength; i++) {
int c = from.GetChar(i);
if (c < min) {
min = c;
}
if (c > max) {
max = c;
}
}
}
BitArray map;
char[] image;
if (complemental || to.IsEmpty) {
image = null;
map = MakeBitmap(from, fromLength, complemental, min, max);
} else {
map = null;
image = new char[max - min + 1];
// no need to initialize the array:
Debug.Assert(Unmapped == 0);
bool needMap = false;
var toEnum = ExpandRanges(to, 0, to.GetCharCount(), true).GetEnumerator();
foreach (var f in ExpandRanges(from, 0, fromLength, false)) {
toEnum.MoveNext();
needMap |= (image[f - min] = toEnum.Current) == Unmapped;
}
if (needMap) {
map = MakeBitmap(from, fromLength, false, min, max);
}
}
return new CharacterMap(map, image, complemental ? to.GetLastChar() : -1, complemental, min, max);
}
示例4: SwapCaseChar
public static bool SwapCaseChar(MutableString/*!*/ self, int index) {
char current = self.GetChar(index);
if (current >= 'A' && current <= 'Z') {
self.SetChar(index, Char.ToLower(current));
return true;
} else if (current >= 'a' && current <= 'z') {
self.SetChar(index, Char.ToUpper(current));
return true;
}
return false;
}
示例5: EndsWith
private static bool EndsWith(MutableString/*!*/ str, MutableString/*!*/ terminator) {
int offset = str.Length - terminator.Length;
if (offset < 0) {
return false;
}
if (str.IsBinary) {
for (int i = 0; i < terminator.Length; i++) {
if (str.GetChar(offset + i) != terminator.GetChar(i)) {
return false;
}
}
} else {
for (int i = 0; i < terminator.Length; i++) {
if (str.GetByte(offset + i) != terminator.GetByte(i)) {
return false;
}
}
}
return true;
}
示例6: GetTrimRange
private static void GetTrimRange(MutableString/*!*/ str, bool left, bool right, out int leftIndex, out int rightIndex) {
GetTrimRange(
str.Length,
!left ? (Func<int, bool>)null : (i) => Char.IsWhiteSpace(str.GetChar(i)),
!right ? (Func<int, bool>)null : (i) => {
char c = str.GetChar(i);
return Char.IsWhiteSpace(c) || c == '\0';
},
out leftIndex,
out rightIndex
);
}
示例7: 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("_", "");
}
示例8: DownCaseChar
public static bool DownCaseChar(MutableString/*!*/ self, int index) {
char current = self.GetChar(index);
if (current >= 'A' && current <= 'Z') {
self.SetChar(index, current.ToLowerInvariant());
return true;
}
return false;
}
示例9: StringToRegexEncoding
internal static RubyRegexOptions StringToRegexEncoding(MutableString encoding) {
if (MutableString.IsNullOrEmpty(encoding)) {
return RubyRegexOptions.NONE;
}
switch (encoding.GetChar(0)) {
case 'N':
case 'n': return RubyRegexOptions.FIXED;
case 'E':
case 'e': return RubyRegexOptions.EUC;
case 'S':
case 's': return RubyRegexOptions.SJIS;
case 'U':
case 'u': return RubyRegexOptions.UTF8;
}
return RubyRegexOptions.NONE;
}
示例10: 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);
}
}
示例11: Ord
public static int Ord(MutableString/*!*/ str) {
if (str.IsEmpty) {
throw RubyExceptions.CreateArgumentError("empty string");
}
char c1 = str.GetChar(0);
if (!Char.IsSurrogate(c1)) {
return (int)c1;
}
char c2;
if (Tokenizer.IsHighSurrogate(c1) && str.GetCharCount() > 1 && Tokenizer.IsLowSurrogate(c2 = str.GetChar(1))) {
return Tokenizer.ToCodePoint(c1, c2);
}
throw RubyExceptions.CreateArgumentError("invalid byte sequence in {0}", str.Encoding);
}
示例12: 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);
}
示例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, 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);
}
}
示例14: 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);
}
}
示例15: IncrementAlphaNumericChar
// TODO: remove recursion
public static void IncrementAlphaNumericChar(MutableString/*!*/ str, int index) {
char c = str.GetChar(index);
if (c == 'z' || c == 'Z' || c == '9') {
int nextIndex = GetIndexOfRightmostAlphaNumericCharacter(str, index - 1);
if (c == 'z') {
str.SetChar(index, 'a');
if (nextIndex == -1)
str.Insert(index, "a");
else
IncrementAlphaNumericChar(str, nextIndex);
} else if (c == 'Z') {
str.SetChar(index, 'A');
if (nextIndex == -1)
str.Insert(index, "A");
else
IncrementAlphaNumericChar(str, nextIndex);
} else {
str.SetChar(index, '0');
if (nextIndex == -1)
str.Insert(index, "1");
else
IncrementAlphaNumericChar(str, nextIndex);
}
} else {
IncrementChar(str, index);
}
}