Exemple #1
0
            public virtual string next()
            {
                if (reader == null)
                {
                    return(null);
                }
                var v = reader.readLine();

                if (object.Equals(v, null))
                {
                    reader.close();
                    reader = null;
                }
                return(v);
            }
Exemple #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);
        }
Exemple #3
0
 public cape.FileAdapter.ReadLineIterator setReader(cape.PrintReader v)
 {
     reader = v;
     return(this);
 }
Exemple #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);
        }
 public ConsoleApplicationMain()
 {
     stdin  = capex.console.Stdin.instance();
     stdout = capex.console.Stdout.instance();
     ctx    = new capex.console.ConsoleApplicationContext();
 }