Commit dfe51432 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8f842cba
......@@ -122,7 +122,7 @@ func fsTail(w io.Writer, path string, ntxn int) (err error) {
// fstail.py uses repr to print user/description:
// https://github.com/zopefoundation/ZODB/blob/5.2.0-5-g6047e2fae/src/ZODB/scripts/fstail.py#L39
xbuf .S("\nuser=") .Qbpy(txnh.User) .S(" description=") .Qbpy(txnh.Description)
xbuf .S("\nuser=") .Qpyb(txnh.User) .S(" description=") .Qpyb(txnh.Description)
// NOTE in zodb/py .length is len - 8, in zodb/go - whole txn record length
xbuf .S(" length=") .D64(txnh.Len - 8)
......
......@@ -42,6 +42,7 @@ func NewReader(r io.Reader) *Reader {
}
// InputOffset returns current position in input stream
// XXX naming + define interface for getting current position
func (r *Reader) InputOffset() int64 {
return r.cr.Nread - int64(r.Reader.Buffered())
}
......@@ -2,9 +2,14 @@
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 2, or (at your
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
......@@ -20,7 +25,7 @@
// xfmt analog would be
//
// xbuf := xfmt.Buffer{}
// xbuf .S("hello ") .Qs("world") .C(' ') .D(1) .C(' ') .Xb([]byte("data"))
// xbuf .S("hello ") .Q("world") .C(' ') .D(1) .C(' ') .Xb([]byte("data"))
// s := xbuf.Bytes()
//
// xfmt.Buffer can be reused several times via Buffer.Reset() .
......@@ -91,7 +96,7 @@ func (b *Buffer) Sb(x []byte) *Buffer {
return b
}
// Cb appends byte formated by %c
// Cb appends byte formatted by %c
func (b *Buffer) Cb(c byte) *Buffer {
*b = append(*b, c)
return b
......@@ -171,4 +176,25 @@ func (b *Buffer) X016(x uint64) *Buffer {
return b
}
// TODO Qs Qb ?
// Q appends string formatted by %q
func (b *Buffer) Q(s string) *Buffer {
*b = strconv.AppendQuote(*b, s)
return b
}
// Qb appends []byte formatted by %q
func (b *Buffer) Qb(s []byte) *Buffer {
*b = strconv.AppendQuote(*b, mem.String(s))
return b
}
// Qcb appends byte formatted by %q
func (b *Buffer) Qcb(c byte) *Buffer {
return b.Qc(rune(c))
}
// Qc appends rune formatted by %q
func (b *Buffer) Qc(c rune) *Buffer {
*b = strconv.AppendQuoteRune(*b, c)
return b
}
// TODO copyright/license
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package xfmt
......@@ -16,10 +31,16 @@ var testv = []struct {format, xformatMeth string; value interface{}} {
{"%c", "C", '\u20ac'}, // 3-bytes encoded
{"%c", "C", '\U00010001'}, // 4-bytes encoded
// TODO %q qb qr qs qcb qc
{"%s", "S", "hello"},
{"%s", "Sb", []byte("world")},
{"%q", "Q", "alpha"},
{"%q", "Qb", []byte("beta")},
{"%q", "Qcb", byte('D')},
{"%q", "Qc", 'B'}, // 1-byte encoded
{"%q", "Qc", 'и'}, // 2-bytes encoded
{"%q", "Qc", '\u20ac'}, // 3-bytes encoded
{"%q", "Qc", '\U00010001'}, // 4-bytes encoded
{"%x", "Xb", []byte("hexstring")},
{"%x", "Xs", "stringhex"},
{"%d", "D", 12765},
......
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// quoting by Python rules
package xfmt
import (
......@@ -8,19 +27,6 @@ import (
"lab.nexedi.com/kirr/go123/mem"
)
// TODO remove - not needed ?
// // pyQuote quotes string the way python repr(str) would do
// func pyQuote(s string) string {
// out := pyQuoteBytes(mem.Bytes(s))
// return mem.String(out)
// }
//
// func pyQuoteBytes(b []byte) []byte {
// buf := make([]byte, 0, (len(b) + 2) /* to reduce allocations when quoting */ * 2)
// return pyAppendQuoteBytes(buf, b)
// }
// bytesContainsByte is like bytes.ContainsRune but a bit faster
func bytesContainsByte(s []byte, c byte) bool {
return bytes.IndexByte(s, c) >= 0
......@@ -112,8 +118,8 @@ func (b *Buffer) Qpy(s string) *Buffer {
return b
}
// Qbpy appends []byte quoted as Python would do
func (b *Buffer) Qbpy(x []byte) *Buffer {
// Qpyb appends []byte quoted as Python would do
func (b *Buffer) Qpyb(x []byte) *Buffer {
*b = AppendQuotePyBytes(*b, x)
return b
}
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package xfmt
import (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment