Exemplo n.º 1
0
        public static Script Parse(string scriptString)
        {
            var           atoms    = scriptString.Split(' ');
            var           script   = new Script();
            StringBuilder valueStr = null;

            foreach (var atom in atoms)
            {
                IScriptAtom newAtom = null;
                if (valueStr != null)
                {
                    valueStr.Append(" ");
                    if (atom.EndsWith("'"))
                    {
                        if (atom.EndsWith(@"\''"))
                        {
                            valueStr.Append(atom.Substring(0, atom.Length - 3));
                            valueStr.Append("'");
                            var valueBytes = Encoding.ASCII.GetBytes(valueStr.ToString());
                            newAtom = new ValueAtom(valueBytes);
                            script.Atoms.Add(newAtom);
                            valueStr = null;
                        }
                        else if (atom.EndsWith(@"\'"))
                        {
                            valueStr.Append(atom.Substring(0, atom.Length - 2));
                            valueStr.Append("'");
                        }
                        else
                        {
                            valueStr.Append(atom.Substring(0, atom.Length - 1));
                            var valueBytes = Encoding.ASCII.GetBytes(valueStr.ToString());
                            newAtom = new ValueAtom(valueBytes);
                            script.Atoms.Add(newAtom);
                            valueStr = null;
                        }
                    }
                    else
                    {
                        valueStr.Append(atom);
                    }
                    continue;
                }
                if (atom.StartsWith("OP_"))
                {
                    var opcode = (ScriptOpCode)Enum.Parse(typeof(ScriptOpCode), atom, false);
                    newAtom = ScriptAtomFactory.GetOpAtom(opcode);
                }
                else if (atom.StartsWith("'"))
                {
                    if (atom.EndsWith("'"))
                    {
                        if (atom.EndsWith(@"\''"))
                        {
                            var valueBytes = Encoding.ASCII.GetBytes(atom.Substring(1, atom.Length - 4) + "'");
                            newAtom = new ValueAtom(valueBytes);
                        }
                        else if (atom.EndsWith(@"\'"))
                        {
                            valueStr = new StringBuilder();
                            valueStr.Append(atom.Substring(1, atom.Length - 3));
                            valueStr.Append("'");
                        }
                        else if (atom.Length > 1)
                        {
                            if (atom.Length > 2)
                            {
                                var valueBytes = Encoding.ASCII.GetBytes(atom.Substring(1, atom.Length - 2));
                                newAtom = new ValueAtom(valueBytes);
                            }
                        }
                        else
                        {
                            valueStr = new StringBuilder();
                        }
                    }
                    else
                    {
                        valueStr = new StringBuilder();
                        valueStr.Append(atom.Substring(1, atom.Length - 1));
                    }
                }
                else if (atom.Length > 0)
                {
                    var valueBytes = BufferOperations.FromByteString(atom, Endianness.BigEndian);
                    newAtom = new ValueAtom(valueBytes);
                }
                if (newAtom != null)
                {
                    script.Atoms.Add(newAtom);
                }
            }
            if (valueStr != null)
            {
                throw new FormatException("Unclosed script string found");
            }
            script.Freeze();
            return(script);
        }
Exemplo n.º 2
0
 public abstract bool Equals(IScriptAtom other);
Exemplo n.º 3
0
 public sealed override bool Equals(IScriptAtom other)
 {
     return(this.Equals(other as OpAtom));
 }
Exemplo n.º 4
0
 public override bool Equals(IScriptAtom other)
 {
     return default(bool);
 }
Exemplo n.º 5
0
 public abstract bool Equals(IScriptAtom other);
Exemplo n.º 6
0
 public override bool Equals(IScriptAtom other)
 {
     return(default(bool));
 }
Exemplo n.º 7
0
 public override bool Equals(IScriptAtom other)
 {
     return(this.Equals(other as ValueAtom));
 }