本文整理汇总了C#中MutableString.ToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.ToByteArray方法的具体用法?C# MutableString.ToByteArray怎么用?C# MutableString.ToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.ToByteArray方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FastXs
public static MutableString FastXs(RubyContext/*!*/ context, MutableString/*!*/ self)
{
//TODO: we are assuming that every string is UTF8, but this is wrong
String utf8String = Encoding.UTF8.GetString(self.ToByteArray());
StringBuilder builder = new StringBuilder((int)(utf8String.Length * 1.5));
Entities.XML.Escape(builder, utf8String);
return MutableString.CreateAscii(builder.ToString());
}
示例2: GetBytePtr
public static unsafe IntPtr GetBytePtr(MutableString str)
{
IntPtr pp;
fixed (byte* bp = str.ToByteArray())
{
pp = (IntPtr)bp;
}
return pp;
}
示例3: ToJsonRawObject
public static Hash ToJsonRawObject(RubyScope scope, MutableString self)
{
byte[] selfBuffer = self.ToByteArray();
var array = new RubyArray(selfBuffer.Length);
foreach (byte b in selfBuffer) {
array.Add(b & 0xFF);
}
var context = scope.RubyContext;
var result = new Hash(context);
var createId = Helpers.GetCreateId(scope);
result.Add(createId, MutableString.Create(context.GetClassName(self), RubyEncoding.Binary));
result.Add(MutableString.CreateAscii("raw"), array);
return result;
}
示例4: ToJson
public static MutableString ToJson(MutableString self)
{
MutableString result = MutableString.CreateMutable(self.Length + 2, RubyEncoding.UTF8);
char[] chars = Encoding.UTF8.GetChars(self.ToByteArray());
byte[] escapeSequence = new byte[] { (byte)'\\', 0 };
result.Append('"');
foreach (char c in chars) {
switch (c) {
case '"':
case '/':
case '\\':
escapeSequence[1] = (byte)c;
result.Append(escapeSequence);
break;
case '\n':
escapeSequence[1] = (byte)'n';
result.Append(escapeSequence);
break;
case '\r':
escapeSequence[1] = (byte)'r';
result.Append(escapeSequence);
break;
case '\t':
escapeSequence[1] = (byte)'t';
result.Append(escapeSequence);
break;
case '\f':
escapeSequence[1] = (byte)'f';
result.Append(escapeSequence);
break;
case '\b':
escapeSequence[1] = (byte)'b';
result.Append(escapeSequence);
break;
default:
if (c >= 0x20 && c <= 0x7F) {
result.Append((byte)c);
}
else {
result.Append(Helpers.EscapeUnicodeChar(c));
}
break;
}
}
result.Append('"');
return result;
}
示例5: Initialize
public static Certificate/*!*/ Initialize(Certificate/*!*/ self, MutableString/*!*/ data) {
if (data == null) {
self._certificate = new X509Certificate();
} else {
self._certificate = new X509Certificate(data.ToByteArray());
}
return self;
}
示例6: Write
// returns the number of bytes written to the stream:
public int Write(MutableString/*!*/ value) {
byte[] bytes = value.ToByteArray();
return Write(bytes, 0, bytes.Length);
}
示例7: Dump
public static MutableString/*!*/ Dump(RubyContext/*!*/ context, MutableString/*!*/ self) {
StringBuilder result = new StringBuilder();
result.Append('"');
byte[] bytes = self.ToByteArray();
for (int i = 0; i < bytes.Length; i++) {
AppendStringRepresentationOfChar(result, bytes[i], i + 1 < bytes.Length ? bytes[i + 1] : -1, true);
}
result.Append('"');
return self.CreateInstance().Append(result).TaintBy(self);
}
示例8: Process
internal static int Process(zlib.ZStream/*!*/ zst, MutableString str, zlib.FlushStrategy flush, bool compress,
ref MutableString trailingUncompressedData)
{
if (str == null) {
str = MutableString.FrozenEmpty;
flush = zlib.FlushStrategy.Z_FINISH;
} else if (str.Length == 0 && flush == NO_FLUSH) {
return Z_OK;
}
// data still available from previous input:
if (zst.avail_in > 0) {
int err = Process(zst, flush, compress, ref trailingUncompressedData);
// double flush:
if (compress && flush != zlib.FlushStrategy.Z_FINISH && err == (int)zlib.ZLibResultCode.Z_DATA_ERROR) {
return Z_OK;
}
// append new input to the current input:
if (err != Z_OK && err != Z_STREAM_END) {
byte[] currentInput = zst.next_in;
byte[] newInput = str.ToByteArray();
int minLength = zst.next_in_index + zst.avail_in + newInput.Length;
if (currentInput.Length < minLength) {
Array.Resize(ref currentInput, Math.Max(currentInput.Length * 2, minLength));
}
Buffer.BlockCopy(newInput, 0, currentInput, zst.next_in_index + zst.avail_in, newInput.Length);
zst.next_in = currentInput;
zst.avail_in += newInput.Length;
return err;
}
}
if (str != null) {
byte[] input = str.ToByteArray();
zst.next_in = input;
zst.next_in_index = 0;
zst.avail_in = input.Length;
} else {
zst.avail_in = 0;
}
return Process(zst, flush, compress, ref trailingUncompressedData);
}
示例9: WriteStringValue
private void WriteStringValue(MutableString/*!*/ value) {
byte[] data = value.ToByteArray();
WriteInt32(data.Length);
_writer.Write(data);
}
示例10: WriteString
private static void WriteString(Stream/*!*/ stream, FormatDirective directive, MutableString str)
{
// TODO (opt): unneccessary copy of byte[]
byte[] bytes = str != null ? str.ToByteArray() : Utils.EmptyBytes;
int dataLen;
int paddedLen;
if (directive.Count.HasValue) {
paddedLen = directive.Count.Value;
dataLen = Math.Min(bytes.Length, paddedLen);
} else {
paddedLen = bytes.Length;
dataLen = bytes.Length;
}
stream.Write(bytes, 0, dataLen);
if (paddedLen > dataLen) {
byte fill = (directive.Directive == 'A') ? (byte)' ' : (byte)0;
for (int j = 0; j < (paddedLen - dataLen); j++) {
stream.WriteByte(fill);
}
}
if (directive.Directive == 'Z' && !directive.Count.HasValue) {
stream.WriteByte((byte)0);
}
}
示例11: Dump
private static StringBuilder/*!*/ Dump(MutableString/*!*/ self) {
StringBuilder result = new StringBuilder();
result.Append('"');
byte[] bytes = self.ToByteArray();
for (int i = 0; i < bytes.Length; i++) {
AppendStringRepresentationOfChar(result, bytes[i], i + 1 < bytes.Length ? bytes[i + 1] : -1, true);
}
result.Append('"');
return result;
}
示例12: PrintInteractiveResult
public static void PrintInteractiveResult(RubyScope/*!*/ scope, MutableString/*!*/ value) {
var writer = scope.RubyContext.DomainManager.SharedIO.OutputStream;
writer.WriteByte((byte)'=');
writer.WriteByte((byte)'>');
writer.WriteByte((byte)' ');
var bytes = value.ToByteArray();
writer.Write(bytes, 0, bytes.Length);
writer.WriteByte((byte)'\r');
writer.WriteByte((byte)'\n');
}
示例13: ToYamlNode
public static Node ToYamlNode(MutableString/*!*/ self, [NotNull]RubyRepresenter/*!*/ rep)
{
if (!self.IsEmpty && ContainsBinaryData(self)) {
return rep.BaseCreateNode(self.ToByteArray());
}
Debug.Assert(self.IsAscii());
string str = self.ToString();
ScalarQuotingStyle style = ScalarQuotingStyle.None;
if (str.StartsWith(":", StringComparison.Ordinal)) {
style = ScalarQuotingStyle.Double;
} else {
style = rep.GetYamlStyle(self);
}
var tag = rep.GetTagUri(self, Tags.Str, typeof(MutableString));
IList instanceVariableNames = rep.ToYamlProperties(self);
if (instanceVariableNames.Count == 0) {
return rep.Scalar(tag, str, style);
}
var map = new Dictionary<object, object>();
rep.AddYamlProperties(map, self, instanceVariableNames, false);
return rep.Map(
new Dictionary<Node, Node> {
{ rep.Scalar(null, "str", style), rep.Scalar(null, str, style) }
},
tag,
map,
FlowStyle.Block
);
}