本文整理汇总了C#中MutableString.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.Clone方法的具体用法?C# MutableString.Clone怎么用?C# MutableString.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ICloneable_op_Clone
public void ICloneable_op_Clone()
{
ICloneable expected = new MutableString("One");
var actual = expected.Clone();
Assert.Equal(expected, actual);
Assert.NotSame(expected, actual);
}
示例2: MatchData
private MatchData(Match/*!*/ match, MutableString/*!*/ originalString, int[] kIndices) {
Debug.Assert(match.Success);
_match = match;
// TODO (opt): create groups instead?
_originalString = originalString.Clone().Freeze();
_kIndices = kIndices;
IsTainted = originalString.IsTainted;
}
示例3: BlockReplaceAll
public static object BlockReplaceAll(ConversionStorage<MutableString>/*!*/ tosConversion,
RubyScope/*!*/ scope, [NotNull]BlockParam/*!*/ block, MutableString/*!*/ self,
[NotNull]RubyRegex pattern)
{
object blockResult;
MutableString result;
self.TrackChanges();
object r = BlockReplaceAll(tosConversion, scope, self, block, pattern, out blockResult, out result) ? blockResult : (result ?? self.Clone());
RequireNoVersionChange(self);
return r;
}
示例4: UpCase
public static MutableString/*!*/ UpCase(MutableString/*!*/ self) {
MutableString result = self.Clone();
UpCaseMutableString(result);
return result;
}
示例5: RemoveSubstringInPlace
public static MutableString RemoveSubstringInPlace(RubyScope/*!*/ scope, MutableString/*!*/ self,
[NotNull]RubyRegex/*!*/ regex, [DefaultProtocol]int occurrance) {
if (regex.IsEmpty) {
return self.Clone().TaintBy(regex, scope);
}
Group group = MatchRegexp(scope, self, regex, occurrance);
return group == null ? null : RemoveSubstringInPlace(self, group.Index, group.Length).TaintBy(regex, scope);
}
示例6: LeftJustify
public static MutableString/*!*/ LeftJustify(MutableString/*!*/ self,
[DefaultProtocol]int width, [DefaultProtocol, NotNull]MutableString/*!*/ padding) {
if (padding.Length == 0) {
throw RubyExceptions.CreateArgumentError("zero width padding");
}
int count = width - self.Length;
if (count <= 0) {
return self;
}
int iterations = count / padding.Length;
int remainder = count % padding.Length;
MutableString result = self.Clone().TaintBy(padding);
for (int i = 0; i < iterations; i++) {
result.Append(padding);
}
result.Append(padding, 0, remainder);
return result;
}
示例7: Squeeze
public static MutableString/*!*/ Squeeze(RubyContext/*!*/ context, MutableString/*!*/ self, [NotNull]params object[] args) {
MutableString result = self.Clone();
SqueezeMutableString(result, Protocols.CastToStrings(context, args));
return result;
}
示例8: ReplaceAll
public static MutableString ReplaceAll(RubyScope/*!*/ scope, MutableString/*!*/ self,
[DefaultProtocol, NotNull]RubyRegex/*!*/ pattern, [DefaultProtocol, NotNull]MutableString/*!*/ replacement) {
return ReplaceAll(scope, self, replacement, pattern) ?? self.Clone();
}
示例9: BlockReplaceFirst
public static object BlockReplaceFirst(RubyScope/*!*/ scope, [NotNull]BlockParam/*!*/ block, MutableString/*!*/ self,
[NotNull]MutableString matchString) {
object blockResult;
MutableString result;
var regex = new RubyRegex(Regex.Escape(matchString.ToString()), RubyRegexOptions.NONE);
return BlockReplaceFirst(scope, self, block, regex, out blockResult, out result) ? blockResult : (result ?? self.Clone());
}
示例10: ReplaceAll
public static MutableString/*!*/ ReplaceAll(ConversionStorage<MutableString>/*!*/ toS, BinaryOpStorage/*!*/ hashDefault, RubyScope/*!*/ scope, MutableString/*!*/ self,
[DefaultProtocol, NotNull]RubyRegex/*!*/ pattern, [DefaultProtocol, NotNull]Union<IDictionary<object, object>, MutableString>/*!*/ replacement) {
return ReplaceAll(toS, hashDefault, scope, self, replacement, pattern) ?? self.Clone();
}
示例11: Chop
public static MutableString/*!*/ Chop(MutableString/*!*/ self) {
return self.IsEmpty ? self.CreateInstance().TaintBy(self) : ChopInteral(self.Clone());
}
示例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 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);
}
}
示例13: LoadFile
/// <summary>
/// Returns <b>true</b> if a Ruby file is successfully loaded, <b>false</b> if it is already loaded.
/// </summary>
/// <param name="globalScope">
/// A scope against which the file should be executed or null to create a new scope.
/// </param>
/// <param name="self"></param>
/// <param name="path"></param>
/// <param name="flags"></param>
/// <param name="loaded"></param>
/// <returns>True if the file was loaded/executed by this call.</returns>
public bool LoadFile(Scope globalScope, object self, MutableString/*!*/ path, LoadFlags flags, out object loaded) {
Assert.NotNull(path);
string assemblyName, typeName;
string strPath = path.ConvertToString();
if (TryParseAssemblyName(strPath, out typeName, out assemblyName)) {
if (AlreadyLoaded(strPath, (string)null, flags)) {
loaded = ((flags & LoadFlags.ResolveLoaded) != 0) ? GetAssembly(assemblyName, true, false) : null;
return false;
}
Assembly assembly = LoadAssembly(assemblyName, typeName, false, false);
if (assembly != null) {
FileLoaded(path.Clone(), flags);
loaded = assembly;
return true;
}
}
return LoadFromPath(globalScope, self, strPath, path.Encoding, flags, out loaded);
}
示例14: FirstChar
public static MutableString FirstChar(MutableString/*!*/ self)
{
if (self.IsEmpty) {
return self.Clone();
}
// TODO: optimize
var enumerator = self.GetCharacters();
enumerator.MoveNext();
return enumerator.Current.ToMutableString(self.Encoding);
}
示例15: Encode
public static MutableString Encode(
ConversionStorage<IDictionary<object, object>>/*!*/ toHash,
ConversionStorage<MutableString>/*!*/ toStr,
MutableString/*!*/ self,
[Optional]object toEncoding,
[Optional]object fromEncoding,
[DefaultParameterValue(null), DefaultProtocol]IDictionary<object, object> options)
{
// TODO: optimize
return EncodeInPlace(toHash, toStr, self.Clone(), toEncoding, fromEncoding, options);
}