コード例 #1
0
        public static capex.text.XMLParser forFile(cape.File file)
        {
            if (!(file != null))
            {
                return(null);
            }
            var reader = file.read();

            if (!(reader != null))
            {
                return(null);
            }
            var v = new capex.text.XMLParser();

            v.it = (cape.CharacterIterator) new cape.CharacterIteratorForReader((cape.Reader)reader);
            return(v);
        }
コード例 #2
0
        public bool read(cape.File file)
        {
            if (!(file != null))
            {
                return(false);
            }
            var buf = new cape.PrintReader((cape.Reader)file.read());

            if (!(buf != null))
            {
                return(false);
            }
            var n = 0;

            while (true)
            {
                var line = buf.readLine();
                if (!(line != null))
                {
                    break;
                }
                var va = cape.String.split(line, ':');
                cape.Iterator <string> val = cape.Vector.iterate(va);
                if (val != null)
                {
                    var front = val.next();
                    var back  = val.next();
                    if (front != null)
                    {
                        front = cape.String.strip(front);
                    }
                    if (back != null)
                    {
                        back = cape.String.strip(back);
                    }
                    if (add(front, back))
                    {
                        n++;
                    }
                }
            }
            return(true);
        }
コード例 #3
0
        public capex.text.RichTextDocument parse()
        {
            cape.LineReader pr = null;
            if (file != null)
            {
                pr = (cape.LineReader) new cape.PrintReader((cape.Reader)file.read());
            }
            else if (!(object.Equals(data, null)))
            {
                pr = (cape.LineReader) new cape.StringLineReader(data);
            }
            if (pr == null)
            {
                return(null);
            }
            var v = new capex.text.RichTextDocument();

            while (processInput(pr, v))
            {
                ;
            }
            return(v);
        }
コード例 #4
0
        public virtual bool read(cape.File file)
        {
            if (!(file != null))
            {
                return(false);
            }
            var reader = file.read();

            if (!(reader != null))
            {
                return(false);
            }
            var    ins  = new cape.PrintReader((cape.Reader)reader);
            string line = null;
            string tag  = null;

            cape.StringBuilder lineBuffer = null;
            string             terminator = null;

            while ((line = ins.readLine()) != null)
            {
                if (lineBuffer != null)
                {
                    lineBuffer.append(line);
                    if (object.Equals(line, terminator))
                    {
                        line       = lineBuffer.toString();
                        lineBuffer = null;
                        terminator = null;
                    }
                    else
                    {
                        lineBuffer.append('\n');
                        continue;
                    }
                }
                line = cape.String.strip(line);
                if (cape.String.isEmpty(line) || cape.String.startsWith(line, "#"))
                {
                    continue;
                }
                if (cape.String.endsWith(line, "{"))
                {
                    if (cape.String.indexOf(line, ':') < 0)
                    {
                        if (!(tag != null))
                        {
                            tag = cape.String.strip(cape.String.getSubString(line, 0, cape.String.getLength(line) - 1));
                        }
                        continue;
                    }
                    else
                    {
                        lineBuffer = new cape.StringBuilder();
                        lineBuffer.append(line);
                        lineBuffer.append('\n');
                        terminator = "}";
                        continue;
                    }
                }
                if (cape.String.endsWith(line, "["))
                {
                    lineBuffer = new cape.StringBuilder();
                    lineBuffer.append(line);
                    lineBuffer.append('\n');
                    terminator = "]";
                    continue;
                }
                if (cape.String.endsWith(line, "\"\"\""))
                {
                    lineBuffer = new cape.StringBuilder();
                    lineBuffer.append(line);
                    lineBuffer.append('\n');
                    terminator = "\"\"\"";
                    continue;
                }
                if (tag != null && object.Equals(line, "}"))
                {
                    tag = null;
                    continue;
                }
                var sp = cape.String.split(line, ':', 2);
                if (!(sp != null))
                {
                    continue;
                }
                var key = cape.String.strip(cape.Vector.get(sp, 0));
                var val = cape.String.strip(cape.Vector.get(sp, 1));
                if (cape.String.startsWith(val, "\"") && cape.String.endsWith(val, "\""))
                {
                    val = cape.String.getSubString(val, 1, cape.String.getLength(val) - 2);
                }
                if (cape.String.isEmpty(key))
                {
                    continue;
                }
                if (tag != null)
                {
                    key = key + "[" + tag + "]";
                }
                data.add((string)key, (string)val);
            }
            this.file = file;
            return(true);
        }