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


C# MutableString.ToByteArray方法代码示例

本文整理汇总了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());
 }
开发者ID:nrk,项目名称:ironruby-hpricot,代码行数:8,代码来源:BuiltinsOps.cs

示例2: GetBytePtr

 public static unsafe IntPtr GetBytePtr(MutableString str)
 {
     IntPtr pp;
       fixed (byte* bp = str.ToByteArray())
       {
     pp = (IntPtr)bp;
       }
       return pp;
 }
开发者ID:trietptm,项目名称:retoolkit,代码行数:9,代码来源:Helpers.cs

示例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;
        }
开发者ID:nrk,项目名称:ironruby-json,代码行数:16,代码来源:Generator.String.cs

示例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;
 }
开发者ID:nrk,项目名称:ironruby-json,代码行数:47,代码来源:Generator.String.cs

示例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;
                }
开发者ID:jschementi,项目名称:iron,代码行数:9,代码来源:OpenSSL.cs

示例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);
 }
开发者ID:jcteague,项目名称:ironruby,代码行数:5,代码来源:RubyIO.cs

示例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);
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:12,代码来源:MutableStringOps.cs

示例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);
            }
开发者ID:TerabyteX,项目名称:main,代码行数:48,代码来源:zlib.cs

示例9: WriteStringValue

 private void WriteStringValue(MutableString/*!*/ value) {
     byte[] data = value.ToByteArray();
     WriteInt32(data.Length);
     _writer.Write(data);
 }
开发者ID:rafacv,项目名称:iron_languages,代码行数:5,代码来源:Marshal.cs

示例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);
     }
 }
开发者ID:TerabyteX,项目名称:main,代码行数:24,代码来源:RubyEncoder.cs

示例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;
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:12,代码来源:MutableStringOps.cs

示例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');
 }
开发者ID:teejayvanslyke,项目名称:ironruby,代码行数:10,代码来源:RubyOps.cs

示例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
            );
        }
开发者ID:TerabyteX,项目名称:main,代码行数:33,代码来源:BuiltinsOps.cs


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